public static ShoppingCart ToCoreModel(this ShoppingCartEntity entity) { if (entity == null) { throw new ArgumentNullException("entity"); } var retVal = new ShoppingCart(); retVal.InjectFrom(entity); retVal.Currency = (CurrencyCodes)Enum.Parse(typeof(CurrencyCodes), entity.Currency); if (entity.Items != null) { retVal.Items = entity.Items.Select(x => x.ToCoreModel()).ToList(); } if (entity.Addresses != null) { retVal.Addresses = entity.Addresses.Select(x => x.ToCoreModel()).ToList(); } if (entity.Shipments != null) { retVal.Shipments = entity.Shipments.Select(x => x.ToCoreModel()).ToList(); } if (entity.Payments != null) { retVal.Payments = entity.Payments.Select(x => x.ToCoreModel()).ToList(); } retVal.TaxDetails = entity.TaxDetails.Select(x => x.ToCoreModel()).ToList(); return(retVal); }
public static ShipmentItemEntity ToDataModel(this ShipmentItem shipmentItem, ShoppingCartEntity cartEntity, PrimaryKeyResolvingMap pkMap) { if (shipmentItem == null) { throw new ArgumentNullException("shipmentItem"); } var retVal = new ShipmentItemEntity(); pkMap.AddPair(shipmentItem, retVal); retVal.InjectFrom(shipmentItem); //Try to find cart line item by shipment item if (!String.IsNullOrEmpty(shipmentItem.LineItemId)) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItemId); } if (retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.Id == shipmentItem.LineItem.Id); } if (retVal.LineItem == null && shipmentItem.LineItem != null) { retVal.LineItem = cartEntity.Items.FirstOrDefault(x => x.ProductId == shipmentItem.LineItem.ProductId); } if (retVal.LineItem != null && !String.IsNullOrEmpty(retVal.LineItem.Id)) { retVal.LineItemId = retVal.LineItem.Id; retVal.LineItem = null; } return(retVal); }
/// <summary> /// 列表获取 /// </summary> public IList <ShoppingCartEntity> GetList(ShoppingCartEntity entity, int Page, int PageSize) { var lNewsBLL = new LNewsBLL(CurrentUserInfo); var objectImagesBLL = new ObjectImagesBLL(CurrentUserInfo); var itemService = new ItemService(CurrentUserInfo); if (PageSize <= 0) { PageSize = 15; } IList <ShoppingCartEntity> eventsList = new List <ShoppingCartEntity>(); DataSet ds = new DataSet(); ds = _currentDAO.GetList(entity, Page, PageSize); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { eventsList = DataTableToObject.ConvertToList <ShoppingCartEntity>(ds.Tables[0]); if (eventsList != null) { foreach (var item in eventsList) { item.ItemDetail = itemService.GetVwItemDetailById(item.ItemId, entity.VipId); } } } return(eventsList); }
private string GetList(HttpContext context) { Pagination pagination = new Pagination(); pagination.PageIndex = Convert.ToInt32(HttpContext.Current.Request["pageindex"].ToInt(1)); pagination.PageSize = Convert.ToInt32(HttpContext.Current.Request["pagesize"].ToInt(3)); pagination.IsPaging = (bool)context.Request["ispaging"].To <bool>(false); ShoppingCartEntity entity = new ShoppingCartEntity(); entity.UserId = 1; entity.Deleted = false; ShoppingCartService service = new ShoppingCartService(); List <ShoppingCartEntity> list = service.GetList(entity, pagination); //创建匿名类,包含分页及查询的数据,以及是否查询成功 var resultObj = new { page = pagination, data = list, code = 10000 }; //将对象序列化成为JSON格式 return(Newtonsoft.Json.JsonConvert.SerializeObject(resultObj)); }
public async Task ScanItemTest() { var initialShoppingCart = new ShoppingCartEntity { LineItems = new List <LineItemEntity>() }; var item = new Item { ProductCode = "Item1", Price = 1.33333 }; var saveCartValidation = new Func <ShoppingCartEntity, bool>((cart) => { return(cart.Total.Equals(1.34) && cart.SubTotal.Equals(1.34) && cart.LineItems[0].ProductCode.Equals(item.ProductCode)); }); var applyDiscountValidation = new Func <ShoppingCart, bool>((cart) => { return(cart.LineItems[0].ProductCode.Equals(item.ProductCode)); }); var checkoutRepositoryMock = new Mock <ICheckoutRepository>(MockBehavior.Strict); checkoutRepositoryMock.Setup(c => c.GetShoppingCart()).ReturnsAsync(initialShoppingCart); checkoutRepositoryMock.Setup(c => c.SaveShoppingCart(It.Is <ShoppingCartEntity>(cart => saveCartValidation(cart)))) .ReturnsAsync(It.IsAny <ShoppingCartEntity>()); var engineMock = new Mock <IDiscountEngine>(MockBehavior.Strict); engineMock.Setup(e => e.Apply(It.Is <ShoppingCart>(c => applyDiscountValidation(c)))).Returns(Task.CompletedTask); var service = GetService(checkoutRepositoryMock, engineMock); await service.Scan(item); }
private string Insert(HttpContext context) { List <EmployeeEntity> entities = (List <EmployeeEntity>)context.Session["authinfo"]; ShoppingCartEntity entity = new ShoppingCartEntity(); //entity.UserId = entities[0].Id; entity.UserId = 1; entity.ProductId = context.Request["productid"].To <int>(); entity.Count = context.Request["count"].To <int>(); entity.Deleted = false; ShoppingCartService service = new ShoppingCartService(); int success = 10001; if (service.Create(entity)) { success = 10000; } var resultObj = new { Code = success }; //将对象序列化成为JSON格式 return(Newtonsoft.Json.JsonConvert.SerializeObject(resultObj)); }
private ShoppingCartDTO ToDTO(ShoppingCartEntity shoppingCartEntity) { ShoppingCartDTO shoppingCartDTO = new ShoppingCartDTO() { CardTypeId = shoppingCartEntity.CardTypeId, Id = shoppingCartEntity.Id, CardTypeName = shoppingCartEntity.CardType.CardTypeName, Num = shoppingCartEntity.Num, UserId = shoppingCartEntity.UserId, UserName = shoppingCartEntity.User.UserName }; return(shoppingCartDTO); }
public long InsertShoppingCart(ShoppingCartDTO t_ShoppingCart) { using (B2CDbContext ctx = new B2CDbContext()) { ShoppingCartEntity ShoppingCartEntity = new ShoppingCartEntity() { CardTypeId = t_ShoppingCart.CardTypeId, Num = t_ShoppingCart.Num, UserId = t_ShoppingCart.UserId }; ctx.ShoppingCarts.Add(ShoppingCartEntity); ctx.SaveChanges(); return(ShoppingCartEntity.Id); } }
public async Task SaveChangesAsync_CreateCart() { //Arrange var cartId = Guid.NewGuid().ToString(); var entity = new ShoppingCartEntity { Id = cartId }; var carts = new List <ShoppingCart> { entity.ToModel(AbstractTypeFactory <ShoppingCart> .TryCreateInstance()) }; var service = GetShoppingCartService(); //Act await service.SaveChangesAsync(carts.ToArray()); //Assert }
public async Task GetTotalTest() { var total = 1.23; var initialShoppingCart = new ShoppingCartEntity { Total = total }; var checkoutRepositoryMock = new Mock <ICheckoutRepository>(MockBehavior.Strict); checkoutRepositoryMock.Setup(c => c.GetShoppingCart()).ReturnsAsync(initialShoppingCart); var engineMock = new Mock <IDiscountEngine>(MockBehavior.Strict); var service = GetService(checkoutRepositoryMock, engineMock); Assert.Equal(total, await service.Total()); }
private string Update(HttpContext context) { ShoppingCartEntity entity = new ShoppingCartEntity(); entity.Id = context.Request["id"].To <int>(); entity.UserId = 1; entity.Count = context.Request["count"].To <int>(); ShoppingCartService service = new ShoppingCartService(); int success = 10001; if (service.Update(entity)) { success = 10000; } var resultObj = new { code = success }; //将对象序列化成为JSON格式 return(Newtonsoft.Json.JsonConvert.SerializeObject(resultObj)); }
public void CouponsPatch() { var originalEntity = new ShoppingCartEntity { Coupons = new ObservableCollection <CouponEntity> { new CouponEntity { Code = "12345", Id = "aa" }, new CouponEntity { Code = "abcde", Id = "ab" }, new CouponEntity { Code = "AA-BB-CC", Id = "ac" }, new CouponEntity { Code = "00-11-22", Id = "ad" }, new CouponEntity { Code = "ABCDE", Id = "ae" }, } }; var modifiedEntity = new ShoppingCartEntity { Coupons = new ObservableCollection <CouponEntity> { new CouponEntity { Code = "abcde", Id = "ba" }, new CouponEntity { Code = "AA-BB-CC", Id = "bb" }, new CouponEntity { Code = "00-11-22", Id = "bc" }, new CouponEntity { Code = "ABCDE", Id = "bd" }, new CouponEntity { Code = "FGHIJ", Id = "be" }, new CouponEntity { Code = "KLMNO", Id = "bf" }, } }; modifiedEntity.Patch(originalEntity); Assert.Equal(6, originalEntity.Coupons.Count); Assert.Equal("abcde", originalEntity.Coupons[0].Code); Assert.Equal("ab", originalEntity.Coupons[0].Id); Assert.Equal("AA-BB-CC", originalEntity.Coupons[1].Code); Assert.Equal("ac", originalEntity.Coupons[1].Id); Assert.Equal("00-11-22", originalEntity.Coupons[2].Code); Assert.Equal("ad", originalEntity.Coupons[2].Id); Assert.Equal("ABCDE", originalEntity.Coupons[3].Code); Assert.Equal("ae", originalEntity.Coupons[3].Id); Assert.Equal("FGHIJ", originalEntity.Coupons[4].Code); Assert.Equal("be", originalEntity.Coupons[4].Id); Assert.Equal("KLMNO", originalEntity.Coupons[5].Code); Assert.Equal("bf", originalEntity.Coupons[5].Id); }
/// <summary> /// 列表数量获取 /// </summary> public int GetListQty(ShoppingCartEntity entity) { return(_currentDAO.GetListQty(entity)); }
/// <summary> /// 列表数量获取 /// </summary> public decimal GetListAmount(ShoppingCartEntity entity) { return(_currentDAO.GetListAmount(entity)); }
/// <summary> /// 将商品加入购物车 /// </summary> /// <param name="channelId">渠道ID</param> /// <param name="token">登录用户令牌</param> /// <param name="guid">未登录用户临时ID</param> /// <param name="user_id">登录用户ID</param> /// <param name="uid">登录用户,登录账户Email</param> /// <param name="area_id">区域ID</param> /// <param name="pid">商品ID</param> /// <param name="qty">商品数量</param> /// <returns></returns> public static MResult InsertShoppingCart(int channelId, string token, string guid, string user_id, string uid, string area_id, string pid, string qty) { #region 0会员等级 //创建返回实体 var result = new MResult(); var userLevel = 0; try { if (!string.IsNullOrEmpty(uid) && !uid.Equals("null", StringComparison.CurrentCultureIgnoreCase)) { var member = Factory.DALFactory.Member(); var memberInfo = member.GetMemberInfo(uid); userLevel = MCvHelper.To(memberInfo.clusterId, 0); } if (userLevel < 1) { userLevel = 1; } } catch (Exception ex) { result.status = Core.Enums.MResultStatus.ExceptionError; result.msg = "查询用户数据错误!"; return(result); } #endregion #region 1、参数处理 result.status = Core.Enums.MResultStatus.Success; //定义参数 //int channelId = -1; int userId = -1; int productId = -1; int quantity = -1; //参数转换 //int.TryParse(sid, out channelId); int.TryParse(pid.Trim(), out productId); int.TryParse(user_id, out userId); int.TryParse(qty, out quantity); #endregion #region 2、相关检测处理 //商品数量检测 if (quantity <= 0) { result.status = Core.Enums.MResultStatus.ParamsError; result.msg = "传入的商品数量参数有误!"; } //商品ID转换 if (productId <= 0) { result.status = Core.Enums.MResultStatus.ParamsError; result.msg = "传入的商品ID参数有误!"; } //如果参数错误中断程序执行 if (result.status == Core.Enums.MResultStatus.ParamsError) { return(result); } #endregion #region 3、获取购物车中商品信息 //获取购物车中信息 var shoppingCartList = GetShoppingCartProductInfosByUserIDGuidChannelID(userId, guid, channelId); if (shoppingCartList != null && shoppingCartList.info.shoppingcart_list.Count > 0) { //获取当前商品的购物车中存在的商品信息 var shoppingCartProductInfo = shoppingCartList.info.shoppingcart_list.Find(p => p.intProductID == productId); //检测购物车中是否存在当前商品 if (shoppingCartProductInfo != null) { //获取当前用户购物车中当前商品的数量 int productCount = (int)shoppingCartProductInfo.intBuyCount; //检查是否是删除商品,合并数量或删除购物车中的删除商品 if (shoppingCartProductInfo.intIsDelete == 1) { DeleteShoppingCartByProductIdUserID(shoppingCartProductInfo.intShopCartID); } else { //如果不是删除状态,则将当前要购买的数量与购物车中的数量累加 quantity += productCount; var shoppingCart = Factory.DALFactory.ShoppingCartDal(); if (shoppingCart.SetShoppingCartGoodsNum(userId, guid, shoppingCartProductInfo.intShopCartID, quantity)) { result.status = Core.Enums.MResultStatus.Success; result.msg = "添加购物车成功"; return(result); } else { result.status = Core.Enums.MResultStatus.ExecutionError; result.msg = "购物车更新商品数量失败!"; return(result); } } } } #endregion #region 4、商品信息处理 //检测商品实时库存 if (!Wcf.BLL.Goods.GoodsBLL.CheckProductStockByProductID(productId, quantity)) { result.status = Core.Enums.MResultStatus.ExecutionError; result.msg = "商品库存不足!"; return(result); } //获取商品信息 var goodsDal = DALFactory.Goods(); var pdt = goodsDal.GetGoodsInfo(userLevel, channelId, productId); //检查商品信息 if (pdt == null) { result.status = Core.Enums.MResultStatus.ExecutionError; result.msg = "商品信息有误!"; return(result); } #endregion #region 5、处理商品加入购物车 //给实体赋值 ShoppingCartEntity spc = new ShoppingCartEntity(); //购物车保护 if (pdt.intProductID <= 0 || pdt.numVipPrice <= 0) { if (pdt.intAttribute != 5) { result.msg = "商品加入购物车失败!"; result.status = Core.Enums.MResultStatus.ExecutionError; return(result); } } spc.vchGuid = spc.intUserID > 0 ? "" : guid; spc.intProductID = productId; spc.nchProductName = pdt.vchProductName; spc.intBuyCount = quantity; spc.intUserID = userId; spc.intBrandID = pdt.intBrandID; spc.intCateId = pdt.intWebChildType; spc.intChannelID = channelId; spc.chrIsGift = 0; spc.numOrgPrice = (decimal)pdt.numVipPrice; spc.intScore = (int)pdt.intScore; spc.numSalePrice = (decimal)pdt.numVipPrice; spc.intOrgScore = (int)pdt.intScore; spc.vchPicURL = pdt.vchMainPicURL; spc.intWeight = pdt.intWeight; spc.vchProductPrinted = pdt.vchProductPrinted; spc.dtAddTime = System.DateTime.Now; spc.numCost = (decimal)pdt.numCost; spc.numCleanCost = (decimal)pdt.numCleanCost; spc.intPromID = 0; spc.intSuitID = -1; spc.nchSuitName = ""; spc.intPromCount = 1; spc.intGiftType = 0; spc.intAreaID = Convert.ToInt32(area_id); spc.vchproductcode = pdt.vchproductcode; spc.numMarketPrice = pdt.numMarketPrice; //加入购物车 try { var retValue = AddShoppingCartProductInfo(spc); if (retValue) { result.status = Core.Enums.MResultStatus.Success; result.msg = "添加购物车成功"; } else { result.status = Core.Enums.MResultStatus.ExecutionError; result.msg = "添加购物车失败!"; } } catch (Exception ex) { result.status = Core.Enums.MResultStatus.ExceptionError; result.msg = "购物车出错了!"; } #endregion return(result); }