public ActionResult Edit(int id) { var entry = SatChilddb.SupportTickets.FirstOrDefault(a => a.Id == id); var model = new EditSupportTicket { Id = id, Employee = SatChilddb.Employees.FirstOrDefault(a => a.Id == entry.EmpId).Name, Client = SatChilddb.Clients.FirstOrDefault(a => a.Id == entry.ClientId).Name, Contract = SatChilddb.Contracts.FirstOrDefault(a => a.Id == entry.ContractId).Title, ContactName = entry.ContactName, Contact = entry.Contact, TicketStart = entry.TicketStart, TicketEnd = entry.TicketEnd, Notes = entry.Notes }; return(View(model)); }
public ActionResult Edit(EditSupportTicket model) { if (!ModelState.IsValid) { return(RedirectToAction("Index", new { message = SupportMessages.Error })); } var entry = SatChilddb.SupportTickets.FirstOrDefault(a => a.Id == model.Id); entry.EmpId = (entry.EmpId == SatChilddb.Employees.FirstOrDefault(a => a.Name.Equals(model.Employee)).Id) ? entry.EmpId : SatChilddb.Employees.FirstOrDefault(a => a.Name.Equals(model.Employee)).Id; entry.ClientId = (entry.ClientId == SatChilddb.Clients.FirstOrDefault(a => a.Name.Equals(model.Client)).Id) ? entry.ClientId : SatChilddb.Clients.FirstOrDefault(a => a.Name.Equals(model.Client)).Id; entry.ContractId = (entry.ContractId == SatChilddb.Contracts.FirstOrDefault(a => a.Title.Equals(model.Contract)).Id) ? entry.ContractId : SatChilddb.Contracts.FirstOrDefault(a => a.Title.Equals(model.Contract)).Id; entry.ContactName = (entry.ContactName.Equals(model.ContactName) ? entry.ContactName : model.ContactName); entry.Contact = entry.Contact.Equals(model.Contact) ? entry.Contact : model.Contact; entry.TicketStart = entry.TicketStart == model.TicketStart ? entry.TicketStart : model.TicketStart; entry.TicketEnd = entry.TicketEnd == model.TicketEnd ? entry.TicketEnd : model.TicketEnd; entry.Notes = entry.Notes.Equals(model.Notes) ? entry.Notes : model.Notes; entry.BugId = entry.BugId == model.BugId ? entry.BugId : model.BugId; SatChilddb.SaveChangesAsync(); return(RedirectToAction("Index", new { message = SupportMessages.EditSuccess })); }