예제 #1
0
        public ProductsViewModel GetViewModel(SearchFilter sf)
        {
            ProductsViewModel vm = new ProductsViewModel();

            vm.Filter   = sf.FilterString;
            vm.TownName = sf.TownName;

            var products = GetProducts(sf);

            if (products != null)
            {
                vm.Products = products.ToList();
            }

            vm.Regions = locationManager.GetRegions();

            vm.PagingInfo = new PagingInfo
            {
                CurrentPage    = sf.Page,
                ProductsOnPage = ProductsOnPage,
                Total          = (products == null) ? 0 : products.Count()
            };
            if (products != null)
            {
                vm.Products = vm.Products.Skip((sf.Page - 1) * ProductsOnPage).Take(ProductsOnPage);
            }

            return(vm);
        }
예제 #2
0
 public ActionResult AddProduct(AddProductViewModel productVM)
 {
     if (authHelper.IsAuthenticated(HttpContext))
     {
         ViewBag.IsLogged     = true;
         ViewBag.FirstAttempt = true;
         productVM.Regions    = locationManager.GetRegions().Skip(1).ToList();
         return(View(productVM));
     }
     TempData["ErrorMessage"] = true;
     return(RedirectToAction("Login", "Account"));
 }
예제 #3
0
        public ActionResult EditProduct(AddProductViewModel vm, IEnumerable <HttpPostedFileBase> images = null)
        {
            ViewBag.IsLogged   = true;
            vm.Images          = TempData["Images"] as Lazy <List <Image> >;
            TempData["Images"] = vm.Images; //refresh tempdata value

            if (ModelState.IsValid)
            {
                vm.Regions = locationManager.GetRegions().Skip(1).ToList();
                vm.User    = userManager.GetUserByCookies(HttpContext.Request.Cookies[Constants.NameCookie].Value);
                productManager.UpdateProduct(vm, images);
                //TempData["SuccessEdit"] = true;
                return(RedirectToAction("Cabinet", "Account"));
            }

            return(View(vm));
        }