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));
 }
 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);
 }
Beispiel #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);
        }
 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));
 }
Beispiel #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);
        }
        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()
            };
        }
        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);
        }
 public ActionResult Index(UserData userData)
 {
     return View(GetShoppingCartModel(userData));
 }
Beispiel #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;
        }
Beispiel #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);
        }
Beispiel #11
0
 public ActionResult Details(Guid? orderId, UserData userData)
 {
     var orderModel = GenerateOrderModel(orderId, userData);
     if (orderModel == null)
     {
         return RedirectToAction("Index", userData);
     }
     return View(orderModel);
 }
Beispiel #12
0
        public ActionResult LoginWidget(UserData userData)
        {
            LoginWidgetModel model = new LoginWidgetModel();
            if (null != userData)
                model.UserData = userData;

            return PartialView(model);
        }