public TransportRateConfirmationDto Update(Guid id, TransportRateCreateDto dto) { Transport transport = TransportMock.Transports.FirstOrDefault(e => e.Id == dto.TransportId); if (transport == null) { return(null); } var rate = _context.TransportRate.FirstOrDefault(e => e.Id == id); if (rate == null) { return(null); } rate.Description = dto.Description; rate.RateScale = dto.RateScale; rate.RateTypeId = dto.RateTypeId; rate.TransportId = dto.TransportId; _context.SaveChanges(); _logger.Log("Update TransportRate"); return(_mapper.Map <TransportRateConfirmationDto>(rate)); }
public TransportRateConfirmationDto Create(TransportRateCreateDto dto) { Transport transport = TransportMock.Transports.FirstOrDefault(e => e.Id == dto.TransportId); if (transport == null) { return(null); } TransportRate newRate = new TransportRate() { Id = Guid.NewGuid(), Description = dto.Description, RateScale = dto.RateScale, RateTypeId = dto.RateTypeId, TransportId = dto.TransportId }; _context.TransportRate.Add(newRate); _context.SaveChanges(); _logger.Log("Create TransportRate"); return(_mapper.Map <TransportRateConfirmationDto>(newRate)); }
public ActionResult Put(Guid id, TransportRateCreateDto dto) { var entity = _service.Update(id, dto); if (entity == null) { return(NotFound()); } return(Ok(entity)); }
public ActionResult Post([FromBody] TransportRateCreateDto dto) { var entity = _service.Create(dto); return(Ok(entity)); }