예제 #1
0
        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");
        }
예제 #2
0
 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[]{});
 }
예제 #3
0
        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};
        }
예제 #4
0
파일: CartBinder.cs 프로젝트: kilonet/elfam
 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;
 }
예제 #5
0
 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);
 }
예제 #6
0
 public ActionResult CartWidget(Cart  cart)
 {
     return View(cart);
 }
예제 #7
0
        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 });
        }
예제 #8
0
        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

            });
        }
예제 #9
0
 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 });
 }
예제 #10
0
 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);
     }
 }
예제 #11
0
 public ActionResult Index(Cart cart)
 {
     return View("Review", new ReviewCartViewModel{ Cart = cart});
 }