From 3781272615470a0d846835be96963d204e241d73 Mon Sep 17 00:00:00 2001 From: lianpi3 Date: Thu, 1 Aug 2024 15:38:20 +0330 Subject: [PATCH] add ticket --- Controllers/ticketsController.cs | 142 +++++++++++++++++++++++++++++++ Models/Model1.Context.cs | 1 + Models/Model1.edmx | 52 +++++++++-- Models/Model1.edmx.diagram | 1 + Models/response.cs | 23 +++++ Models/ticket.cs | 5 +- Views/news/Latest.cshtml | 52 +++++++++++ Views/tickets/Create.cshtml | 55 ++++++++++++ Views/tickets/Delete.cshtml | 64 ++++++++++++++ Views/tickets/Details.cshtml | 58 +++++++++++++ Views/tickets/Index.cshtml | 57 +++++++++++++ WebApplication1.csproj | 8 ++ 12 files changed, 508 insertions(+), 10 deletions(-) create mode 100644 Controllers/ticketsController.cs create mode 100644 Models/response.cs create mode 100644 Views/news/Latest.cshtml create mode 100644 Views/tickets/Create.cshtml create mode 100644 Views/tickets/Delete.cshtml create mode 100644 Views/tickets/Details.cshtml create mode 100644 Views/tickets/Index.cshtml diff --git a/Controllers/ticketsController.cs b/Controllers/ticketsController.cs new file mode 100644 index 0000000..3f638de --- /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"); + + } + + // 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); + } + } +} 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..798b380 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/news/Latest.cshtml b/Views/news/Latest.cshtml new file mode 100644 index 0000000..e91bb41 --- /dev/null +++ b/Views/news/Latest.cshtml @@ -0,0 +1,52 @@ +@model IEnumerable + +

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

+ + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.title) + + @Html.DisplayNameFor(model => model.cat) + + @Html.DisplayNameFor(model => model.tag) + + @Html.DisplayNameFor(model => model.publishDate) + + @Html.DisplayNameFor(model => model.views) +
+ @Html.DisplayFor(modelItem => item.title) + + + @Html.DisplayFor(modelItem => item.cat) + + @Html.DisplayFor(modelItem => item.tag) + + @Html.DisplayFor(modelItem => item.publishDate) + + @Html.DisplayFor(modelItem => item.views) + + @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/Views/tickets/Create.cshtml b/Views/tickets/Create.cshtml new file mode 100644 index 0000000..04ade79 --- /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") +
diff --git a/Views/tickets/Delete.cshtml b/Views/tickets/Delete.cshtml new file mode 100644 index 0000000..68ff0cb --- /dev/null +++ b/Views/tickets/Delete.cshtml @@ -0,0 +1,64 @@ +@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) +
+ +
+ @Html.DisplayNameFor(model => model.status) +
+ +
+ @Html.DisplayFor(model => model.status) +
+ +
+ + @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..5d90b8c --- /dev/null +++ b/Views/tickets/Details.cshtml @@ -0,0 +1,58 @@ +@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.DisplayNameFor(model => model.status) +
+ +
+ @Html.DisplayFor(model => model.status) +
+ +
+
+

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

diff --git a/Views/tickets/Index.cshtml b/Views/tickets/Index.cshtml new file mode 100644 index 0000000..c57f18e --- /dev/null +++ b/Views/tickets/Index.cshtml @@ -0,0 +1,57 @@ +@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.DisplayNameFor(model => model.status) +
+ @Html.DisplayFor(modelItem => item.title) + + @Html.DisplayFor(modelItem => item.content) + + @Html.DisplayFor(modelItem => item.priority) + + @Html.DisplayFor(modelItem => item.senderid) + + @Html.DisplayFor(modelItem => item.status) + + @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 c8c5b71..ad105fa 100644 --- a/WebApplication1.csproj +++ b/WebApplication1.csproj @@ -145,6 +145,7 @@ + Global.asax @@ -155,6 +156,9 @@ + + Model1.tt + True @@ -274,6 +278,10 @@ + + + +