예제 #1
0
 /// <summary>
 /// Load Categories from db
 /// </summary>
 /// <returns></returns>
 private IEnumerable <SelectListItem> GetCategories()
 {
     return(_repository.GetCategories().Select(
                s => new SelectListItem
     {
         Text = s.Name,
         Value = s.Id.ToString(),
         Disabled = false
     }).ToList());
 }
예제 #2
0
        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 }));
            }
        }
예제 #3
0
 /// <summary>
 /// Connection with db
 /// </summary>
 /// <param name="repo"></param>
 public OrderController(IEshopRepository goodsRepo, IOrderRepository orderRepo)
 {
     _goodsRepository   = goodsRepo;
     _orderRepository   = orderRepo;
     ViewBag.Categories = _goodsRepository.GetCategories().ToList();
 }
예제 #4
0
 /// <summary>
 /// Set connection with db
 /// </summary>
 /// <param name="repo"></param>
 public CartController(IEshopRepository repo)
 {
     _repository        = repo;
     ViewBag.Categories = _repository.GetCategories().ToList();
 }