public ResponseVM Delete(Guid id) { using (context) { if (context.TicketMinors.Where(x => x.TicketMinorid == id && x.Status == "Open").Any()) { return(new ResponseVM("deleted", false, "TicketMinor", "Can't delete! Ticket is still open.")); } using (var dbTransaction = context.Database.BeginTransaction()) { try { TicketMinor ticketMinorToBeDeleted = context.TicketMinors.Find(id); if (ticketMinorToBeDeleted == null) { return(new ResponseVM("deleted", false, "TicketMinor", ResponseVM.DOES_NOT_EXIST)); } context.TicketMinors.Remove(ticketMinorToBeDeleted); context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("deleted", true, "TicketMinor")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("deleted", false, "TicketMinor", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }
public ResponseVM Update(TicketMinorVM ticketMinorVM) { using (context) { using (var dbTransaction = context.Database.BeginTransaction()) { try { TicketMinor ticketMinorToBeUpdated = context.TicketMinors.Find(ticketMinorVM.TicketMinorid); if (ticketMinorToBeUpdated == null) { return(new ResponseVM("updated", false, "TicketMinor", ResponseVM.DOES_NOT_EXIST)); } ticketMinorToBeUpdated.DateAccomplished = DateTime.Now; ticketMinorToBeUpdated.WorkByid = Guid.Parse(ticketMinorVM.WorkByid); ticketMinorToBeUpdated.WorkDone = ticketMinorVM.WorkDone; ticketMinorToBeUpdated.Status = ticketMinorVM.Status; context.SaveChanges(); dbTransaction.Commit(); return(new ResponseVM("updated", true, "TicketMinor")); } catch (Exception ex) { dbTransaction.Rollback(); return(new ResponseVM("updated", false, "TicketMinor", ResponseVM.SOMETHING_WENT_WRONG, "", ex)); } } } }