public JsonResult UpdateShopProduct(int id, decimal price)
        {
            if (!Request.IsAjaxRequest())
            {
                throw new InvalidCastException("Not an ajax request");
            }

            var shopProduct = _shopProductRefRepository.Read(id);

            shopProduct.Price = price;

            if (WebSecurity.CurrentUserId != shopProduct.ShopId && !User.IsInRole("Administrator") && !User.IsInRole("Moderator"))
            {
                return(Json(new { status = "fail" }, "text/html"));
            }

            try
            {
                _shopProductRefRepository.Save(shopProduct);
            }
            catch
            {
                return(Json(new { status = "fail" }, "text/html"));
            }

            return(Json(new { status = "success" }, "text/html"));
        }
Example #2
0
        public ActionResult RemoveProductFromShop(FilterParams filterParams, int shopProductId)
        {
            var shopProduct = _shopProductRefRepository.Read(shopProductId);

            //Verification access
            if (shopProduct == null || (WebSecurity.CurrentUserId != shopProduct.Shop.UserId && !User.IsInRole("Administrator") && !User.IsInRole("Moderator")))
            {
                return(HttpNotFound());
            }

            try
            {
                _shopProductRefRepository.Delete(shopProduct);
            }
            catch
            {
                TempData["error"] = "Произошла ошибка при удалении товара";
            }
            return(RedirectToAction("ProductsShop", filterParams));
        }