public void RemoveShoppingItem( ShoppingCar shoppingCart, string productId, int count) { if (shoppingCart == null) { throw new ArgumentNullException(); } var shoppingItem = shoppingCart.ItemListInCar .FirstOrDefault(x => x.ProductId.Equals(productId)); if (shoppingItem != null) { int countToAddBack = Math.Min(shoppingItem.ItemCount, count); shoppingItem.ItemCount -= count; if (shoppingItem.ItemCount <= 0) { shoppingCart.ItemListInCar.Remove(shoppingItem); } try { int result = _productService.AddProduct(productId, countToAddBack); } catch (ArgumentException e) { throw (e); } } }
public ActionResult AddCar(int id, int Num) { int membersId = Convert.ToInt32(Session["LoginId"]); using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.MembersId == membersId && s.ProductId == id); if (shop != null) { //return Content("<script>alert('您已加入购物车');window.location.href='/Home/Detailed?id=" + id + "'</script>"); return(Json(-1, JsonRequestBehavior.AllowGet)); } else { Product pro = fs.Product.FirstOrDefault(p => p.ProductId == id); ShoppingCar shopcar = new ShoppingCar(); shopcar.MembersId = membersId; shopcar.NowPrice = pro.NowPrice; shopcar.Num = Num; shopcar.Price = pro.NowPrice * Num; shopcar.ProductId = id; fs.ShoppingCar.Add(shopcar); fs.SaveChanges(); return(Json("添加成功", JsonRequestBehavior.AllowGet)); } } }
/// <summary> /// 加入购物车 /// </summary> /// <param name="goodid"></param> /// <param name="userid"></param> /// <param name="specificationarr"></param> /// <returns></returns> public List <ShoppingCarOutput> IntoShoppingCar(string goodid, string userid, string specificationIdArr, decimal price) { var data = EF.ShoppingCars.Where(a => a.GoodId == goodid && a.UserId == userid).ToList(); if (data.Count != 0) { data.FirstOrDefault().Amount += 1; } else { var mod = new ShoppingCar { Amount = 1, Price = price, CreateTime = DateTime.Now, GoodId = goodid, IsDelect = true, UserId = userid, SpecificationName = GetSpecificationName(specificationIdArr), }; EF.ShoppingCars.Add(mod); } if (EF.SaveChanges() > 0) { return(GetShoppingCarList(userid)); //return null; } return(null); }
public int UpdateShoppingCar(ShoppingCar car) { using (IDbConnection conn = new SqlConnection(sqlconnstr)) { conn.Open(); return(conn.Execute("update shoppingcar set scount =scount + @scount where gid = @GID and UID = @UID and Spay =0", new { scount = car.SCount, GID = car.GID, UID = car.UID })); } }
public ActionResult GetInventory(int id) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.CarId == id); Product pro = fs.Product.FirstOrDefault(p => p.ProductId == shop.ProductId); return(Json(pro.Inventory, JsonRequestBehavior.AllowGet)); } }
public List <ShoppingItem> CheckShoppingCart(ShoppingCar shoppingCart) { foreach (var item in shoppingCart.ItemListInCar) { Console.WriteLine(item); } return(shoppingCart.ItemListInCar); }
public static Purchase ConvertToPurchase(this ShoppingCar shopping) { Purchase purchase = new Purchase(); purchase.Date = DateTime.Now; purchase.Total = shopping.Total; purchase.Purchases = shopping.ListPurchase; return(purchase); }
public int AddShoppingCar(ShoppingCar car) { car.SID = RandomID.GetRandomID("S"); using (IDbConnection conn = new SqlConnection(sqlconnstr)) { conn.Open(); return(conn.Execute("insert shoppingcar(GID,UID,SID,SCount,SPay) values(@GID,@UID,@SID,@SCount,@SPay)", new { GID = car.GID, UID = car.UID, SID = car.SID, SCount = car.SCount, SPay = car.SPay })); } }
public ActionResult DeleteShopCar(int id) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar car = fs.ShoppingCar.FirstOrDefault(c => c.CarId == id); fs.ShoppingCar.Remove(car); fs.SaveChanges(); return(Json("删除成功", JsonRequestBehavior.AllowGet)); } }
public FormPurchase() { InitializeComponent(); PresenterProviders = new PresenterGetProviders(new MYSQLProviderRepository(), this); PresenterProviders.PresenterProviders(); addPurchase = new PresenterAddPurchase(new MYSQLPurchaseRepository(), this); shoppingcar = new ShoppingCar(); carItem = new CarItemPurchase(); }
public int AddShoppingCar(ShoppingCar car) { if (_dao.IsContain(car)) { return(_dao.UpdateShoppingCar(car)); } else { return(_dao.AddShoppingCar(car)); } }
public void Test_GetREsult2(int diffentCount, int sameCount, double expected) { //Araange var actual = 0d; ShoppingCar myCar = new ShoppingCar(); //Act actual = myCar.GetResult(diffentCount, sameCount); //Arrert Assert.Equal(expected, actual); }
public ActionResult EditShopCar(int afternum, int id) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar car = fs.ShoppingCar.FirstOrDefault(c => c.CarId == id); Product pro = fs.Product.FirstOrDefault(p => p.ProductId == car.ProductId); car.Num = afternum; car.Price = afternum * pro.NowPrice; decimal price = afternum * pro.NowPrice; fs.SaveChanges(); return(Json(price, JsonRequestBehavior.AllowGet)); } }
public void Test_GetResultl(int count, double expected) { //Araange var actual = 0d; ShoppingCar myCar = new ShoppingCar(); //Act actual = myCar.GetResult(count); //Arrert Assert.Equal(expected, actual); }
public void Buy_Nothing_Price_Should_Match() { var target = new ShoppingCar(); target.Buy(new Book("HarryPotter1", 0)); target.Buy(new Book("HarryPotter2", 0)); target.Buy(new Book("HarryPotter3", 0)); target.Buy(new Book("HarryPotter4", 0)); target.Buy(new Book("HarryPotter5", 0)); var expected = 0; Assert.AreEqual(expected, target.GetPrice()); }
public void Buy_One_HarryPotter1_One_HarryPotter2_One_HarryPotter3_One_HarryPotter4_One_HarryPotter5_Price_Should_Match() { var target = new ShoppingCar(); target.Buy(new Book("HarryPotter1", 1)); target.Buy(new Book("HarryPotter2", 1)); target.Buy(new Book("HarryPotter3", 1)); target.Buy(new Book("HarryPotter4", 1)); target.Buy(new Book("HarryPotter5", 1)); var expected = 375m; Assert.AreEqual(expected, target.GetPrice()); }
public static List <ShoppingCar> ShoppingCar() { List <ShoppingCar> shoppingCar = new List <ShoppingCar>(); var shoppingCar1 = new ShoppingCar() { Id = 1, IdUser = 1, IdBook = 1, Count = 2, Price = 19.98 }; var shoppingCar2 = new ShoppingCar() { Id = 2, IdUser = 1, IdBook = 3, Count = 1, Price = 29.99 }; var shoppingCar3 = new ShoppingCar() { Id = 3, IdUser = 2, IdBook = 4, Count = 2, Price = 39.98 }; var shoppingCar4 = new ShoppingCar() { Id = 4, IdUser = 3, IdBook = 2, Count = 1, Price = 49.99 }; shoppingCar.Add(shoppingCar1); shoppingCar.Add(shoppingCar2); shoppingCar.Add(shoppingCar3); shoppingCar.Add(shoppingCar4); return(shoppingCar); }
/// <summary> /// 结算页展示 /// </summary> /// <param name="userid"></param> /// <param name="carlist"></param> /// <returns></returns> public SettlementOutput GetSettlementsList(string userid, string orderid) { var data = EF.Good_Orders.Where(a => a.OrderId == orderid).ToList(); var goodlist = new List <GoodListOutput>(); var cartlist = new List <ShoppingCar>(); if (data.Count == 0) { return(null); } foreach (var item in data) { var goodmod = new GoodListOutput() { UserId = userid, Amount = item.Quantity, GoodId = item.GoodId, GoodName = EF.Goods.FirstOrDefault(a => a.GoodId == item.GoodId).GoodName, Price = item.Price, ThumbnailImg = "https://localhost:44363/file/image/200/" + EF.Goods.FirstOrDefault(a => a.GoodId == item.GoodId).ThumbnailImg, SpecificationName = item.SpecificationName, }; goodlist.Add(goodmod); var cartmod = new ShoppingCar() { Amount = item.Quantity, CreateTime = item.CreateTime, GoodId = item.GoodId, IsDelect = item.IsDelect, Price = item.Price, UserId = userid, SpecificationName = item.SpecificationName, }; cartlist.Add(cartmod); } var list = new SettlementOutput() { GetGoodLists = goodlist, GetGoodCoupons = GetCouponList(userid, cartlist), }; return(list); }
public bool IsContain(ShoppingCar car) { string sql = string.Format("select count(*) from shoppingcar where gid = '{0}' and uid = '{1}' and spay = 0", car.GID, car.UID); using (SqlConnection conn = new SqlConnection(sqlconnstr)) { using (SqlCommand cmd = new SqlCommand(sql, conn)) { conn.Open(); int k = (int)cmd.ExecuteScalar(); if (k >= 1) { return(true); } else { return(false); } } } }
public Receipt Checkout(ShoppingCar shoppingCart) { var result = new Receipt(); foreach (var item in shoppingCart.ItemListInCar) { result.ReceiptItems.Add(new ReceiptItem { ReceiptItemId = item.ProductId, ReceiptItemName = item.ProductName, ReceiptPriceOne = item.ItemPrice, ReceiptCount = item.ItemCount, ReceiptItemsPrice = item.ItemSumPrice }); } result.TotalItems = result.ReceiptItems.Count; result.TotalPrice = result.ReceiptItems.Sum(x => x.ReceiptItemsPrice); result.ReceiptId = DateTime.Now.ToString("yyyyMMddHHmmss"); return(result); }
public ActionResult ChangeId(string list) { string array = ""; using (FlowersSIMEntities fs = new FlowersSIMEntities()) { if (list.Length == 1) { int id = Convert.ToInt32(list); ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.CarId == id); return(Json(shop.ProductId, JsonRequestBehavior.AllowGet)); } else { string[] idlist = list.Split(','); for (int i = 0; i < idlist.Length; i++) { int id = Convert.ToInt32(idlist[i]); ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.CarId == id); if (i == (idlist.Count() - 1)) { array = "" + array + "," + shop.ProductId + ""; } if (idlist.Count() == 1) { array = "" + shop.ProductId + ""; } if (i == 0) { array = "" + shop.ProductId + ""; } if (i != (idlist.Count() - 1) && i != 0) { array = "" + array + "," + shop.ProductId + ""; } } return(Json(array, JsonRequestBehavior.AllowGet)); } } }
public ActionResult Money(string array) { if (array == "") { return(Json(0, JsonRequestBehavior.AllowGet)); } else { int money = 0; string[] arr = array.Split(','); for (int i = 0; i < arr.Length; i++) { int carid = Convert.ToInt32(arr[i]); using (FlowersSIMEntities fs = new FlowersSIMEntities()) { ShoppingCar shop = fs.ShoppingCar.FirstOrDefault(s => s.CarId == carid); money += Convert.ToInt32(shop.NowPrice * shop.Num); } } return(Json(money, JsonRequestBehavior.AllowGet)); } }
public void AddShoppingItem( ShoppingCar shoppingCart, string productId, int count) { if (shoppingCart == null) { throw new ArgumentNullException(); } var product = _productRepositorie.GetProductById(productId); if (product.ProductCount < count) { throw new InvalidOperationException($"Product {product.ProductId} count is not enough."); } var shoppingItem = shoppingCart.ItemListInCar .FirstOrDefault(x => x.ProductId.Equals(productId)); if (shoppingItem == null) { shoppingItem = new ShoppingItem { ProductId = productId, ProductName = product.ProductName, ItemPrice = product.ProductPrice, ItemCount = count }; shoppingCart.ItemListInCar.Add(shoppingItem); } else { shoppingItem.ItemCount += count; } _productRepositorie.RemoveProduct(productId, count); }
public ActionResult BatchDelete(string idArray, string tableName) { //判断是否有选中数据 if (idArray == "" || tableName == "") { return(Content("<script>alert('您还没选中,请先选中至少一项数据再进行操作!');window.location.href = '/Manage/" + tableName + "Manage'</script>")); } //将传进来的所选数据的编号数组进行分割 string[] deleteValue = idArray.Split(','); int[] deleteId = Array.ConvertAll(deleteValue, int.Parse); for (int i = 0; i < deleteId.Length; i++) { using (FlowersSIMEntities fs = new FlowersSIMEntities()) { int id = deleteId[i]; //删除该表名内的数据及其与其他表相关联的数据 if (tableName == "Members") { ShoppingCar entity = fs.ShoppingCar.FirstOrDefault(p => p.MembersId == id); if (entity != null) { fs.ShoppingCar.Remove(entity); fs.SaveChanges(); } Orders entity1 = fs.Orders.FirstOrDefault(p => p.MembersId == id); if (entity1 != null) { fs.Orders.Remove(entity1); fs.SaveChanges(); } Members entity2 = fs.Members.FirstOrDefault(p => p.MembersId == id); if (entity2 != null) { fs.Members.Remove(entity2); fs.SaveChanges(); } } if (tableName == "Product") { Product entity = fs.Product.FirstOrDefault(p => p.ProductId == id); if (entity != null) { fs.Product.Remove(entity); fs.SaveChanges(); } } if (tableName == "Orders") { Orders entity = fs.Orders.FirstOrDefault(p => p.OrdersId == id); if (entity != null) { fs.Orders.Remove(entity); fs.SaveChanges(); } } if (i == deleteId.Length - 1) { return(Content("<script>alert('删除成功!,已删除" + deleteId.Length + "项数据');window.location.href = '/Manage/" + tableName + "Manage'</script>")); } } } return(View()); }
public IActionResult AddToCart(int aid, string uid, int amountToBuy) { if (amountToBuy <= 0) { return(RedirectToAction("Index", "Add")); } uid = GetUser(uid).Id; var add = context.Adds.Include(a => a.Article).Include(a => a.User).Single(a => a.ArticleId == aid && a.UserId == uid); var mySl = (from sc in context.ShoppingCars join l in context.ShoppingLists on sc.ShoppingListId equals l.ShoppingListId where sc.UserId == GetUser(User.Identity.Name).Id&& l.IsMainList == true select new { l.ShoppingListId }).ToList(); var sl2 = new ShoppingList(); if (mySl.Count() == 0) { ShoppingList sl1 = new ShoppingList { IsMainList = true, IsSaved = false }; context.ShoppingLists.Add(sl1); context.SaveChanges(); sl2 = context.ShoppingLists.SingleOrDefault(l => context.ShoppingCars.Any(c => c.ShoppingListId == l.ShoppingListId) == false); } else { sl2 = context.ShoppingLists.Find(mySl.First().ShoppingListId); } if (context.ShoppingCars.SingleOrDefault(c => (c.UserId == GetUser(User.Identity.Name).Id&& c.ShoppingListId == sl2.ShoppingListId)) == null) { ShoppingCar sc = new ShoppingCar { UserId = User.Identity.Name, User = GetUser(User.Identity.Name), ShoppingListId = sl2.ShoppingListId, ShoppingList = sl2 }; context.ShoppingCars.Add(sc); context.SaveChanges(); } ShoppingList_Article sla = new ShoppingList_Article { ShoppingListId = sl2.ShoppingListId, ShoppingList = sl2, ArticleId = add.ArticleId, Article = add.Article, Amount = amountToBuy }; context.ShoppingList_Articles.Add(sla); context.SaveChanges(); return(RedirectToAction("Index", "Add")); }
public static List <ShoppingCar> ShoppingCars() { var shoppingcar1 = new ShoppingCar() { CodeProduct = 2, Count = 2, Obs = string.Empty }; var shoppingcar2 = new ShoppingCar() { CodeProduct = 3, Count = 11, Obs = string.Empty }; var shoppingcar3 = new ShoppingCar() { CodeProduct = 1, Count = 3, Obs = string.Empty }; var shoppingcar4 = new ShoppingCar() { CodeProduct = 2, Count = 67, Obs = string.Empty }; var shoppingcar5 = new ShoppingCar() { CodeProduct = 9, Count = 2, Obs = string.Empty }; var shoppingcar6 = new ShoppingCar() { CodeProduct = 3, Count = 8, Obs = string.Empty }; var shoppingcar7 = new ShoppingCar() { CodeProduct = 4, Count = 1, Obs = string.Empty }; var shoppingcar8 = new ShoppingCar() { CodeProduct = 4, Count = 4, Obs = string.Empty }; var shoppingcar9 = new ShoppingCar() { CodeProduct = 5, Count = 15, Obs = string.Empty }; return(new List <ShoppingCar>() { shoppingcar1, shoppingcar2, shoppingcar3, shoppingcar4, shoppingcar5, shoppingcar6, shoppingcar7, shoppingcar8, shoppingcar9 }); }
public ActionResult Add(Orders entity) { string name = Session["LoginUser"] as string; string productidlist = Request.Form["ProductIdList"]; string[] sproductid = productidlist.Split(','); int carorproduct = Convert.ToInt32(Request.Form["carOrproduct"]); //获取来源 int price = 0; string num = ""; #region 将carid转为productid string array = ""; #endregion #region 计算数量加入购物车 using (FlowersSIMEntities dc = new FlowersSIMEntities()) { Orders order = new Orders(); if (carorproduct == 0) { if (productidlist.Length == 1) { int id = Convert.ToInt32(productidlist); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); array = Convert.ToString(shop.ProductId); } else { string[] idlist = productidlist.Split(','); for (int i = 0; i < idlist.Length; i++) { int id = Convert.ToInt32(idlist[i]); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); if (i == (idlist.Count() - 1)) { array = "" + array + "," + shop.ProductId + ""; } if (idlist.Count() == 1) { array = "" + shop.ProductId + ""; } if (i == 0) { array = "" + shop.ProductId + ""; } if (i != (idlist.Count() - 1) && i != 0) { array = "" + array + "," + shop.ProductId + ""; } } } for (int i = 0; i < sproductid.Count(); i++) { int id = Convert.ToInt32(sproductid[i]); ShoppingCar shop = dc.ShoppingCar.FirstOrDefault(s => s.CarId == id); price += Convert.ToInt32(shop.NowPrice * shop.Num); if (i == (sproductid.Count() - 1)) { //num += "" + shop.Num + ""; num = "" + num + "," + shop.Num + ""; } if (sproductid.Count() == 1) { //num = "" + shop.Num + ""; num = "" + shop.Num + ""; } if (i == 0) { num = "" + shop.Num + ""; } if (i != (sproductid.Count() - 1) && i != 0) { //num += "" + shop + ","; num = "" + num + "," + shop.Num + ""; } } order.OrderNumbers = num; order.Price = price; order.ProductIdList = array; } else { int productid = (Convert.ToInt32(productidlist)); Product pro = dc.Product.FirstOrDefault(p => p.ProductId == productid); string Number = Request.Form["Number"]; order.OrderNumbers = Number; order.Price = pro.NowPrice * Convert.ToInt32(Number); order.ProductIdList = productidlist; } Members ber = dc.Members.FirstOrDefault(b => b.MembersName == name); order.MembersId = ber.MembersId; order.OrdersName = entity.OrdersName; order.OrdersPhone = entity.OrdersPhone; order.ConsigneeAddress = entity.ConsigneeAddress; order.ConsigneeName = entity.ConsigneeName; order.ConsigneePhone = entity.ConsigneePhone; order.Status = 0; order.DeliveryTime = DateTime.Now.Date; order.CreateTime = DateTime.Now.Date; //添加实体 dc.Orders.Add(order); //保存更新 dc.SaveChanges(); } #endregion return(Content("<script>alert('添加订单成功!');window.location.href='/MemberOrders/OrderIndex'</script>")); }
public void InitShoppingCarInstance() { shoppingCar = new ShoppingCar();//init with every test method }
public async void LoadShoppingCar() { //Triger que se ejecuta para actualizar la view model, cada vez que se muestra la ventana ShoppingCar.LoadProducts(); }
public void Post([FromBody] ShoppingCar shoppingCar) { }