public BestStartGrantBuilder WithCompletedSections(bool markAsCompleted = true) { With(f => f.Consent, ConsentBuilder.NewValid()); With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid()); With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid()); With(f => f.ExistingChildren, ExistingChildrenBuilder.NewValid()); With(f => f.ApplicantBenefits, BenefitsBuilder.NewWithBenefit()); With(f => f.PartnerBenefits, BenefitsBuilder.NewWithBenefit()); With(f => f.GuardianBenefits, BenefitsBuilder.NewWithBenefit()); With(f => f.GuardianPartnerBenefits, BenefitsBuilder.NewWithBenefit()); With(f => f.PartnerDetails, RelationDetailsBuilder.NewValid("partner")); With(f => f.GuardianDetails, RelationDetailsBuilder.NewValid("guardian")); With(f => f.GuardianPartnerDetails, RelationDetailsBuilder.NewValid("guardian partner")); With(f => f.HealthProfessional, HealthProfessionalBuilder.NewValid()); With(f => f.PaymentDetails, PaymentDetailsBuilder.NewValid()); With(f => f.Evidence, EvidenceBuilder.NewValid()); With(f => f.Declaration, DeclarationBuilder.NewValid()); With(f => f.Started, DomainRegistry.NowUtc() - TimeSpan.FromHours(24)); With(f => f.Completed, DomainRegistry.NowUtc()); With(f => f.UserId, _instance.ApplicantDetails?.EmailAddress); VerifyConsistent(_instance); if (!markAsCompleted) { With(f => f.Completed, null); } return(this); }
public List <CouponDTO> Calculate(CartRequest cart) { var couponNos = DomainRegistry.CouponNoRepository().GetNotUsedByUserId(cart.UserId); var buyProductIds = cart.CartItems.Select(ent => ent.ProductId); List <CouponDTO> couponDtos = new List <CouponDTO>(); foreach (var couponNo in couponNos) { if (couponNo.IsUsed) { continue; } var coupon = DomainRegistry.CouponRepository().GetByIdentity(couponNo.CouponId); if (coupon.ContainsProductIds.Count == 0 || coupon.ContainsProductIds.Any(ent => buyProductIds.Any(e => e == ent))) { couponDtos.Add(new CouponDTO { CanUse = couponNo.IsUsed, ExpiryDate = coupon.ExpiryDate, ID = couponNo.ID, Name = coupon.Name, Value = coupon.Value }); } } return(couponDtos); }
public static ApplicantDetails NewValid(Action <ApplicantDetails> mutator = null) { var value = new ApplicantDetails { Title = "test title", FirstName = "test first name", OtherNames = "test other names", SurnameOrFamilyName = "test surname or family name", DateOfBirth = DomainRegistry.NowUtc().Date.AddYears(-19), PreviouslyLookedAfter = false, FullTimeEducation = false, NationalInsuranceNumber = "AB123456C", CurrentAddress = AddressBuilder.NewValid("applicant"), EmailAddress = "*****@*****.**", PhoneNumer = "01234 567 890", MobilePhoneNumber = "12345 678 901", }; if (mutator != null) { mutator(value); } return(value); }
public Result Create(OrderRequest orderRequest) { if (!string.IsNullOrWhiteSpace(orderRequest.CouponId)) { var couponResult = DomainRegistry.SellingPriceService().IsCouponCanUse(orderRequest.CouponId, orderRequest.OrderTime); if (!couponResult.IsSuccess) { return(Result.Fail(couponResult.Msg)); } } var orderId = DomainRegistry.OrderRepository().NextIdentity(); var order = Domain.Order.Aggregate.Order.Create(orderId, orderRequest.UserId, orderRequest.Receiver, orderRequest.CountryId, orderRequest.CountryName, orderRequest.ProvinceId, orderRequest.ProvinceName, orderRequest.CityId, orderRequest.CityName, orderRequest.DistrictId, orderRequest.DistrictName, orderRequest.Address, orderRequest.Mobile, orderRequest.Phone, orderRequest.Email, orderRequest.PaymentMethodId, orderRequest.PaymentMethodName, orderRequest.ExpressId, orderRequest.ExpressName, orderRequest.Freight, orderRequest.CouponId, orderRequest.CouponName, orderRequest.CouponValue, orderRequest.OrderTime); foreach (var orderItemRequest in orderRequest.OrderItems) { order.AddOrderItem(orderItemRequest.ProductId, orderItemRequest.Quantity, orderItemRequest.UnitPrice, orderItemRequest.JoinedMultiProductsPromotionId, orderItemRequest.ProductName); } //DomainRegistry.OrderRepository().Save(order); IUnitOfWork unitOfWork = new SqlServerUnitOfWork(); unitOfWork.RegisterSaved(order); unitOfWork.Commit(); return(Result.Success()); }
public ChangeOfCircsBuilder WithCompletedSections(bool markAsCompleted = true, bool excludeOptionalSections = false) { With(f => f.Consent, ConsentBuilder.NewValid()); With(f => f.UserId, "*****@*****.**"); With(f => f.ExistingApplicantDetails, ApplicantDetailsBuilder.NewValid(ad => ad.Address = AddressBuilder.NewValid("existing"))); With(f => f.ExistingPaymentDetails, PaymentDetailsBuilder.NewValid()); With(f => f.Options, OptionsBuilder.NewValid()); if (!excludeOptionalSections) { With(f => f.ApplicantDetails, ApplicantDetailsBuilder.NewValid()); With(f => f.ExpectedChildren, ExpectedChildrenBuilder.NewValid()); With(f => f.HealthProfessional, HealthProfessionalBuilder.NewValid()); With(f => f.PaymentDetails, PaymentDetailsBuilder.NewValid()); } With(f => f.Evidence, EvidenceBuilder.NewValid()); With(f => f.Declaration, DeclarationBuilder.NewValid()); With(f => f.Started, DomainRegistry.NowUtc() - TimeSpan.FromHours(24)); With(f => f.Completed, DomainRegistry.NowUtc()); VerifyConsistent(_instance); if (!markAsCompleted) { With(f => f.Completed, null); } return(this); }
private WaitCreateOrder ConvertToWaitCreateOrder(Cart cart, SellingPriceCart sellingPriceCart, ShippingAddress shippingAddress, PaymentMethod paymentMethod, Express express, Coupon coupon) { var orderItems = new List <WaitCreateOrderItem>(); foreach (var sellingPriceFullGroup in sellingPriceCart.FullGroups) { foreach (var sellingPriceCartItem in sellingPriceFullGroup.CartItems) { var cartItem = cart.GetCartItem(sellingPriceCartItem.ProductId); var product = DomainRegistry.ProductService().GetProduct(cartItem.ID); var unitPrice = cartItem.UnitPrice - sellingPriceCartItem.ReducePrice; orderItems.Add(new WaitCreateOrderItem(sellingPriceCartItem.ProductId, cartItem.Quantity, unitPrice, sellingPriceFullGroup.MultiProductsPromotionId, product.SaleName)); } } foreach (var sellingPriceCartItem in sellingPriceCart.CartItems) { var cartItem = cart.GetCartItem(sellingPriceCartItem.ProductId); var product = DomainRegistry.ProductService().GetProduct(cartItem.ID); orderItems.Add(new WaitCreateOrderItem(sellingPriceCartItem.ProductId, cartItem.Quantity, cartItem.UnitPrice, null, product.SaleName)); } return(new WaitCreateOrder(cart.ID, cart.UserId, shippingAddress.Receiver, shippingAddress.CountryId, shippingAddress.CountryName, shippingAddress.ProvinceId, shippingAddress.ProvinceName, shippingAddress.CityId, shippingAddress.CityName, shippingAddress.DistrictId, shippingAddress.DistrictName, shippingAddress.Address, shippingAddress.Mobile, shippingAddress.Phone, shippingAddress.Email, paymentMethod.ID, paymentMethod.Name, express.ID, express.Name, express.Freight, coupon.ID, coupon.Name, coupon.Value, DateTime.Now, orderItems)); }
public Result EditShippingAddress(string userId, DeliveryEditShippingAddressRequest request) { var newAddress = new ShippingAddress(request.ShippingAddressId, userId, request.Receiver, request.CountryId, request.CountryName, request.ProvinceId, request.ProvinceName, request.CityId, request.CityName, request.DistrictId, request.DistrictName, request.Address, request.Mobile, request.Phone, request.Email); DomainRegistry.UserService().EditShippingAddress(newAddress); return(Result.Success()); }
public static ExpectedChildren ExpectedBabyCount(this ExpectedChildren expectedChildren, int?babyCount) { expectedChildren.IsBabyExpected = babyCount > 0; expectedChildren.ExpectancyDate = DomainRegistry.NowUtc().Date.AddDays(100); expectedChildren.IsMoreThan1BabyExpected = babyCount > 1; expectedChildren.ExpectedBabyCount = babyCount > 1 ? babyCount.Value : (int?)null; return(expectedChildren); }
public Result Buy(Guid userId, Guid productId, int quantity) { var cartItem = _userBuyProductDomainService.UserBuyProduct(userId, productId, quantity); var cart = _getUserCartDomainService.GetUserCart(userId); cart.AddCartItem(cartItem); DomainRegistry.CartRepository().Save(cart); return(Result.Success()); }
public List <PaymentMethodDTO> GetAllCanUsePaymentMethods() { var paymentMethods = DomainRegistry.PaymentService().GetAllPaymentMethods(); return(paymentMethods.Select(ent => new PaymentMethodDTO { ID = ent.ID, Name = ent.Name }).ToList()); }
public WalletDTO GetUserWallet(string userId) { var wallet = DomainRegistry.PaymentService().GetWalletByUserId(userId); return(new WalletDTO { AvailableBalance = wallet.AvailableBalance, AvailableScore = wallet.AvailableScore }); }
public static ExpectedChildren Populate(ExpectedChildren expectedChildren, Action <ExpectedChildren> mutator = null) { expectedChildren.IsBabyExpected = true; expectedChildren.ExpectancyDate = DomainRegistry.NowUtc().Date + TimeSpan.FromDays(100); expectedChildren.IsMoreThan1BabyExpected = true; expectedChildren.ExpectedBabyCount = 2; mutator?.Invoke(expectedChildren); return(expectedChildren); }
public List <ExpressDTO> GetAllCanUseExpresses() { var expresses = DomainRegistry.ExpressRepository().GetAll(); return(expresses.Select(ent => new ExpressDTO { Freight = ent.Freight, ID = ent.ID, Name = ent.Name }).ToList()); }
public CalculatedCartDTO Calculate(CartRequest cart) { List <BoughtProduct> boughtProducts = new List <BoughtProduct>(); foreach (var cartItemRequest in cart.CartItems) { var promotionRules = DomainRegistry.PromotionRepository().GetListByContainsProductId(cartItemRequest.ProductId); var boughtProduct = new BoughtProduct(cartItemRequest.ProductId, cartItemRequest.Quantity, cartItemRequest.UnitPrice, 0, promotionRules, cartItemRequest.SelectedMultiProductsPromotionId); boughtProducts.Add(boughtProduct); } #region 处理单品促销 foreach (var boughtProduct in boughtProducts.ToList()) { var calculateResult = _mergeSingleProductPromotionForOneProductDomainService.Merge(boughtProduct.ProductId, boughtProduct.DiscountedUnitPrice, boughtProduct.InSingleProductPromotionRules); var newBoughtProduct = boughtProduct.ChangeReducePrice(calculateResult); boughtProducts.Remove(boughtProduct); boughtProducts.Add(newBoughtProduct); } #endregion #region 处理多商品促销&构造DTO模型 List <CalculatedFullGroupDTO> fullGroupDtos = new List <CalculatedFullGroupDTO>(); foreach (var groupedPromotoinId in boughtProducts.Where(ent => ent.InMultiProductPromotionRule != null).GroupBy(ent => ((PromotionRule)ent.InMultiProductPromotionRule).PromotoinId)) { var multiProdcutsReducePricePromotion = (IMultiProdcutsReducePricePromotion)groupedPromotoinId.First().InMultiProductPromotionRule; //暂时只有减金额的多商品促销 var products = groupedPromotoinId.ToList(); if (multiProdcutsReducePricePromotion == null) { continue; } var reducePrice = multiProdcutsReducePricePromotion.CalculateReducePrice(products); fullGroupDtos.Add(new CalculatedFullGroupDTO { CalculatedCartItems = products.Select(ent => ent.ToDTO()).ToArray(), ReducePrice = reducePrice, MultiProductsPromotionId = groupedPromotoinId.Key }); } #endregion return(new CalculatedCartDTO { CalculatedCartItems = boughtProducts.Where(ent => fullGroupDtos.SelectMany(e => e.CalculatedCartItems).All(e => e.ProductId != ent.ProductId)) .Select(ent => ent.ToDTO()).ToArray(), CalculatedFullGroups = fullGroupDtos.ToArray(), CartId = cart.CartId }); }
protected void OnBeforeUpdate(bool isFinalUpdate) { if (Completed.HasValue) { throw new DomainException("This application has already been submitted and cannot be modified"); } if (isFinalUpdate) { Completed = DomainRegistry.NowUtc(); } }
private static ExistingChild NewChild(int index) { return(new ExistingChild { FirstName = $"child {index + 1} first name", Surname = $"child {index + 1} surname", DateOfBirth = DomainRegistry.NowUtc().Date.AddYears(-(10 + index * 2)), Relationship = Relationship.Parent, ChildBenefit = false, NoChildBenefitReason = $"unit test reason {index + 1}", }); }
private CartItemDTO ConvertToCartItem(SellingPriceCartItem sellingPriceCartItem, CartItem cartItem) { var product = DomainRegistry.ProductService().GetProduct(cartItem.ID); return(new CartItemDTO { ProductId = cartItem.ID, ProductName = product == null ? "商品已失效" : product.SaleName, ReducePrice = sellingPriceCartItem.ReducePrice, SalePrice = cartItem.UnitPrice }); }
public virtual void SetUp() { DataContext = new InMemoryDataContextWithGenerator(); Repository = new DomainRepository(DataContext); DomainRegistry.Repository = Repository; var mapper = GetMapper(); Mapper = mapper; DomainRegistry.SetMapperFunc(() => mapper); }
public Result SubmitOrder(SumbitOrderRequest request) { var cart = _confirmUserCartExistedDomainService.GetUserCart(request.UserId); if (cart.IsEmpty()) { return(Result.Fail("当前购物车中并没有商品")); } var sellingPriceCart = DomainRegistry.SellingPriceService().Calculate(cart); var shippingAddress = DomainRegistry.UserService().GetShippingAddress(request.ShippingAddressId); if (shippingAddress == null) { return(Result.Fail("对不起,你选择的收货地址已不存在!")); } var paymentMethod = DomainRegistry.PaymentService().GetPaymentMethod(request.PaymentMethodId); if (paymentMethod == null) { return(Result.Fail("对不起,你选择的支付方式已不存在!")); } var express = DomainRegistry.ExpressRepository().GetByIdentity(request.ExpressId); if (express == null) { return(Result.Fail("对不起,你选择的配送方式已不存在!")); } var coupon = DomainRegistry.SellingPriceService().GetCoupon(request.CouponId); if (coupon == null) { return(Result.Fail("对不起,你选择的礼券不存在!")); } if (coupon.CanUse) { return(Result.Fail("对不起,你选择的礼券已使用!")); } if (coupon.ExpiryDate < DateTime.Now) { return(Result.Fail("对不起,你选择的礼券已过期!")); } var waitCreateOrder = ConvertToWaitCreateOrder(cart, sellingPriceCart, shippingAddress, paymentMethod, express, coupon); return(DomainRegistry.OrderService().Create(waitCreateOrder)); }
public CartDTO GetCart(string userId) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(null); } var sellingPriceCart = DomainRegistry.SellingPriceService().Calculate(cart); return(ConvertToCart(cart, sellingPriceCart)); }
public Result DeleteCartItem(string userId, string id) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(Result.Fail("当前购物车中并没有商品")); } cart.RemoveCartItem(id); DomainRegistry.CartRepository().Save(cart); return(Result.Success()); }
public async Task Buy(Guid userId, Guid productId, int quantity) { var product = DomainRegistry.ProductService().GetProduct(productId); if (product == null) { throw new NotFoundException("对不起,未能获取产品信息,请重试~"); } var cart = DomainRegistry.MarketService().GetCartOfUser(userId); cart.AddCartItem(productId, quantity, product.Price); await DomainRegistry.Repository <ICartRepository>().SaveAsync <Guid, Domain.Market.Cart>(cart, true); }
public Result Buy(string userId, string productId, int quantity) { var product = DomainRegistry.ProductService().GetProduct(productId); if (product == null) { return(Result.Fail("对不起,未能获取产品信息请重试~")); } var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); cart.AddCartItem(productId, quantity, product.SalePrice); DomainRegistry.CartRepository().Save(cart); return(Result.Success()); }
internal int?Age() { if (!DateOfBirth.HasValue) { return(null); } var today = DomainRegistry.NowUtc().ToLocalTime().Date; var dob = DateOfBirth.Value; var age = today.Year - dob.Year; if (dob.AddYears(age) > today) { age--; // birthday has not happened this year } return(age); }
public Result ChangeQuantity(string userId, string id, int quantity) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(Result.Fail("当前购物车中并没有商品")); } var cartItem = cart.GetCartItem(id); if (cartItem == null) { return(Result.Fail("该购物项已不存在")); } cartItem.ModifyQuantity(quantity); DomainRegistry.CartRepository().Save(cart); return(Result.Success()); }
public Result ChangeMultiProductsPromotion(string userId, string productId, string selectedMultiProductsPromotionId) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(Result.Fail("当前购物车中并没有商品")); } var cartItem = cart.GetCartItem(productId); if (cartItem == null) { return(Result.Fail("该购物项已不存在")); } cartItem.ChangeMultiProductsPromotion(selectedMultiProductsPromotionId); DomainRegistry.CartRepository().Save(cart); return(Result.Success()); }
public CouponDTO GetCoupon(string id) { var couponNo = DomainRegistry.CouponNoRepository().GetByIdentity(id); if (couponNo == null) { return(null); } var coupon = DomainRegistry.CouponRepository().GetByIdentity(couponNo.CouponId); return(new CouponDTO { CanUse = couponNo.IsUsed, ExpiryDate = coupon.ExpiryDate, ID = coupon.ID, Name = coupon.Name, Value = coupon.Value }); }
public List <CouponDTO> GetAllCoupons(string userId) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(null); } var coupons = DomainRegistry.SellingPriceService().CalculateAllCoupons(cart); return(coupons.Select(ent => new CouponDTO { CanUse = ent.CanUse, ExpiryDate = ent.ExpiryDate, ID = ent.ID, Name = ent.Name, Value = ent.Value }).ToList()); }
public static RelationDetails NewValid(string relation = "relation ", Action <RelationDetails> mutator = null) { var value = new RelationDetails { Title = "relation title", FullName = "relation name", DateOfBirth = DomainRegistry.NowUtc().Date.AddYears(-45), NationalInsuranceNumber = "BC123456D", RelationshipToApplicant = "Parent", InheritAddress = false, Address = AddressBuilder.NewValid(relation), }; if (mutator != null) { mutator(value); } return(value); }
public Result AddToFavorites(string userId, string productId) { var cart = _confirmUserCartExistedDomainService.GetUserCart(userId); if (cart.IsEmpty()) { return(Result.Fail("当前购物车中并没有商品")); } var cartItem = cart.GetCartItem(productId); if (cartItem == null) { return(Result.Fail("该购物项已不存在")); } var favorites = DomainRegistry.FavoritesRepository().GetByUserId(userId) ?? new Favorites(userId, null); favorites.AddFavoritesItem(cartItem); DomainRegistry.FavoritesRepository().Save(favorites); return(Result.Success()); }