public Notification Validate(DepotOrderDto depotOrderDto) { Notification notification = new Notification(); if (depotOrderDto == null) { notification.addError("Missing data"); return(notification); } if (string.IsNullOrEmpty(depotOrderDto.DocumentNumber)) { notification.addError("DocumentNumber is missing"); } if (string.IsNullOrEmpty(depotOrderDto.CustomerIdentificationNumber)) { notification.addError("CustomerIdentificationNumber is missing"); } if (string.IsNullOrEmpty(depotOrderDto.OceanCarrierSCACCode)) { notification.addError("OceanCarrierSCACCode is missing"); } if (string.IsNullOrEmpty(depotOrderDto.PortISOCode)) { notification.addError("PortISOCode is missing"); } if (string.IsNullOrEmpty(depotOrderDto.RequestDate.ToString())) { notification.addError("RequestDate is missing"); } if (depotOrderDto.TotalAmount < 0) { notification.addError("TotalAmount can't be negative"); } if (string.IsNullOrEmpty(depotOrderDto.CurrencyISOCode.ToString())) { notification.addError("CurrencyISOCode is missing"); } return(notification); }
public DepotOrder FromDepotOrderDtoToDepotOrder(DepotOrderDto depotOrderDto) { return(_mapper.Map <DepotOrderDto, DepotOrder>(depotOrderDto)); }
public Customer FromDepotOrderDtoToCustomer(DepotOrderDto depotOrderDto) { return(_mapper.Map <DepotOrderDto, Customer>(depotOrderDto)); }
public IActionResult CreateDepotOrder([FromBody] DepotOrderDto depotOrderDto) { bool uowStatus = false; try { var notification = _depotOrderDtoValidator.Validate(depotOrderDto); throwErrors(notification); uowStatus = _unitOfWork.BeginTransaction(); var customer = _customerAssembler.FromDepotOrderDtoToCustomer(depotOrderDto); // Handled by ConsoleLogger since the console has a loglevel of all logger.Message("Verifying customer exists", LogLevel.Debug); Customer searchCustomer = _customerRepository.GetByIdentificationNumber(depotOrderDto.CustomerIdentificationNumber); logger.Message("Customer retrieved.", LogLevel.Info); if (searchCustomer == null) { // Handled by ConsoleLogger and FileLogger since filelogger implements Warning & Error logger.Message("Customer doesn't exist", LogLevel.Warning); logger.Message("Preventing NULL exception", LogLevel.Error); // Handled by ConsoleLogger and EmailLogger as it implements functional error logger.Message("Business exception", LogLevel.FunctionalError); return(StatusCode(StatusCodes.Status400BadRequest, _apiResponseHandler.AppErrorResponse("Customer doesn't exist"))); } DepotOrder depotOrder = _depotOrderAssembler.FromDepotOrderDtoToDepotOrder(depotOrderDto); Port _port = (Port)Enum.Parse(typeof(Port), depotOrderDto.PortISOCode); depotOrder.PortId = (long)_port; depotOrder.Customer = searchCustomer; OceanCarrier _oceanCarrier = (OceanCarrier)Enum.Parse(typeof(OceanCarrier), depotOrderDto.OceanCarrierSCACCode); depotOrder.OceanCarrierId = (long)_oceanCarrier; depotOrder.ValidateDepotOrder(notification); throwErrors(notification); _depotOrderRepository.Create(depotOrder); List <DepotOrderEquipment> depotOrderEquipments = _depotOrderEquipmentAssembler.ToEntityList(depotOrderDto.Equipments); depotOrderEquipments.ForEach(x => x.DepotOrder = depotOrder); depotOrderEquipments.ForEach(x => _depotOrderEquipmentRepository.Create(x)); _unitOfWork.Commit(uowStatus); var message = "DepotOrder created!"; // Handled by ConsoleLogger and EmailLogger logger.Message(message, LogLevel.FunctionalMessage); KipubitRabbitMQ.SendMessage(message); return(StatusCode(StatusCodes.Status201Created, new ApiStringResponseDto(message))); } catch (ArgumentException ex) { _unitOfWork.Rollback(uowStatus); Console.WriteLine(ex.StackTrace); logger.Message(ex.StackTrace, LogLevel.Error); KipubitRabbitMQ.SendMessage(ex.StackTrace); return(BadRequest(_apiResponseHandler.AppErrorResponse(ex.Message))); } catch (Exception ex) { _unitOfWork.Rollback(uowStatus); Console.WriteLine(ex.StackTrace); logger.Message(ex.StackTrace, LogLevel.Error); var message = "Internal Server Error"; KipubitRabbitMQ.SendMessage(message); return(StatusCode(StatusCodes.Status500InternalServerError, _apiResponseHandler.AppErrorResponse(message))); } }