public ActionResult Checkout(EditAndCheckoutViewModel viewModel, Cart cart) { // take products from cart and update quantity foreach (var item in viewModel.CartLines) { CartLineViewModel item1 = item; cart.Items.Single(x => x.Product.Id == item1.ProductId).Quantity = item.Quantity; } if (CurrentUser() == null) { return View("LoginOrRegister"); } int i = 0; foreach (CartItem cartItem in cart.Items) { cartItem.Product = daoTemplate.FindByID<Product>(cartItem.Product.Id); if (cartItem.Product.Rest() < cartItem.Quantity) ModelState.AddModelError(string.Format("CartLines[{0}].Quantity", i), "Слишком большое количество"); i++; } if (!ModelState.IsValid) { return View("Review", new ReviewCartViewModel { Cart = cart }); } return RedirectToAction("EnterShippingDetails"); }
public ActionResult Add(Cart cart, int productId, int quantity) { Product product = daoTemplate.FindByID<Product>(productId); var quantityInCart = cart.CurrentQuantity(productId); if (quantityInCart + quantity > product.Rest()) { return Json(new [] {new { Key = "quantity", Value = "Слишком большое количество" }}); } cart.Add(product, quantity); return Json(new object[]{}); }
public AddOrderResult AddOrder(Cart cart, User user, OrderShippingInfo orderInfo) { if (cart == null) throw new ArgumentException("cart is null"); if (cart.Items == null) throw new ArgumentException("cart items is null"); if (user == null) throw new ArgumentException("user is null"); if (orderInfo == null) throw new ArgumentException("orderInfo is null"); // construct order var orderLines = new List<OrderLine>(); var orderOutcomes = new List<Outcome>(); foreach (CartItem item in cart.Items) { IList<Income> incomes = FindOldestIncomesForProduct(item.Product, item.Quantity); int quantity = item.Quantity; var outcomes = new List<Outcome>(); foreach (Income income in incomes) { int n = Math.Min(quantity, income.QuantityCurrent); income.QuantityCurrent -= n; _daoTemplate.Save(income); Outcome outcome = new Outcome(item.Product.Price, n, income, user.Discount + cart.CurrentDiscount()); quantity -= n; outcomes.Add(outcome); } orderOutcomes.AddRange(outcomes); orderLines.Add(new OrderLine(item.Product, item.Quantity, outcomes)); } Order order = new Order(orderOutcomes, orderLines); order.Comment = orderInfo.Comment ?? ""; DeliverPrices prices = _daoTemplate.FindAll<DeliverPrices>()[0]; if (orderInfo.PaymentType == PaymentType.OnPost) { order.DeliverPrice = prices.PostWhenReceived(cart.SummDiscount()); } else { order.DeliverPrice = GetPrice(orderInfo.DeliverType); } order.CopyFrom(orderInfo); order.User = user; order.Discount = user.Discount + cart.CurrentDiscount(); _daoTemplate.Save(order); order.Uid = _daoTemplate.FindByID<UniqueId>(order.Id).Uid; _daoTemplate.Save(order); return new AddOrderResult(){Order = order}; }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { // Some modelbinders can update properties on existing model instances. This // one doesn't need to - it's only used to supply action method parameters. if (bindingContext.Model != null) throw new InvalidOperationException("Cannot update instances"); // Return the cart from Session[] (creating it first if necessary) Cart cart = (Cart)controllerContext.HttpContext.Session[CartSessionKey]; if (cart == null) { cart = new Cart(); controllerContext.HttpContext.Session[CartSessionKey] = cart; } return cart; }
public ActionResult EnterShippingDetails(Cart cart) { if (cart.Summ() < 300) { ModelState.AddModelError("summ", "Минимальная сумма заказа 300 рублей"); return View("Review", new ReviewCartViewModel { Cart = cart }); } var model = new EnterShippingDetailsViewModel() { Contact = ContactViewModel.From(CurrentUser().Contact), User = CurrentUser(), Cart = cart, DeliverPrices = daoTemplate.FindAll<DeliverPrices>()[0] }; return View("EnterShippingDetails", model); }
public ActionResult CartWidget(Cart cart) { return View(cart); }
public ActionResult Send(EnterShippingDetailsViewModel viewModel, Cart cart) { if (!ModelState.IsValid || viewModel.DeliverType == DeliverType.NULL || viewModel.PaymentType == PaymentType.NULL) { if (viewModel.DeliverType == DeliverType.NULL) { ModelState.AddModelError("DeliverType", "Выберите способ доставки"); } if (viewModel.PaymentType == PaymentType.NULL) { ModelState.AddModelError("PaymentType", "Выберите способ оплаты"); } return View("EnterShippingDetails", new EnterShippingDetailsViewModel() { Contact = ContactViewModel.From(CurrentUser().Contact), Cart = cart, User = CurrentUser(), DeliverPrices = daoTemplate.FindAll<DeliverPrices>()[0], DeliverType = viewModel.DeliverType, Comment = viewModel.Comment }); } OrderShippingInfo info = OrderShippingInfo.From(viewModel); AddOrderResult result = orderService.AddOrder(cart, CurrentUser(), info); var message = MailService.RenderViewToString("~/Views/MailTemplates/NewOrder.aspx", result.Order, this.ControllerContext); BillViewModel model = new BillViewModel() { Price = result.Order.SummWithDiscount, Address = result.Order.ShippingDetails.AddressBill(), Uid = result.Order.Uid, UserName = result.Order.ShippingDetails.FullName }; var attachment = ""; if (result.Order.PaymentType == PaymentType.Bank) { attachment = MailService.RenderViewToString("~/Views/Order/Bill.aspx", model, this.ControllerContext); } MailService.Send("Новый заказ - Elfam.ru", message, result.Order.User.Email, attachment, null); message = MailService.RenderViewToString("~/Views/MailTemplates/NewOrderAdmin.aspx", result.Order, this.ControllerContext); // MailService.Send("Новый заказ № " + result.Order.Uid, message, "*****@*****.**"); mailService.SendCcAdmins("Новый заказ № " + result.Order.Uid, message, "*****@*****.**"); cart.Items.Clear(); return RedirectToAction("DetailsUser", "Order", new { id = result.Order.Uid }); }
public ActionResult Remove(int productId, Cart cart) { var remove = cart.Items.Single(x => x.Product.Id == productId); cart.Items.Remove(remove); return View("Review", new ReviewCartViewModel() { Cart = cart }); }
public ActionResult Recalc(EditAndCheckoutViewModel viewModel, Cart cart) { // take products from cart and update quantity foreach (var item in viewModel.CartLines) { CartLineViewModel item1 = item; cart.Items.Single(x => x.Product.Id == item1.ProductId).Quantity = item.Quantity; } int i = 0; foreach (CartItem cartItem in cart.Items) { cartItem.Product = daoTemplate.FindByID<Product>(cartItem.Product.Id); if (cartItem.Product.Rest() < cartItem.Quantity) ModelState.AddModelError(string.Format("CartLines[{0}].Quantity", i), "Слишком большое количество"); i++; } return View("Review", new ReviewCartViewModel { Cart = cart }); }
public ActionResult LoginAndCheckout(string email, string password, Cart cart) { if (userService.AuthenticateUser(email, password)) { User user = daoTemplate.FindUniqueByField<User>(Models.User.EmailProperty, email); FormsAuthentication.SetAuthCookie(email, true); return View("EnterShippingDetails", new EnterShippingDetailsViewModel() { Contact = ContactViewModel.From(user.Contact), User = user, Cart = cart, DeliverPrices = daoTemplate.FindAll<DeliverPrices>()[0] }); } else { ModelState.AddModelError("login", "Неправильное имя пользователя или пароль"); return View("LoginOrRegister", cart); } }
public ActionResult Index(Cart cart) { return View("Review", new ReviewCartViewModel{ Cart = cart}); }