private void ValidateRequest(string origin, string destiny, ShipsToRequestModel entity, out WarehouseResponse originWarehouse, out WarehouseResponse destinyWarehouse) { if (entity == null) { throw new HttpRequestException(_errorHandler.GetErrorMessage(ErrorMessagesEnum.EntityNull)); } if (!ModelState.IsValid) { throw new HttpRequestException(string.Format(_errorHandler.GetErrorMessage(ErrorMessagesEnum.ModelValidation), ModelState.Values.First().Errors.First().ErrorMessage)); } originWarehouse = GetWarehouseByName(origin); destinyWarehouse = GetWarehouseByName(destiny); }
public void UpdateRoute([Required] string origin, [Required] string destiny, [FromBody] ShipsToRequestModel entity) { WarehouseResponse originWarehouse, destinyWarehouse; ValidateRequest(origin, destiny, entity, out originWarehouse, out destinyWarehouse); if (!_service.GetDirectRoute(originWarehouse.Id, destinyWarehouse.Id).Any()) { throw new HttpRequestException(_errorHandler.GetErrorMessage(ErrorMessagesEnum.EntityNotFound)); } var request = new ShipsToRequest { Cost = entity.Cost, Time = entity.Time, Origin = originWarehouse, Destiny = destinyWarehouse }; _service.Update(request); }