Пример #1
0
 public PartialViewResult DeleteItem(Guid productId, UserData userData)
 {
     var shoppingCartId = Session.GetShoppingCardId();
     var cartItem = CartItemsRepository.Find(c => c.OrderId == shoppingCartId && c.ProductId == productId);
     if (cartItem != null)
     {
         CartItemsRepository.Delete(cartItem);
     }
     return PartialView("ShoppingCartTable", GetShoppingCartModel(userData));
 }
Пример #2
0
 public PartialViewResult AddProduct(Guid productId, int count, UserData userData)
 {
     var shoppingCartId = Session.GetShoppingCardId();
     var cartItem = CartItemsRepository.Find(c => c.OrderId == shoppingCartId && c.ProductId == productId);
     if (cartItem == null)
     {
         cartItem = new Unico.Data.Entities.CartItem() { OrderId = shoppingCartId, ProductId = productId };
     }
     cartItem.Count += count;
     CartItemsRepository.SaveOrUpdateAll(cartItem);
     return ShoppingCartWidget(userData);
 }
Пример #3
0
        public ActionResult CreateOrder(UserData userData)
        {
            if (userData == null)
            {
                return RedirectToAction("Index", "ShoppingCart", userData);
            }

            var orderId = Session.GetShoppingCardId();
            var cartItems = CartItemsRepository.FindAll(c => c.OrderId == orderId).ToList();
            if (cartItems.Count > 0)
            {
                Session.NewShoppingCardId();

                OrdersRepository.SaveOrUpdateAll(new Order()
                {
                        AccountId = userData.AccountId,
                        Number = HashHelper.GetStringHash(orderId),
                        ExternalId = orderId,
                        CreatedOn = DateTime.UtcNow
                });

                foreach (var cartItem in cartItems)
                {
                    var product = ProductsRepository.Find(p => p.ExternalId == cartItem.ProductId);
                    if (product != null)
                    {
                        ProductOrderRepository.SaveOrUpdateAll(new ProductOrder()
                        {
                                OrderId = orderId,
                                ProductId = cartItem.ProductId,
                                Count = cartItem.Count,
                                Price = product.Price,
                                LastStatusUpdate = DateTime.UtcNow,
                                Status = OrderStatus.New,
                                WorkType = WorkType.Sell //TODO!
                        });
                    }
                }

                var acc = AccountProfileRepository.Find(a => a.ExternalId == userData.AccountId);
                var orderModel = GenerateOrderModel(orderId, userData);
                var orderModelEmail = new OrderEmailModel() { OrderModel = orderModel, UserEmail = acc.Email, UserPhone = acc.Phone };

                EmailSender.Send(userData.AccountId, EmailTypeEnum.OrderConfirmation, orderModel);
                EmailSender.SendInternal(userData.AccountId, EmailTypeEnum.NewOrderCreated, orderModelEmail);

                return RedirectToAction("Index", userData);
            }

            return RedirectToAction("Index", "ShoppingCart", userData);
        }
Пример #4
0
 public PartialViewResult SetCount(Guid productId, int count, UserData userData)
 {
     if (count == 0)
     {
         return DeleteItem(productId, userData);
     }
     var shoppingCartId = Session.GetShoppingCardId();
     var cartItem = CartItemsRepository.Find(c => c.OrderId == shoppingCartId && c.ProductId == productId);
     if (cartItem != null)
     {
         cartItem.Count = count;
         CartItemsRepository.SaveOrUpdateAll(cartItem);
     }
     return PartialView("ShoppingCartTable", GetShoppingCartModel(userData));
 }
Пример #5
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Some code to validate and check authentication
                    if (!Membership.ValidateUser(model.Email, model.Password))
                    {
                        throw new Exception("Incorrect username or password");
                    }

                    AccountProfile account = AccountRepository.GetByEmail(model.Email);

                    UserData userData = new UserData
                    {
                        Name = account.Name,
                        AccountId = account.ExternalId,
                        Email = account.Email
                    };

                    Response.SetAuthCookie(account.ExternalId.ToString(), model.RememberMe, userData);

                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", "Имя пользователя или пароль указаны неверно.");
            }

            model.Password = "";
            return View(model);
        }
Пример #6
0
        private ShoppingCartModel GetShoppingCartModel(UserData userData)
        {
            var shoppingCartId = Session.GetShoppingCardId();
            var items = CartItemsRepository.FindAll(cart => cart.OrderId == shoppingCartId);

            return new ShoppingCartModel()
            {
                CartItems = items.Select(item =>
                {
                    var product = ProductsRepository.Find(p => p.ExternalId == item.ProductId);
                    return new Unico.Models.CartItem()
                    {
                        ProductId = product.ExternalId,
                        Brand = product.Brand.Name,
                        Count = item.Count,
                        Description = product.Description,
                        Name = product.Name,
                        Price = product.Price
                    };
                }).ToList()
            };
        }
Пример #7
0
        public PartialViewResult ShoppingCartWidget(UserData userData)
        {
            var model = new ShoppingCartWidgetModel();
            if (null != userData)
            {
                var shoppingCartId = Session.GetShoppingCardId();
                var itemsCount = CartItemsRepository.FindAll(cart => cart.OrderId == shoppingCartId).Count();
                model.Count = itemsCount;
            }

            return PartialView("ShoppingCartWidget", model);
        }
Пример #8
0
 public ActionResult Index(UserData userData)
 {
     return View(GetShoppingCartModel(userData));
 }
Пример #9
0
        private OrderModel GenerateOrderModel(Guid? orderId, UserData userData)
        {
            var order = OrdersRepository.Find(ord => ord.AccountId == userData.AccountId && ord.ExternalId == orderId);

            if (order == null)
            {
                return null;
            }

            var orderModel = Mapper.Map<OrderModel>(order);

            var orderItems = ProductOrderRepository.FindAll(item => item.OrderId == orderId).ToList()
                .Select(item =>
                {
                    var model = Mapper.Map<OrderItemModel>(item);
                    var prod = ProductsRepository.Find(p => p.ExternalId == item.ProductId);
                    if (prod != null)
                    {
                        model.ProductName = prod.Name;
                        model.ProductDetails = prod.Description;
                    }
                    return model;
                }).ToList();

            orderModel.Items = orderItems;
            return orderModel;
        }
Пример #10
0
        //
        // GET: /Orders/
        public ActionResult Index(UserData userData)
        {
            if (userData == null)
            {
                RedirectToAction("Index", "Home");
            }

            var orders = OrdersRepository.FindAll(ord => ord.AccountId == userData.AccountId).ToList()
                .OrderByDescending(ord=>ord.CreatedOn).Select(ord=> Mapper.Map<OrderModel>(ord));
            return View(orders);
        }
Пример #11
0
 public ActionResult Details(Guid? orderId, UserData userData)
 {
     var orderModel = GenerateOrderModel(orderId, userData);
     if (orderModel == null)
     {
         return RedirectToAction("Index", userData);
     }
     return View(orderModel);
 }
Пример #12
0
        public ActionResult LoginWidget(UserData userData)
        {
            LoginWidgetModel model = new LoginWidgetModel();
            if (null != userData)
                model.UserData = userData;

            return PartialView(model);
        }