コード例 #1
0
ファイル: ShopsController.cs プロジェクト: ReklamaTM/reklama
        public ActionResult EditShopPage(int id)
        {
            var shop = _shopService.GetShop(id);

            if (shop == null || (WebSecurity.CurrentUserId != shop.UserID && !User.IsInRole("Administrator") && !User.IsInRole("Moderator")))
            {
                return(HttpNotFound());
            }

            _profileRepository.Context = new ReklamaContext();
            var result = new ShopPageViewModel()
            {
                Shop = shop
            };

            var categories = shop.ShopProduct.Select(q => q.Product.Category).Distinct().ToList();

            if (categories.Any())
            {
                result.MonthlyFee = categories.Sum(x => x.Price);
            }

            if (WebSecurity.CurrentUserId == shop.UserID && shop.IsActive == false && !User.IsInRole("Administrator") && !User.IsInRole("Moderator"))
            {
                TempData["error"] = "Магазин еще не активирован!";
                return(Redirect("/"));
            }

            return(View(result));
        }
コード例 #2
0
        /// <summary>
        /// Creates a ShopPageViewModel and returns the Shop view
        /// </summary>
        /// <returns>Shop view</returns>
        public IActionResult Shop()
        {
            var model = new ShopPageViewModel()
            {
                Products = productsService.GetAllProductsViewModel()
            };

            return(View(model));
        }
コード例 #3
0
ファイル: ShopsController.cs プロジェクト: ReklamaTM/reklama
        public ActionResult EditShopPage(ShopPageViewModel model)
        {
            var shop = _shopService.GetShop(model.Shop.ID);

            if (WebSecurity.CurrentUserId == shop.UserID || User.IsInRole("Administrator") || User.IsInRole("Moderator"))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        shop.Phone       = model.Shop.Phone;
                        shop.Site        = model.Shop.Site;
                        shop.Icq         = model.Shop.Icq;
                        shop.Skype       = model.Shop.Skype;
                        shop.Description = HtmlUtils.RemoveUnwantedTags(model.Shop.Description);
                        shop.Monday      = model.Shop.Monday;
                        shop.Tuesday     = model.Shop.Tuesday;
                        shop.Wednesday   = model.Shop.Wednesday;
                        shop.Thursday    = model.Shop.Tuesday;
                        shop.Friday      = model.Shop.Friday;
                        shop.Saturday    = model.Shop.Saturday;
                        shop.Sunday      = model.Shop.Sunday;
                        if (User.IsInRole("Administrator") || User.IsInRole("Moderator"))
                        {
                            shop.Title = model.Shop.Title;
                        }
                        _shopService.Save();
                        return(RedirectToAction("ViewShopPage", "Shops", new { id = shop.ID }));
                    }
                    catch
                    {
                        TempData["error"] = ProjectConfiguration.Get.DataErrorMessage;
                        return(View(model));
                    }
                }
                TempData["error"] = ProjectConfiguration.Get.DataErrorMessage;
                return(View(model));
            }
            else
            {
                return(RedirectToRoute("RestrictedAccess"));
            }
        }
コード例 #4
0
        public async Task <IActionResult> Index()
        {
            var categoryId = int.Parse(_cookieProvider.GetCookieValue("categoryId") ?? "0");
            var productsDB = await _productService.GetProductsFromDBByFilterAsync(1, categoryId);

            var products = productsDB
                           .Select(p =>
                                   new ProductViewModel
            {
                Id          = p.Id,
                Name        = p.Name,
                Price       = p.Price,
                Description = p.About,
                Count       = HttpContext
                              .Session
                              .Get <Cart>("Cart")
                              ?.GetCartItem(p.Id)
                              ?.Count ?? 0
            }).ToList();

            var categories = (await _productService.GetCategoriesFromDBAsync())
                             .Select(c =>
                                     new CategoryViewModel
            {
                Id    = c.Id,
                Name  = c.Name,
                State = c.Id == categoryId ? "active" : null
            }).ToList();

            var model = new ShopPageViewModel
            {
                CategoryId = categoryId,
                Products   = products,
                Categories = categories
            };

            return(View(model));
        }
コード例 #5
0
 public ShopPage()
 {
     InitializeComponent();
     BindingContext = new ShopPageViewModel(Navigation);
 }