public async Task <PromoterCommandResponse> Handle(CreatePromoterCommand command) { await _promoterDomainService.CheckPromoterIsExist(command.NationalCode); var code = _seqRepository.GetNextSequenceValue(SqNames.PromoterSequence); var promoter = new Promoter(Guid.NewGuid(), code, command.FirstName, command.LastName, command.NationalCode, command.MobileNumber); _repository.Add(promoter); return(new PromoterCommandResponse()); }
public async Task <CreateShopCommandResponse> Handle(CreateShopCommand command) { var shopNumber = _seqRepository.GetNextSequenceValue(SqNames.ShopNumberSequence); var marketer = await _marketerRepository.AsQuery().SingleOrDefaultAsync(p => p.BarcodeId == command.BarcodeId); if (marketer == null) { throw new DomainException("بازاریاب یافت نشد"); } _marketerDomainService.CheckMarketerActive(marketer); _marketerDomainService.CheckMaxMarketerAllowedIsEnough(marketer); _personDomainService.CheckShopIsExist(command.UserId); var city = _cityRepository.Find(command.Address.CityId); if (city == null) { throw new DomainException("شهر وارد شده یافت نشد"); } var appSetting = await _applicationSettingRepository.AsQuery().SingleOrDefaultAsync(); if (appSetting == null) { throw new DomainException("تنظیمات برنامه یافت نشد"); } if (command.DefaultDiscount < appSetting.MinimumDiscount || command.DefaultDiscount > appSetting.MaximumDiscount) { throw new DomainException("تخفیف پیش فرض در بازه تخفیفات معتبر نمی باشد"); } var address = new ShopAddress(city.Id, city.Code, city.CityName, command.Address.AddressText, command.Address.PhoneNumber, command.Address.Position.ToDbGeography(), command.Address.ShopMobileNumber, command.Address.ZoneId, city.Province.Id, city.Province.Code, city.Province.Name); var accountBank = new BankAccount(command.BankAccount.Iban, command.BankAccount.AccountOwnerName, command.BankAccount.AccountNumber); var imageDocument = new ImageDocuments(command.ImageDocuments.FaceImage, command.ImageDocuments.NationalCardImage); var shop = new Shop(Guid.NewGuid(), command.Name, command.FirstName, command.LastName, command.EmailAddress, command.UserId, command.Description, command.NationalCode, address, accountBank, imageDocument, command.MobileNumber, command.AreaRadius, command.Metrage, command.DefaultDiscount, marketer.Id, shopNumber) { AppInfos = new List <AppInfo>(), CustomerSubsets = new List <ShopCustomerSubset>() }; _repository.Add(shop); DomainEventDispatcher.Raise(new AssignmentShopMarketersHistoryEvent(shop, marketer, new UserInfo(command.UserId, command.MobileNumber, "کاربر موبایل"))); DomainEventDispatcher.Raise(new AddPanelNotificationEvent(Guid.NewGuid(), command.Name, "فروشگاه ایجاد شد", PanelNotificationType.ShopCreated, shop.Id.ToString())); return(new CreateShopCommandResponse()); }
public Task <CreateCustomerCommandResponse> Handle(CreateCustomerCommand command) { var customerNumber = _seqRepository.GetNextSequenceValue(SqNames.CustomerNumberSequence); _personDomainService.CheckCustomerIsExist(command.UserId); var customer = new Customer(Guid.NewGuid(), command.FirstName, command.LastName, command.EmailAddress, command.UserId, DefultCustomerAddress.CreateNull(), command.MobileNumber, customerNumber, command.BirthDate) { CustomerAddresses = new List <CustomerAddress>(), AppInfos = new List <AppInfo>() }; _repository.Add(customer); _personDomainService.SetCustomerRecommender(command.RecommendCode, customer); return(Task.FromResult(new CreateCustomerCommandResponse())); }
public async Task <AcceptOrderSuggestionCommandResponse> Handle(AcceptOrderSuggestionCommand command) { var setting = _applicationSettingRepository.AsQuery().FirstOrDefault(); var orderSuggestion = await _repository.AsQuery().SingleOrDefaultAsync(p => p.Id == command.OrderSuggestionId); if (orderSuggestion == null) { throw new DomainException("پیشنهاد سفارش یافت نشد"); } var order = _orderRepository.AsQuery().SingleOrDefault(p => p.Id == orderSuggestion.OrderId); if (order == null) { throw new DomainException("سفارش یافت نشد"); } if (DateTime.Now > orderSuggestion.CreationTime.AddMinutes(setting.OrderSuggestionExpireTime)) { throw new DomainException("زمان تایید پیشنهاد پایان یافته است"); } var selectedOrderSuggestionItems = orderSuggestion.OrderSuggestionItems.Where(p => command.AcceptOrderSuggestionItem.Any(i => i.OrderSuggestionItemId == p.Id)) .ToList(); long factorId = _seqRepository.GetNextSequenceValue(SqNames.FactorIdSequence); List <FactorRaw> factorRaws = new List <FactorRaw>(); var havePercentDiscountToday = _orderDomainService.CheckOrderPercentDiscountToday(order.Customer, orderSuggestion.OrderId); foreach (var selectedOrderSuggestionItem in selectedOrderSuggestionItems) { switch (selectedOrderSuggestionItem) { case AlternativeProductSuggestionItem alternativeProductSuggestionItem: { var itemQuantity = command.AcceptOrderSuggestionItem.SingleOrDefault(p => p.OrderSuggestionItemId == selectedOrderSuggestionItem.Id); var quantity = itemQuantity?.Quantity ?? alternativeProductSuggestionItem.Quantity; var product = _productRepository.Find(alternativeProductSuggestionItem .AlternativeProductSuggestion.ProductId); if (product == null) { throw new DomainException("محصول جایگزین یافت نشد"); } var factorRaw = new FactorRaw(product.Id, quantity, alternativeProductSuggestionItem.Description, alternativeProductSuggestionItem.Price, product.Name, alternativeProductSuggestionItem.AlternativeProductSuggestion .ProductImage, product.Brand.Id, product.Brand.Name, null); factorRaws.Add(factorRaw); break; } case HasProductSuggestionItem hasProductSuggestionItem: { var itemQuantity = command.AcceptOrderSuggestionItem.SingleOrDefault(p => p.OrderSuggestionItemId == selectedOrderSuggestionItem.Id); var quantity = itemQuantity?.Quantity ?? hasProductSuggestionItem.Quantity; var product = _productRepository.Find(hasProductSuggestionItem.OrderItem.OrderProduct.ProductId); FactorRaw factorRaw; if (havePercentDiscountToday) { if (hasProductSuggestionItem.OrderItem.Discount != null) { if (hasProductSuggestionItem.OrderItem.Discount is OrderItemPercentDiscount orderItemPercentDiscount) { if (orderItemPercentDiscount.HasDiscountValid()) { factorRaw = new FactorRaw(product.Id, quantity, hasProductSuggestionItem.Description, hasProductSuggestionItem.Price, product.Name, hasProductSuggestionItem.OrderItem.OrderProduct.ProductImage, product.Brand.Id, product.Brand.Name, new FactorRawPercentDiscount(Guid.NewGuid(), orderItemPercentDiscount.DiscountId, orderItemPercentDiscount.DiscountTitle, orderItemPercentDiscount.FromDate, orderItemPercentDiscount.ToDate, orderItemPercentDiscount.Percent, orderItemPercentDiscount.FromTime, orderItemPercentDiscount.ToTime)); } else { factorRaw = new FactorRaw(product.Id, quantity, hasProductSuggestionItem.Description, hasProductSuggestionItem.Price, product.Name, hasProductSuggestionItem.OrderItem.OrderProduct.ProductImage, product.Brand.Id, product.Brand.Name, null); } } else { factorRaw = new FactorRaw(product.Id, quantity, hasProductSuggestionItem.Description, hasProductSuggestionItem.Price, product.Name, hasProductSuggestionItem.OrderItem.OrderProduct.ProductImage, product.Brand.Id, product.Brand.Name, null); } } else { factorRaw = new FactorRaw(product.Id, quantity, hasProductSuggestionItem.Description, hasProductSuggestionItem.Price, product.Name, hasProductSuggestionItem.OrderItem.OrderProduct.ProductImage, product.Brand.Id, product.Brand.Name, null); } } else { factorRaw = new FactorRaw(product.Id, quantity, hasProductSuggestionItem.Description, hasProductSuggestionItem.Price, product.Name, hasProductSuggestionItem.OrderItem.OrderProduct.ProductImage, product.Brand.Id, product.Brand.Name, null); } factorRaws.Add(factorRaw); break; } } } DomainEventDispatcher.Raise(new TheOrderStatusWentToAcceptEvent(order)); DomainEventDispatcher.Raise(new CreateFactorEvent(factorId, order.Id, orderSuggestion.Id, CalcTotalPrice(factorRaws), orderSuggestion.Discount, factorRaws, orderSuggestion.Shop, order.Customer, order, orderSuggestion.ShippingTime)); orderSuggestion.OrderSuggestionStatus = OrderSuggestionStatus.Accept; return(new AcceptOrderSuggestionCommandResponse(factorId)); }