public UseTicket Update(UseTicket updatedUseTicket) { UseTicket changedUseTicket = _useTicketRepo.Update(updatedUseTicket); if (changedUseTicket == null) { throw new ApplicationException("That ticket does not exist to be updated."); } return(changedUseTicket); }
public UseTicket Add(UseTicket newUseTicket) { UseTicket addedUseTicket = _useTicketRepo.Add(newUseTicket); if (addedUseTicket == null) { throw new ApplicationException("That ticket already exists."); } return(addedUseTicket); }
public UseTicket GetById(int id) { UseTicket useTicket = _useTicketRepo.GetById(id); if (useTicket == null) { throw new ApplicationException("That use ticket does not exist."); } return(useTicket); }
public UseTicket Add(UseTicket newUseTicket) { UseTicket useTicketCheck = _dbContext.UseTickets.FirstOrDefault(ut => ut.Id == newUseTicket.Id); if (useTicketCheck != null) { return(null); } _dbContext.UseTickets.Add(newUseTicket); _dbContext.SaveChanges(); return(newUseTicket); }
public UseTicket GetById(int id) { UseTicket useTicket = _dbContext.UseTickets.FirstOrDefault(ut => ut.Id == id); if (useTicket == null) { return(null); } return(_dbContext.UseTickets .Include(ut => ut.User) .Include(ut => ut.Company) .FirstOrDefault(ut => ut.Id == id)); }
public bool Delete(int id) { UseTicket delTicket = GetById(id); if (delTicket == null) { return(false); } _dbContext.Remove(delTicket); _dbContext.SaveChanges(); return(true); }
public IActionResult Post([FromBody] UseTicketApiModel useTicket) { try { UseTicket newTicket = useTicket.ToDomainModel(); newTicket = _useTicketService.Add(newTicket); return(Ok(newTicket.ToApiModel())); } catch (Exception ex) { ModelState.AddModelError("CreatUseTicketError", ex.Message); return(BadRequest(ModelState)); } }
public IActionResult Put(int id, [FromBody] UseTicketApiModel useTicket) { try { UseTicket updatedTicket = useTicket.ToDomainModel(); updatedTicket.Id = id; updatedTicket = _useTicketService.Update(updatedTicket); return(Ok(updatedTicket.ToApiModel())); } catch (Exception ex) { ModelState.AddModelError("UpdateUseTicketError", ex.Message); return(BadRequest(ModelState)); } }
public UseTicket Update(UseTicket updatedUseTicket) { UseTicket currentTicket = _dbContext.UseTickets.FirstOrDefault(ut => ut.Id == updatedUseTicket.Id); if (currentTicket == null) { return(null); } _dbContext.Entry(currentTicket) .CurrentValues .SetValues(updatedUseTicket); _dbContext.UseTickets.Update(currentTicket); _dbContext.SaveChanges(); return(currentTicket); }
public static UseTicketApiModel ToApiModel(this UseTicket useTicket) { return(new UseTicketApiModel { Id = useTicket.Id, TISNumber = useTicket.TISNumber, Date = useTicket.Date, Notes = useTicket.Notes, companyId = useTicket.CompanyId, Company = useTicket.Company != null ? useTicket.Company.Name : null, UserId = useTicket.UserId, User = useTicket.User != null ? useTicket.User.FullName : null }); }