Example #1
0
        /// <summary>
        /// Adding new items to Cart or updating existed
        /// </summary>
        /// <param name="id">Goods Id in db</param>
        /// <param name="returnUrl">Url of previous page</param>
        /// <returns></returns>
        public RedirectToRouteResult Add(int id, string returnUrl)
        {
            Goods goods = _repository.GetGoods()
                          .FirstOrDefault(g => g.Id == id);

            if (goods != null)
            {
                GetCart().AddItem(goods, 1);
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Index(int?id)
        {
            // Arrange
            CompareModel model    = GetCompare();
            var          category = _repository.GetCategories().ToList();
            var          goods    = _repository.GetGoods().First(g => g.Id == id);
            var          url      = string.Empty;

            if (Request.UrlReferrer != null)
            {
                url = HttpContext.Request.UrlReferrer.AbsolutePath;
            }
            else
            {
                url = "~/Goods/List";
            }

            // Set url for return
            model.ReturnUrl = url;

            // Adding item to qq
            if (model.Item1 == null)   // first item is empty
            {
                model.Item1        = goods;
                Session["Compare"] = model;
            }
            else
            {
                if (model.Item2 == null) // second item is empty
                {
                    model.Item2        = _repository.GetGoods().FirstOrDefault(g => g.CategoryId == goods.CategoryId);
                    Session["Compare"] = model;
                }
                else  // qq is full, so we need cant add more items
                {
                    TempData["UserMess"] = "В очереди для сравнения уже есть 2 товара, для начала удалите один из них";
                    return(RedirectToAction("Index", "Item", new { id = id, UserMess = "В очереди для " }));
                }
            }

            // if we have 2 objects to compare - we compare them
            if (model.Item1 != null && model.Item2 != null)
            {
                return(View(model));
            }
            else // all other ways
            {
                TempData["UserMess"] = "Товар успешно добавлен в очередь для сравнения, добавьте еще один товар для сравнения";
                return(RedirectToAction("Index", "Item", new { id = id }));
            }
        }
Example #3
0
        /// <summary>
        /// Toogle Action wich can sort by id by asc and desc
        /// </summary>
        /// <param name="model"></param>
        /// <returns>View with sorted Goods</returns>
        public ActionResult ListById(GoodsModel model)
        {
            model.Sort         = (SortModel)Session["Sort"];
            ViewBag.Categories = GetCategories();

            if (model.Sort.RevboolId)
            {
                model.Goods = Filters(model)
                              .OrderBy(g => g.Id)
                              .Reverse().ToList();

                ReverseToModel(model, "Id");
                return(View("List", model));
            }
            else
            {
                model.Goods = _repository.GetGoods()
                              .OrderBy(g => g.Id).ToList();

                ReverseToModel(model, "Id");
                return(View("List", model));
            }
        }
Example #4
0
        // Creating new Order and saving it into db
        public ActionResult CreateOrder(CreateOrderModel model)
        {
            // Arrange
            var goods    = _goodsRepository.GetGoods().ToList();
            var status   = _orderRepository.GetStatuses().ToList();
            var userName = HttpContext.User.Identity.Name;
            var user     = HttpContext.GetOwinContext().GetUserManager <AppUserManager>()
                           .Users.FirstOrDefault(u => u.UserName == userName);
            var orderCart = ((Cart)HttpContext.Session["Cart"]).Lines.ToList();

            // Valdation
            if (ModelState.IsValid)
            {
                Order order = new Order()
                {
                    OrderCart   = orderCart,
                    Date        = DateTime.Now,
                    OrderStatus = status[0],
                    User        = userName,
                    Shipment    = new Shipment()
                    {
                        Address = model.Address,
                        City    = model.City,
                        Country = model.Country,
                        ZIP     = model.ZIP,
                        Reciver = model.Reciver
                    }
                };

                // Save order into db
                _orderRepository.AddOrder(order);
                // Send e-mail to admin
                SendNotification(user);
                // Clear Cart
                HttpContext.Session["Cart"] = null;
                // Some log info
                logger.Info($"Registred new order from user:{userName}");

                return(View());
            }

            // Return view if model is invalid
            return(View("Index", model));
        }
Example #5
0
 /// <summary>
 /// Displays all Goods from db into View
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     return(View(_repository.GetGoods().ToList()));
 }
Example #6
0
 public ActionResult Index(int id)
 {
     return(View(_repository.GetGoods().Single(i => i.Id == id)));
 }