add ticket
This commit is contained in:
142
Controllers/ticketsController.cs
Normal file
142
Controllers/ticketsController.cs
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user