diff --git a/Controllers/responsesController.cs b/Controllers/responsesController.cs new file mode 100644 index 0000000..665109d --- /dev/null +++ b/Controllers/responsesController.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Entity; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using WebApplication1.Models; + +namespace WebApplication1.Controllers +{ + public class responsesController : Controller + { + private newswebappEntities db = new newswebappEntities(); + + // GET: responses + public ActionResult Index() + { + if (Convert.ToInt32(Session["Userrole"]) > 0) + { + return View(db.tickets.OrderByDescending(p => p.priority).Where(s=> s.status == 1).ToList()); + } + else + { + @ViewBag.role = "user"; + } + + 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"); + + } + + // GET: responses/Details/5 + public ActionResult Details(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + response response = db.responses.Find(id); + if (response == null) + { + return HttpNotFound(); + } + return View(response); + } + + // GET: responses/Create + public ActionResult Create() + { + return View(); + } + + // POST: responses/Create + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details see https://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Create([Bind(Include = "ID,title,content,adminid,ticketid")] response response) + { + if (ModelState.IsValid) + { + + db.responses.Add(response); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + return View(response); + } + + // GET: responses/Edit/5 + public ActionResult Respond(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + ViewBag.targetTicket = db.tickets.Find(id); + ViewBag.sender = db.users.Find(db.tickets.Find(id).senderid); + + if (ViewBag.targetTicket == null) + { + return HttpNotFound(); + } + return View(); + } + + // POST: responses/Edit/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // more details see https://go.microsoft.com/fwlink/?LinkId=317598. + [HttpPost] + [ValidateAntiForgeryToken] + public ActionResult Respond([Bind(Include = "ID,title,content,adminid,ticketid")] response response) + { + if (ModelState.IsValid) + { + response.adminid = Convert.ToInt32(Session["Userid"]); + //wtf + db.responses.Add(response); + db.SaveChanges(); + + var targetTicket= db.tickets.Find(response.ticketid); + targetTicket.status = 0; + db.SaveChanges(); + return RedirectToAction("Index"); + } + return View(response); + } + + // GET: responses/Delete/5 + public ActionResult Delete(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + response response = db.responses.Find(id); + if (response == null) + { + return HttpNotFound(); + } + return View(response); + } + + // POST: responses/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public ActionResult DeleteConfirmed(int id) + { + response response = db.responses.Find(id); + db.responses.Remove(response); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + } +} diff --git a/Controllers/ticketsController.cs b/Controllers/ticketsController.cs new file mode 100644 index 0000000..91ac69a --- /dev/null +++ b/Controllers/ticketsController.cs @@ -0,0 +1,142 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.Entity; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; +using WebApplication1.Models; + +namespace WebApplication1.Controllers +{ + public class ticketsController : Controller + { + private newswebappEntities db = new newswebappEntities(); + + // GET: tickets + public ActionResult Index() + { + if (Session["User"] != null) + { + int uid = Convert.ToInt32(Session["Userid"]); + return View(db.tickets.Where(n => n.senderid == uid)); + } + else + return RedirectToAction("Login"); + } + + // GET: tickets/Details/5 + public ActionResult Details(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + ticket ticket = db.tickets.Find(id); + if (ticket == null) + { + return HttpNotFound(); + } + return View(ticket); + } + + // GET: tickets/Create + public ActionResult Create() + { + if (Session["User"] != null) + { + return View(); + } + else + return RedirectToAction("Login","users"); + + } + + // POST: tickets/Create + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // 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) + { + if (ModelState.IsValid) + { + ticket.senderid = Convert.ToInt32(Session["Userid"]); + ticket.status = 1; + + db.tickets.Add(ticket); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + return View(ticket); + } + + // GET: tickets/Edit/5 + public ActionResult Edit(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + ticket ticket = db.tickets.Find(id); + if (ticket == null) + { + return HttpNotFound(); + } + return View(ticket); + } + + // POST: tickets/Edit/5 + // To protect from overposting attacks, enable the specific properties you want to bind to, for + // 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) + { + if (ModelState.IsValid) + { + db.Entry(ticket).State = EntityState.Modified; + db.SaveChanges(); + return RedirectToAction("Index"); + } + return View(ticket); + } + + // GET: tickets/Delete/5 + public ActionResult Delete(int? id) + { + if (id == null) + { + return new HttpStatusCodeResult(HttpStatusCode.BadRequest); + } + ticket ticket = db.tickets.Find(id); + if (ticket == null) + { + return HttpNotFound(); + } + return View(ticket); + } + + // POST: tickets/Delete/5 + [HttpPost, ActionName("Delete")] + [ValidateAntiForgeryToken] + public ActionResult DeleteConfirmed(int id) + { + ticket ticket = db.tickets.Find(id); + db.tickets.Remove(ticket); + db.SaveChanges(); + return RedirectToAction("Index"); + } + + protected override void Dispose(bool disposing) + { + if (disposing) + { + db.Dispose(); + } + base.Dispose(disposing); + } + } +} \ No newline at end of file diff --git a/Models/Model1.Context.cs b/Models/Model1.Context.cs index f79f1ff..c4289fc 100644 --- a/Models/Model1.Context.cs +++ b/Models/Model1.Context.cs @@ -30,5 +30,6 @@ namespace WebApplication1.Models public virtual DbSet tags { get; set; } public virtual DbSet tickets { get; set; } public virtual DbSet users { get; set; } + public virtual DbSet responses { get; set; } } } diff --git a/Models/Model1.edmx b/Models/Model1.edmx index 4ab2a02..2aaf1b2 100644 --- a/Models/Model1.edmx +++ b/Models/Model1.edmx @@ -29,6 +29,16 @@ + + + + + + + + + + @@ -42,10 +52,11 @@ - - - - + + + + + @@ -60,6 +71,7 @@ + @@ -74,6 +86,7 @@ + @@ -112,10 +125,11 @@ - - - - + + + + + @@ -127,6 +141,16 @@ + + + + + + + + + + @@ -171,6 +195,7 @@ + @@ -190,6 +215,17 @@ + + + + + + + + + + + diff --git a/Models/Model1.edmx.diagram b/Models/Model1.edmx.diagram index 2170411..08b62f3 100644 --- a/Models/Model1.edmx.diagram +++ b/Models/Model1.edmx.diagram @@ -10,6 +10,7 @@ + diff --git a/Models/response.cs b/Models/response.cs new file mode 100644 index 0000000..652d6aa --- /dev/null +++ b/Models/response.cs @@ -0,0 +1,23 @@ +//------------------------------------------------------------------------------ +// +// This code was generated from a template. +// +// Manual changes to this file may cause unexpected behavior in your application. +// Manual changes to this file will be overwritten if the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WebApplication1.Models +{ + using System; + using System.Collections.Generic; + + public partial class response + { + public int ID { get; set; } + public string title { get; set; } + public string content { get; set; } + public Nullable adminid { get; set; } + public Nullable ticketid { get; set; } + } +} diff --git a/Models/ticket.cs b/Models/ticket.cs index e372bae..6183030 100644 --- a/Models/ticket.cs +++ b/Models/ticket.cs @@ -17,7 +17,8 @@ namespace WebApplication1.Models public int ID { get; set; } public string title { get; set; } public string content { get; set; } - public string priority { get; set; } - public Nullable senderid { get; set; } + public int priority { get; set; } + public int senderid { get; set; } + public Nullable status { get; set; } } } diff --git a/Views/responses/Create.cshtml b/Views/responses/Create.cshtml new file mode 100644 index 0000000..e2d4075 --- /dev/null +++ b/Views/responses/Create.cshtml @@ -0,0 +1,59 @@ +@model WebApplication1.Models.response + +@{ + ViewBag.Title = "Create"; +} + +

Create

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

response

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.content, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.adminid, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.adminid, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.adminid, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.ticketid, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.ticketid, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.ticketid, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
diff --git a/Views/responses/Delete.cshtml b/Views/responses/Delete.cshtml new file mode 100644 index 0000000..8ac5c02 --- /dev/null +++ b/Views/responses/Delete.cshtml @@ -0,0 +1,56 @@ +@model WebApplication1.Models.response + +@{ + ViewBag.Title = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

response

+
+
+
+ @Html.DisplayNameFor(model => model.title) +
+ +
+ @Html.DisplayFor(model => model.title) +
+ +
+ @Html.DisplayNameFor(model => model.content) +
+ +
+ @Html.DisplayFor(model => model.content) +
+ +
+ @Html.DisplayNameFor(model => model.adminid) +
+ +
+ @Html.DisplayFor(model => model.adminid) +
+ +
+ @Html.DisplayNameFor(model => model.ticketid) +
+ +
+ @Html.DisplayFor(model => model.ticketid) +
+ +
+ + @using (Html.BeginForm()) { + @Html.AntiForgeryToken() + +
+ | + @Html.ActionLink("Back to List", "Index") +
+ } +
diff --git a/Views/responses/Details.cshtml b/Views/responses/Details.cshtml new file mode 100644 index 0000000..72c0e28 --- /dev/null +++ b/Views/responses/Details.cshtml @@ -0,0 +1,50 @@ +@model WebApplication1.Models.response + +@{ + ViewBag.Title = "Details"; +} + +

Details

+ +
+

response

+
+
+
+ @Html.DisplayNameFor(model => model.title) +
+ +
+ @Html.DisplayFor(model => model.title) +
+ +
+ @Html.DisplayNameFor(model => model.content) +
+ +
+ @Html.DisplayFor(model => model.content) +
+ +
+ @Html.DisplayNameFor(model => model.adminid) +
+ +
+ @Html.DisplayFor(model => model.adminid) +
+ +
+ @Html.DisplayNameFor(model => model.ticketid) +
+ +
+ @Html.DisplayFor(model => model.ticketid) +
+ +
+
+

+ @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) | + @Html.ActionLink("Back to List", "Index") +

diff --git a/Views/responses/Index.cshtml b/Views/responses/Index.cshtml new file mode 100644 index 0000000..f1e1931 --- /dev/null +++ b/Views/responses/Index.cshtml @@ -0,0 +1,39 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

Index

+ +

+ @Html.ActionLink("Create New", "Create") +

+ + + + + + + +@foreach (var item in Model) { + + + + + +} + +
+ @Html.DisplayNameFor(model => model.title) + + @Html.DisplayNameFor(model => model.content) +
+ @Html.DisplayFor(modelItem => item.title) + + @Html.DisplayFor(modelItem => item.content) + + @Html.ActionLink("Respond", "Respond", new { id=item.ID }) | + @Html.ActionLink("Details", "Details", new { id=item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id=item.ID }) +
diff --git a/Views/responses/Respond.cshtml b/Views/responses/Respond.cshtml new file mode 100644 index 0000000..773269a --- /dev/null +++ b/Views/responses/Respond.cshtml @@ -0,0 +1,99 @@ +@model WebApplication1.Models.response + +@{ + ViewBag.Title = "Edit"; + string priority = ""; + if (ViewBag.targetTicket.priority == 1) + { + priority = "Urgant"; + } + else if (ViewBag.targetTicket.priority == 2) + { + priority = "Important"; + } + else + { + priority = "Normal"; + } +} + +

Edit

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + + + +

response

+
+
+
+
+ Title +
+ +
+
+ +
+ Sender +
+ +
+
+ +
+ Priority +
+ +
+
+ +
+ Content +
+ +
+
+
+
+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.TextAreaFor(model => model.content, new { @class = "form-control" } ) + @Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" }) +
+
+ + +
+ +
+ +
+
+ + +
+
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
diff --git a/Views/tickets/Create.cshtml b/Views/tickets/Create.cshtml new file mode 100644 index 0000000..7ba5c2d --- /dev/null +++ b/Views/tickets/Create.cshtml @@ -0,0 +1,55 @@ +@model WebApplication1.Models.ticket + +@{ + ViewBag.Title = "Create"; +} + +

Create

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

ticket

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) +
+ @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.TextAreaFor(model => model.content, new { @class = "form-control" }) + @Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.priority, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ +
+ +
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
\ No newline at end of file diff --git a/Views/tickets/Delete.cshtml b/Views/tickets/Delete.cshtml new file mode 100644 index 0000000..b89a7bd --- /dev/null +++ b/Views/tickets/Delete.cshtml @@ -0,0 +1,56 @@ +@model WebApplication1.Models.ticket + +@{ + ViewBag.Title = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

ticket

+
+
+
+ @Html.DisplayNameFor(model => model.title) +
+ +
+ @Html.DisplayFor(model => model.title) +
+ +
+ @Html.DisplayNameFor(model => model.content) +
+ +
+ @Html.DisplayFor(model => model.content) +
+ +
+ @Html.DisplayNameFor(model => model.priority) +
+ +
+ @Html.DisplayFor(model => model.priority) +
+ +
+ @Html.DisplayNameFor(model => model.senderid) +
+ +
+ @Html.DisplayFor(model => model.senderid) +
+ +
+ + @using (Html.BeginForm()) { + @Html.AntiForgeryToken() + +
+ | + @Html.ActionLink("Back to List", "Index") +
+ } +
diff --git a/Views/tickets/Details.cshtml b/Views/tickets/Details.cshtml new file mode 100644 index 0000000..6443fbb --- /dev/null +++ b/Views/tickets/Details.cshtml @@ -0,0 +1,50 @@ +@model WebApplication1.Models.ticket + +@{ + ViewBag.Title = "Details"; +} + +

Details

+ +
+

ticket

+
+
+
+ @Html.DisplayNameFor(model => model.title) +
+ +
+ @Html.DisplayFor(model => model.title) +
+ +
+ @Html.DisplayNameFor(model => model.content) +
+ +
+ @Html.DisplayFor(model => model.content) +
+ +
+ @Html.DisplayNameFor(model => model.priority) +
+ +
+ @Html.DisplayFor(model => model.priority) +
+ +
+ @Html.DisplayNameFor(model => model.senderid) +
+ +
+ @Html.DisplayFor(model => model.senderid) +
+ +
+
+

+ @Html.ActionLink("Edit", "Edit", new { id = Model.ID }) | + @Html.ActionLink("Back to List", "Index") +

diff --git a/Views/tickets/Edit.cshtml b/Views/tickets/Edit.cshtml new file mode 100644 index 0000000..920973e --- /dev/null +++ b/Views/tickets/Edit.cshtml @@ -0,0 +1,61 @@ +@model WebApplication1.Models.ticket + +@{ + ViewBag.Title = "Edit"; +} + +

Edit

+ +@using (Html.BeginForm()) +{ + @Html.AntiForgeryToken() + +
+

ticket

+
+ @Html.ValidationSummary(true, "", new { @class = "text-danger" }) + @Html.HiddenFor(model => model.ID) + +
+ @Html.LabelFor(model => model.title, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.title, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.title, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.content, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.content, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.content, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.priority, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.priority, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.priority, "", new { @class = "text-danger" }) +
+
+ +
+ @Html.LabelFor(model => model.senderid, htmlAttributes: new { @class = "control-label col-md-2" }) +
+ @Html.EditorFor(model => model.senderid, new { htmlAttributes = new { @class = "form-control" } }) + @Html.ValidationMessageFor(model => model.senderid, "", new { @class = "text-danger" }) +
+
+ +
+
+ +
+
+
+} + +
+ @Html.ActionLink("Back to List", "Index") +
diff --git a/Views/tickets/Index.cshtml b/Views/tickets/Index.cshtml new file mode 100644 index 0000000..28c8e87 --- /dev/null +++ b/Views/tickets/Index.cshtml @@ -0,0 +1,51 @@ +@model IEnumerable + +@{ + ViewBag.Title = "Index"; +} + +

Index

+ +

+ @Html.ActionLink("Create New", "Create") +

+ + + + + + + + + +@foreach (var item in Model) { + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.title) + + @Html.DisplayNameFor(model => model.content) + + @Html.DisplayNameFor(model => model.priority) + + @Html.DisplayNameFor(model => model.senderid) +
+ @Html.DisplayFor(modelItem => item.title) + + @Html.DisplayFor(modelItem => item.content) + + @Html.DisplayFor(modelItem => item.priority) + + @Html.DisplayFor(modelItem => item.senderid) + + @Html.ActionLink("Edit", "Edit", new { id=item.ID }) | + @Html.ActionLink("Details", "Details", new { id=item.ID }) | + @Html.ActionLink("Delete", "Delete", new { id=item.ID }) +
diff --git a/WebApplication1.csproj b/WebApplication1.csproj index 9d918dc..115f1b0 100644 --- a/WebApplication1.csproj +++ b/WebApplication1.csproj @@ -145,6 +145,8 @@ + + Global.asax @@ -156,6 +158,9 @@ + + Model1.tt + True @@ -276,6 +281,16 @@ + + + + + + + + + +