public IHttpActionResult PutTicket(int id, string reporter, string message) { try { //Use Put to create or replace var ticket = db.TICKETS.FirstOrDefault((p) => p.Id == id); if (ticket == null) { ticket = new TICKET(id, reporter, message); db.TICKETS.Add(ticket); db.SaveChanges(); return(Ok(ticket)); } else { ticket.Message = message; ticket.Reporter = reporter; db.TICKETS.Attach(ticket); var entry = db.Entry(ticket); entry.Property(e => e.Message).IsModified = true; entry.Property(e => e.Reporter).IsModified = true; db.SaveChanges(); return(Ok(ticket)); } } catch (Exception e) { return(Content(HttpStatusCode.InternalServerError, e.Message)); } }
public ActionResult Close([Bind(Include = "TicketGuid,TicketNumber,Summary,Description,CreationDate," + "Creator,ClosedDate,TicketPriority,ClosingComments")] Ticket ticket) { if (ModelState.IsValid) { ticket.ClosedDate = DateTime.Now; db.Entry(ticket).State = EntityState.Modified; db.SaveChanges(); TempData["Message"] = "Ticket successfully closed!"; return(RedirectToAction("Index")); } return(View(ticket)); }