public ResultDto Add([FromBody] TruckageDto model) { if (!ModelState.IsValid) { return new ResultDto { Success = false, Message = "Não foi possível cadastrar frete. Verifique se está preenchido corretamente." } } ; DateTimeFormatInfo dfiTruckage = DateTimeFormatInfo.CurrentInfo; DateTime dateTruckage = model.CreatedAt; Calendar calTruckage = dfiTruckage.Calendar; var weekOfTheYear = calTruckage.GetWeekOfYear(dateTruckage, dfiTruckage.CalendarWeekRule, dfiTruckage.FirstDayOfWeek); var truckage = new Truckage(model.TruckageId, model.IsCargo, model.IsLeavingLoaded, model.CreatedAt, weekOfTheYear, model.LatitudeOrigin, model.LongitudeOrigin, model.LatitudeDestiny, model.LongitudeDestiny, model.DriverId, model.TruckTypeId); _repository.Add(truckage); var resultTruckageDto = new ResultTruckageDto(truckage.TruckegaId, truckage.IsCargo, truckage.IsLeavingLoaded, truckage.CreatedAt, truckage.WeekOfTheYear, truckage.LatitudeOrigin, truckage.LongitudeOrigin, truckage.LatitudeDestiny, truckage.LongitudeDestiny, truckage.DriverId, truckage.TruckTypeId); return(new ResultDto { Success = true, Message = "Frete cadastrado com sucesso.", Data = resultTruckageDto }); }
public ResultDto Update([FromBody] TruckageDto model) { if (!ModelState.IsValid) { return new ResultDto { Success = false, Message = "Não foi possível alterar os dados do frete. Verifique se está preenchido corretamente." } } ; var truckage = new Truckage(model.TruckageId, model.IsCargo, model.IsLeavingLoaded, model.CreatedAt, model.WeekOfTheYear, model.LatitudeOrigin, model.LongitudeOrigin, model.LatitudeDestiny, model.LongitudeDestiny, model.DriverId, model.TruckTypeId); _repository.Update(truckage); var resultTruckageDto = new ResultTruckageDto(truckage.TruckegaId, truckage.IsCargo, truckage.IsLeavingLoaded, truckage.CreatedAt, truckage.WeekOfTheYear, truckage.LatitudeOrigin, truckage.LongitudeOrigin, truckage.LatitudeDestiny, truckage.LongitudeDestiny, truckage.DriverId, truckage.TruckTypeId); return(new ResultDto { Success = true, Message = "Dados atualizados com sucesso.", Data = resultTruckageDto }); } }
public ResultTruckageDto Get(int id) { var consult = _context.Truckages.FirstOrDefault(t => t.TruckegaId == id); var resultTruckageDto = new ResultTruckageDto(consult.TruckegaId, consult.IsCargo, consult.IsLeavingLoaded, consult.CreatedAt, consult.WeekOfTheYear, consult.LatitudeOrigin, consult.LongitudeOrigin, consult.LatitudeDestiny, consult.LongitudeDestiny, consult.DriverId, consult.TruckTypeId); return(resultTruckageDto); }