示例#1
0
        public void CompleteOrder(Guid orderId)
        {
            var order = _orderRepository.Get(orderId);

            Validate.Found(order, "Orderan");
            order.Complete();
            _orderRepository.Update(order);

            var tenant  = _tenantManager.FindByIdAsync(order.TenantId).Result;
            var message = NotificationMessageHelper.GenerateCompleteMessage(order, tenant);

            WhatsappAPI.SendMessage(order.Customer.WhatsappNumber, message);
        }
示例#2
0
        public void Approve(Guid id)
        {
            var order = _orderRepository.Get(id);

            Validate.Found(order, "Orderan");
            order.Approve();
            _orderRepository.Update(order);

            var tenant  = GetCurrentTenant();
            var message = NotificationMessageHelper.GenerateApprovedMessage(order, tenant);

            WhatsappAPI.SendMessage(order.Customer.WhatsappNumber, message);
        }
示例#3
0
        public void Cancel(CancelPaymentInputDto inputDto)
        {
            var order = _orderRepository.Get(inputDto.Id);

            Validate.Found(order, "Orderan");
            order.Cancel();
            _orderRepository.Update(order);

            var tenant  = GetCurrentTenant();
            var message = NotificationMessageHelper.GenerateCancelOrderMessage(order, inputDto.Reason, tenant);

            WhatsappAPI.SendMessage(order.Customer.WhatsappNumber, message);
        }
示例#4
0
        public Guid AddPayment(ConfirmationOrderInputDto inputDto)
        {
            var order = _orderRepository.Get(inputDto.Id);

            Validate.Found(order, "Orderan");
            var fileName = string.Format("{0}_{1}", order.OrderNumber, order.Payment.PaymentHistories.Count + 1);
            var filePath = _imageGenerator.SavePaymentReceipt(inputDto.generateImage(), fileName, JpegFormat.Instance);

            order.AddPayment(inputDto.BankName, inputDto.AccountName, inputDto.AccountNumber, filePath);
            _orderRepository.Update(order);

            var tenant  = GetCurrentTenant();
            var message = NotificationMessageHelper.GenerateConfirmationMessage(order, tenant);

            WhatsappAPI.SendMessage(order.Customer.WhatsappNumber, message);

            return(order.Id);
        }
示例#5
0
        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));
        }