ticket and respond
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
@ -16,32 +17,40 @@ namespace WebApplication1.Controllers
|
||||
|
||||
// GET: responses
|
||||
public ActionResult Index()
|
||||
{
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Convert.ToInt32(Session["Userrole"]) > 0)
|
||||
{
|
||||
return View(db.tickets.OrderByDescending(p => p.priority).Where(s=> s.status == 1).ToList());
|
||||
var models = (from user in db.users // Access Users DbSet
|
||||
join tickets in db.tickets on user.ID equals tickets.senderid into ticketsgroup // Join News DbSet
|
||||
from tickets in ticketsgroup.DefaultIfEmpty() // Left outer join
|
||||
where tickets != null // Filter based on existence of news record
|
||||
select new ticketlist
|
||||
{
|
||||
username = user != null ? user.usename : null,
|
||||
ticketID = tickets.ID, // Use null-conditional operator for missing news
|
||||
ticketTitle = tickets.title,
|
||||
priority = tickets.priority,
|
||||
status = tickets.status
|
||||
}).OrderByDescending(p => p.priority).Where(s => s.status == 1 || s.status ==3).ToList();
|
||||
|
||||
|
||||
return View(models);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ViewBag.role = "user";
|
||||
return new HttpStatusCodeResult(HttpStatusCode.Unauthorized);
|
||||
}
|
||||
|
||||
if (Session["User"] != null)
|
||||
{
|
||||
if (Session["Userid"] == null)
|
||||
{
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
user user = db.users.Find(Session["Userid"]);
|
||||
if (user == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
return View(user);
|
||||
}
|
||||
else
|
||||
return RedirectToAction("Login", "users");
|
||||
|
||||
}
|
||||
public ActionResult test()
|
||||
{
|
||||
return View(db.responses.ToList());
|
||||
|
||||
}
|
||||
|
||||
// GET: responses/Details/5
|
||||
@ -74,7 +83,8 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
response.adminid = Convert.ToInt32(Session["Userid"]);
|
||||
var targetTicket = db.tickets.Find(response.ticketid);
|
||||
db.responses.Add(response);
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
@ -91,7 +101,8 @@ namespace WebApplication1.Controllers
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
ViewBag.targetTicket = db.tickets.Find(id);
|
||||
ViewBag.sender = db.users.Find(db.tickets.Find(id).senderid);
|
||||
var u = db.users.Find(db.tickets.Find(id).senderid);
|
||||
ViewBag.sender = u.usename;
|
||||
|
||||
if (ViewBag.targetTicket == null)
|
||||
{
|
||||
@ -109,19 +120,59 @@ namespace WebApplication1.Controllers
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
response.adminid = Convert.ToInt32(Session["Userid"]);
|
||||
//wtf
|
||||
db.responses.Add(response);
|
||||
db.SaveChanges();
|
||||
|
||||
response.adminid = Convert.ToInt32(Session["Userid"]);
|
||||
var targetTicket = db.tickets.Find(response.ticketid);
|
||||
targetTicket.status = 0;
|
||||
|
||||
if (response.ID == 0)
|
||||
{
|
||||
db.responses.Add(response);
|
||||
targetTicket.status = 2;
|
||||
targetTicket.responsid = response.ID;
|
||||
try
|
||||
{
|
||||
db.SaveChanges();
|
||||
}
|
||||
catch (DbEntityValidationException ex)
|
||||
{
|
||||
foreach (var validationErrors in ex.EntityValidationErrors)
|
||||
{
|
||||
foreach (var validationError in validationErrors.ValidationErrors)
|
||||
{
|
||||
Console.WriteLine($"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var res = db.responses.Find(response.ID);
|
||||
res.content += "\n" + response.content;
|
||||
targetTicket.status = 2;
|
||||
try
|
||||
{
|
||||
db.SaveChanges();
|
||||
}
|
||||
catch (DbEntityValidationException ex)
|
||||
{
|
||||
foreach (var validationErrors in ex.EntityValidationErrors)
|
||||
{
|
||||
foreach (var validationError in validationErrors.ValidationErrors)
|
||||
{
|
||||
Console.WriteLine($"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
return View(response);
|
||||
}
|
||||
|
||||
|
||||
// GET: responses/Delete/5
|
||||
public ActionResult Delete(int? id)
|
||||
{
|
||||
|
||||
@ -23,7 +23,7 @@ namespace WebApplication1.Controllers
|
||||
return View(db.tickets.Where(n => n.senderid == uid));
|
||||
}
|
||||
else
|
||||
return RedirectToAction("Login");
|
||||
return RedirectToAction("Login", "users");
|
||||
}
|
||||
|
||||
// GET: tickets/Details/5
|
||||
@ -58,10 +58,11 @@ namespace WebApplication1.Controllers
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Create([Bind(Include = "ID,title,content,priority,senderid,status")] ticket ticket)
|
||||
public ActionResult Create([Bind(Include = "ID,title,content,priority,senderid,status,responsid")] ticket ticket)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
ticket.responsid = 0;
|
||||
ticket.senderid = Convert.ToInt32(Session["Userid"]);
|
||||
ticket.status = 1;
|
||||
|
||||
@ -81,6 +82,8 @@ namespace WebApplication1.Controllers
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
||||
}
|
||||
ticket ticket = db.tickets.Find(id);
|
||||
ViewBag.response = db.responses.Find(ticket.responsid);
|
||||
|
||||
if (ticket == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
@ -93,11 +96,13 @@ namespace WebApplication1.Controllers
|
||||
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Edit([Bind(Include = "ID,title,content,priority,senderid,status")] ticket ticket)
|
||||
public ActionResult Edit([Bind(Include = "ID,title,content,priority,senderid,status,responsid")] ticket ticket)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
db.Entry(ticket).State = EntityState.Modified;
|
||||
var currentTicket = db.tickets.Find(ticket.ID);
|
||||
currentTicket.content += "\n" + ticket.content;
|
||||
currentTicket.status = 3;
|
||||
db.SaveChanges();
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace WebApplication1.Models
|
||||
{
|
||||
public class Login
|
||||
{
|
||||
[Key]
|
||||
public int ID { get; set; }
|
||||
public string username { get; set; }
|
||||
public string password { get; set; }
|
||||
}
|
||||
}
|
||||
@ -34,8 +34,8 @@
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||
<Property Name="title" Type="nchar" MaxLength="10" />
|
||||
<Property Name="content" Type="nchar" MaxLength="10" />
|
||||
<Property Name="title" Type="nvarchar" MaxLength="150" />
|
||||
<Property Name="content" Type="nvarchar(max)" />
|
||||
<Property Name="adminid" Type="int" />
|
||||
<Property Name="ticketid" Type="int" />
|
||||
</EntityType>
|
||||
@ -52,11 +52,12 @@
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
|
||||
<Property Name="title" Type="nvarchar" MaxLength="50" Nullable="false" />
|
||||
<Property Name="title" Type="nvarchar" MaxLength="150" Nullable="false" />
|
||||
<Property Name="content" Type="nvarchar(max)" Nullable="false" />
|
||||
<Property Name="priority" Type="int" Nullable="false" />
|
||||
<Property Name="senderid" Type="int" Nullable="false" />
|
||||
<Property Name="status" Type="int" />
|
||||
<Property Name="responsid" Type="int" />
|
||||
</EntityType>
|
||||
<EntityType Name="user">
|
||||
<Key>
|
||||
@ -125,11 +126,12 @@
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||
<Property Name="title" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />
|
||||
<Property Name="title" Type="String" MaxLength="150" FixedLength="false" Unicode="true" Nullable="false" />
|
||||
<Property Name="content" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" Nullable="false" />
|
||||
<Property Name="priority" Type="Int32" Nullable="false" />
|
||||
<Property Name="senderid" Type="Int32" Nullable="false" />
|
||||
<Property Name="status" Type="Int32" />
|
||||
<Property Name="responsid" Type="Int32" />
|
||||
</EntityType>
|
||||
<EntityType Name="user">
|
||||
<Key>
|
||||
@ -146,8 +148,8 @@
|
||||
<PropertyRef Name="ID" />
|
||||
</Key>
|
||||
<Property Name="ID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
|
||||
<Property Name="title" Type="String" MaxLength="10" FixedLength="true" Unicode="true" />
|
||||
<Property Name="content" Type="String" MaxLength="10" FixedLength="true" Unicode="true" />
|
||||
<Property Name="title" Type="String" MaxLength="150" FixedLength="false" Unicode="true" />
|
||||
<Property Name="content" Type="String" MaxLength="Max" FixedLength="false" Unicode="true" />
|
||||
<Property Name="adminid" Type="Int32" />
|
||||
<Property Name="ticketid" Type="Int32" />
|
||||
</EntityType>
|
||||
@ -195,6 +197,7 @@
|
||||
<EntitySetMapping Name="tickets">
|
||||
<EntityTypeMapping TypeName="newswebappModel.ticket">
|
||||
<MappingFragment StoreEntitySet="ticket">
|
||||
<ScalarProperty Name="responsid" ColumnName="responsid" />
|
||||
<ScalarProperty Name="status" ColumnName="status" />
|
||||
<ScalarProperty Name="senderid" ColumnName="senderid" />
|
||||
<ScalarProperty Name="priority" ColumnName="priority" />
|
||||
|
||||
@ -20,5 +20,6 @@ namespace WebApplication1.Models
|
||||
public int priority { get; set; }
|
||||
public int senderid { get; set; }
|
||||
public Nullable<int> status { get; set; }
|
||||
public Nullable<int> responsid { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
18
Models/ticketlist.cs
Normal file
18
Models/ticketlist.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace WebApplication1.Models
|
||||
{
|
||||
public class ticketlist
|
||||
{
|
||||
public int ticketID { get; set; }
|
||||
public int userID { get; set; }
|
||||
public string username { get; set; }
|
||||
public string ticketTitle { get; set; }
|
||||
public int priority { get; set; }
|
||||
public int? status { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,12 @@
|
||||
@model IEnumerable<WebApplication1.Models.ticket>
|
||||
@using WebApplication1.Models
|
||||
@model IEnumerable<ticketlist>
|
||||
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Index";
|
||||
|
||||
string status = "";
|
||||
|
||||
}
|
||||
|
||||
<h2>Index</h2>
|
||||
@ -12,26 +17,36 @@
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.title)
|
||||
Title
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.content)
|
||||
Sender username
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
@foreach (var item in Model) {
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
@Html.DisplayFor(modelItem => item.ticketTitle)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.content)
|
||||
@Html.DisplayFor(modelItem => item.username)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Respond", "Respond", new { id=item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
||||
@if (item.status == 1)
|
||||
{
|
||||
status = "awaiting response";
|
||||
}
|
||||
else if (item.status == 3)
|
||||
{
|
||||
status = "open";
|
||||
}
|
||||
@status
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Respond", "Respond", new { id = item.ticketID })
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
@ -15,6 +15,16 @@
|
||||
{
|
||||
priority = "Normal";
|
||||
}
|
||||
string status = "";
|
||||
if (ViewBag.targetTicket.status == 1)
|
||||
{
|
||||
status = "awaiting response";
|
||||
}
|
||||
else if (ViewBag.targetTicket.status == 3)
|
||||
{
|
||||
status = "open";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<h2>Edit</h2>
|
||||
@ -49,11 +59,17 @@
|
||||
<input class="form-control" placeholder=@priority readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
Status
|
||||
<div class="col-md-10">
|
||||
<input class="form-control" placeholder=@status readonly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
Content
|
||||
<div class="col-md-10">
|
||||
<textarea class="form-control" placeholder=@ViewBag.targetTicket.content></textarea>
|
||||
<textarea class="form-control">@ViewBag.targetTicket.content</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
@ -80,7 +96,8 @@
|
||||
<div class="form-group">
|
||||
|
||||
<div class="col-md-10">
|
||||
<input class="form-control" name="ticketid" value=@ViewBag.targetTicket.ID hidden />
|
||||
<input class="form-control" name="ticketid" value=@ViewBag.targetTicket.ID readonly hidden />
|
||||
<input class="form-control" name="ID" value=@ViewBag.targetTicket.responsid readonly hidden />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
45
Views/responses/test.cshtml
Normal file
45
Views/responses/test.cshtml
Normal file
@ -0,0 +1,45 @@
|
||||
@model IEnumerable<WebApplication1.Models.response>
|
||||
|
||||
<p>
|
||||
@Html.ActionLink("Create New", "Create")
|
||||
</p>
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.content)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.adminid)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.ticketid)
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
@foreach (var item in Model) {
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.title)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.content)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.adminid)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.ticketid)
|
||||
</td>
|
||||
<td>
|
||||
@Html.ActionLink("Edit", "Edit", new { id=item.ID }) |
|
||||
@Html.ActionLink("Details", "Details", new { id=item.ID }) |
|
||||
@Html.ActionLink("Delete", "Delete", new { id=item.ID })
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
</table>
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
@{
|
||||
ViewBag.Title = "Edit";
|
||||
|
||||
}
|
||||
|
||||
<h2>Edit</h2>
|
||||
@ -15,7 +16,22 @@
|
||||
<hr />
|
||||
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
|
||||
@Html.HiddenFor(model => model.ID)
|
||||
<section class="col-md-4">
|
||||
<div class="form-group">
|
||||
Title
|
||||
<div class="col-md-10">
|
||||
<input class="form-control" placeholder=@ViewBag.response.title readonly />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
Content
|
||||
<div class="col-md-10">
|
||||
<textarea class="form-control" placeholder=@ViewBag.response.content></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<br />
|
||||
</section>
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@ -27,26 +43,11 @@
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.content, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.TextAreaFor(model => model.content, new { @class = "form-control" })
|
||||
@Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.priority, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.priority, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.priority, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@Html.LabelFor(model => model.senderid, htmlAttributes: new { @class = "control-label col-md-2" })
|
||||
<div class="col-md-10">
|
||||
@Html.EditorFor(model => model.senderid, new { htmlAttributes = new { @class = "form-control" } })
|
||||
@Html.ValidationMessageFor(model => model.senderid, "", new { @class = "text-danger" })
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-10">
|
||||
|
||||
@ -154,7 +154,7 @@
|
||||
<Compile Include="Models\category.cs">
|
||||
<DependentUpon>Model1.tt</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Models\Login.cs" />
|
||||
<Compile Include="Models\ticketlist.cs" />
|
||||
<Compile Include="Models\newsModel.cs" />
|
||||
<Compile Include="Models\Register.cs" />
|
||||
<Compile Include="Controllers\tagsController.cs" />
|
||||
@ -291,6 +291,7 @@
|
||||
<Content Include="Views\responses\Details.cshtml" />
|
||||
<Content Include="Views\responses\Respond.cshtml" />
|
||||
<Content Include="Views\responses\Index.cshtml" />
|
||||
<Content Include="Views\responses\test.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="App_Data\" />
|
||||
|
||||
Reference in New Issue
Block a user