public OrderDto CreateOrder(CreateOrderInputDto inputDto) { var tenant = GetCurrentTenant(); var district = _districtRepository.FirstOrDefault(i => i.Id == inputDto.DistrictId); Validate.Found(district, "Kecamatan"); var paymentMethod = _paymentMethodRepository.FirstOrDefault(i => i.Bank.Code == inputDto.PaymentMethodCode); Validate.Found(paymentMethod, "Metode Pembayaran", inputDto.PaymentMethodCode); var order = Order.Create(inputDto.Name, inputDto.Email, inputDto.Whatsapp, district, inputDto.Address, inputDto.Note, paymentMethod, (transactionDate) => { return(_autoNumberGenerator.GenerateOrderNumber(transactionDate)); }); foreach (var itemInputDto in inputDto.Items) { var product = _productRepository.Get(itemInputDto.ProductId); Validate.Found(product, "Produk"); order.AddItem(product, itemInputDto.Quantity, itemInputDto.Note); } var expeditionService = _expeditionServiceRepository.FirstOrDefault(i => i.Id == inputDto.ExpeditionServiceId); Validate.Found(expeditionService, "Ekpedisi"); order.AddShipment(expeditionService, (totalWeight) => { var getFreightByServiceInputDto = new GetFreightByServiceInputDto(expeditionService, tenant.District, district, totalWeight); var freightResult = _freightAppService.GetFreightByExpeditionService(getFreightByServiceInputDto); return(Tuple.Create(freightResult.Cost, freightResult.EstimatedTimeDelivery)); }); _orderRepository.Insert(order); var message = NotificationMessageHelper.GenerateDraftMessage(order, tenant); WhatsappAPI.SendMessage(order.Customer.WhatsappNumber, message); return(Mapper.Map <OrderDto>(order)); }
public OrderDto CreateOrder(CreateOrderInputDto inputDto) { var order = _orderAppService.CreateOrder(inputDto); return(order); }