public async Task <ActionResult> Login(LoginViewModel viewModel)
        {
            await SetInitialDataAsync();

            if (ModelState.IsValid)
            {
                UserDTO userDto = new UserDTO {
                    Email = viewModel.Email, Password = viewModel.Password
                };
                ClaimsIdentity claim = await UserService.Authenticate(userDto);

                if (claim == null)
                {
                    ModelState.AddModelError("", "Неверный логин или пароль");
                }
                else
                {
                    AuthenticationManager.SignOut();
                    AuthenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = true
                    }, claim);
                    var cartId = shoppingCartFactory.GetCart(this.HttpContext).ShoppingCartId;
                    await MigrateShoppingCart(userDto.Email, cartId);

                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(viewModel));
        }
Exemple #2
0
        public ActionResult Index(int?id, string category, int?page, string searchName, string author)
        {
            int pageSize   = 6;
            int pageNumber = (page ?? 1);
            IEnumerable <BookDTO> books;

            ViewBag.category   = category;
            ViewBag.searchName = searchName;
            ViewBag.author     = author;

            if (searchName == null)
            {
                books = bookService.GetBooks(category, author);
            }
            else
            {
                books = bookService.FindBooks(searchName);
            }

            var mapper         = new MapperConfiguration(cfg => cfg.CreateMap <BookDTO, BookViewModel>()).CreateMapper();
            var booksViewModel = mapper.Map <IEnumerable <BookDTO>, List <BookViewModel> >(books);


            if (Request.IsAjaxRequest())
            {
                var cart      = shoppingCartFactory.GetCart(HttpContext);
                var addedBook = bookService.GetBook(id.Value);
                orderService.AddToCart(addedBook, cart.ShoppingCartId);


                return(PartialView("BookSummary", booksViewModel.ToPagedList(pageNumber, pageSize)));
            }

            return(View(booksViewModel.ToPagedList(pageNumber, pageSize)));
        }
Exemple #3
0
        public ActionResult Index(int?id, string category, int?page, string searchName)
        {
            int pageSize   = 6;
            int pageNumber = (page ?? 1);
            IEnumerable <ProductDTO> products;

            ViewBag.category   = category;
            ViewBag.searchName = searchName;

            if (searchName == null)
            {
                products = productService.GetProducts(category);
            }
            else
            {
                products = productService.FindProducts(searchName);
            }

            var mapper            = new MapperConfiguration(cfg => cfg.CreateMap <ProductDTO, ProductViewModel>()).CreateMapper();
            var productsViewModel = mapper.Map <IEnumerable <ProductDTO>, List <ProductViewModel> >(products);

            if (Request.IsAjaxRequest())
            {
                var cart      = shoppingCartFactory.GetCart(HttpContext);
                var addedProd = productService.GetProduct(id.Value);
                orderService.AddToCart(addedProd, cart.ShoppingCartId);


                return(PartialView("Summary", productsViewModel.ToPagedList(pageNumber, pageSize)));
            }
            return(View(productsViewModel.ToPagedList(pageNumber, pageSize)));
        }
Exemple #4
0
        public async Task <ActionResult> Index(string returnUrl, Controller controller)
        {
            var cartId = shoppingCartFactory.GetCart(HttpContext);
            ShoppingCartViewModel viewModel = new ShoppingCartViewModel
            {
                CartItems = await orderService.GetAllCartItems(cartId.ShoppingCartId),
                returnUrl = returnUrl,
                CartTotal = await orderService.GetTotal(cartId.ShoppingCartId)
            };

            return(View(viewModel));
        }
        //
        // GET: /ShoppingCart/
        public ActionResult Index()
        {
            var cart = _shoppingCartFactory.GetCart(this.HttpContext);

            // Set up our ViewModel
            var viewModel = new ShoppingCartViewModel
            {
                CartItems = cart.GetCartItems(),
                CartTotal = cart.GetTotal()
            };

            // Return the view
            return(View(viewModel));
        }
Exemple #6
0
        public ActionResult AddressAndPayment(FormCollection values)
        {
            var order = new Order();

            TryUpdateModel(order);

            try
            {
                if (string.Equals(values["PromoCode"], PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Save Order
                    _orders.Add(order);
                    _unitOfWork.SaveChanges();
                    //Process the order
                    var cart = _shoppingCartFactory.GetCart(this.HttpContext);
                    cart.CreateOrder(order);

                    return(RedirectToAction("Complete",
                                            new { id = order.OrderId }));
                }
            }
            catch
            {
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
Exemple #7
0
        public async Task <ActionResult> MakeOrder(OrderViewModel model)
        {
            var order = new OrderDTO();

            if (ModelState.IsValid)
            {
                TryUpdateModel(order);
                order.OrderDate = DateTime.Now;
                var cart = shoppingCartFactory.GetCart(this.HttpContext);
                await orderSerivce.CreateNewOrder(order, cart.ShoppingCartId);

                return(RedirectToAction("Complete"));
            }

            return(View(model));
        }
        public async Task <ActionResult> AddToCart(int?id, int?page, string category)
        {
            var cart       = shoppingCartFactory.GetCart(HttpContext);
            var addedBook  = orderService.GetBook(id.Value);
            int pageSize   = 3;
            int pageNumber = (page ?? 1);

            await orderService.AddToCart(addedBook, cart.ShoppingCartId);

            BookViewModel viewModel = new BookViewModel
            {
                Books = orderService.GetBooks(category)
            };
            var books = orderService.GetBooks(category);

            return(PartialView("BookSummary", books.ToPagedList(pageNumber, pageSize)));
        }