public void TestBasket() { var customer = new CustomerAction(8); var store = new StoreAction(); customer.ClearBasket(); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement()); Assert.IsTrue(customer.GetBasket().Count() == 2); customer.DelBasket(customer.GetBasket().First().id); Assert.IsTrue(customer.GetBasket().Count() == 1); }
public void TestConfirmPayForAll(long userId) { var customer = new CustomerAction(userId); var store = new StoreAction(); customer.ClearBasket(); Assert.AreEqual(customer.GetBasket().Count(), 0); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement()); var fastPayModel = GenerateBasketElement(true); var fastPayId = customer.AddBasket(fastPayModel).packId; var packId = customer.AddBasket(GenerateBasketElement()).packId; var price = store.GetAllGoods().First(s => s.id == fastPayModel.goodId).price; var total = price * fastPayModel.count; var payModel = new PayModel { packId = fastPayId, countInBasket = 1, payDate = DateTime.Now, transactionNumber = Guid.NewGuid().ToString(), totalSumm = total }; customer.Pay(payModel); Assert.AreEqual(customer.GetOrders().Where(s => s.packId == fastPayId).Count(), 1); customer.AddBasket(GenerateBasketElement(true)); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement(true)); Assert.AreEqual(customer.GetBasket().Count(), 4); Assert.IsTrue(customer.GetOrders().Count() > 0); var basket = customer.GetBasket(); var payModel2 = new PayModel { packId = (long)basket.Select(s => s.packId).Distinct().Single(), countInBasket = 4, payDate = DateTime.Now, transactionNumber = Guid.NewGuid().ToString(), totalSumm = basket.Sum(s => s.summTotal).Value }; customer.Pay(payModel2); Assert.AreEqual(customer.GetOrders().Where(s => s.packId == packId).Count(), 4); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement(true)); Assert.IsTrue(customer.GetBasket().Count() == 1); }
public ActionResult Basket() { var customer = new CustomerAction(Session.GetUserId()); var basket = customer.GetBasket(); return(View(basket)); }
public JsonResult DeleteBasket(long basketId) { var customer = new CustomerAction(Session.GetUser().id); try { customer.DelBasket(basketId); Session.UpdateBasket(); var basketSum = customer.GetBasket()?.Sum(s => s.summTotal) ?? 0.00M; var basketCount = customer.GetBasket()?.Count() ?? 0; return(Json(new { result = 0, basketSum = basketSum, basketCount = basketCount }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { result = -1, message = "Ошибка удаления из корзины. Перезагрузите страницу" }, JsonRequestBehavior.AllowGet)); } }
public static void UpdateBasket(this HttpSessionStateBase sbase) { if (IsAuth(sbase)) { var user = GetUser(sbase); var customer = new CustomerAction(user.id); user.basket = customer.GetBasket(); } }
public static void Login(this HttpSessionStateBase sbase, long userId) { var account = new AccountAction(); var user = account.GetUserInfo(new UserIdModel { userId = userId }); var customer = new CustomerAction(userId); user.basket = customer.GetBasket(); user.wishList = customer.GetWishList(); SetUser(sbase, user); }
public void TestFastPay() { var customer = new CustomerAction(8); var store = new StoreAction(); customer.ClearBasket(); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement()); var payPackId = customer.AddBasket(GenerateBasketElement(true)); customer.AddBasket(GenerateBasketElement()); customer.AddBasket(GenerateBasketElement()); Assert.IsTrue(customer.GetBasket().Where(s => s.packId == payPackId.packId).Count() == 1); }
public JsonResult AddBasket(long goodId, int count) { var customer = new CustomerAction(Session.GetUser().id); try { var addBasketModel = new AddBasketModel { goodId = goodId, count = count, isFastPay = false }; var result = customer.AddBasket(addBasketModel); Session.UpdateBasket(); var basketSum = customer.GetBasket()?.Sum(s => s.summTotal) ?? 0.00M; var basketCount = customer.GetBasket()?.Count() ?? 0; return(Json(new { result = 0, basketSum = basketSum, basketCount = basketCount, basket = Session.GetUser().basket.Select(s => new { name = s.name, summTotal = s.summTotal, id = s.id, imageUrl = s.imageUrl }) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { result = -1, message = "Ошибка добавления в корзину" }, JsonRequestBehavior.AllowGet)); } }