예제 #1
0
        protected virtual IActionResult Get(MaterialView materialView)
        {
            if (materialView == null)
            {
                return(BadRequest());
            }

            var category = categoriesCache.GetCategory(materialView.CategoryName);

            if (!materialsAuthorization.CanGet(User.Roles, category))
            {
                return(Unauthorized());
            }

            if (materialView.IsHidden && !materialsAuthorization.CanHide(User.Roles, category))
            {
                return(Unauthorized());
            }

            if (materialView.DeletedDate != null && !materialsAuthorization.CanRestoreAsync(User, category.Id))
            {
                return(Unauthorized());
            }

            materialView.VisitsCount += materialsVisitsCounterCache.CountMaterial(UserOrIpKey, materialView.Id);

            return(Json(materialView));
        }
예제 #2
0
        protected virtual IActionResult Get(MaterialView materialView)
        {
            if (materialView == null)
            {
                return(BadRequest());
            }

            var category = categoriesCache.GetCategory(materialView.CategoryName);

            if (!materialsAuthorization.CanGet(User.Roles, category))
            {
                return(Unauthorized());
            }

            if (materialView.IsHidden && !materialsAuthorization.CanHide(User.Roles, category))
            {
                return(Unauthorized());
            }

            if (materialView.IsDeleted && !materialsAuthorization.CanRestoreAsync(User, category.Id))
            {
                return(Unauthorized());
            }

            return(Json(materialView));
        }
예제 #3
0
        public virtual async Task <IActionResult> GetById(int id)
        {
            int?categoryId = await materialsManager.GetMaterialCategoryIdAsync(id);

            if (categoryId == null)
            {
                return(BadRequest());
            }

            var category = categoriesCache.GetCategory(categoryId.Value);

            if (!materialsAuthorization.CanGet(User.Roles, category))
            {
                return(Unauthorized());
            }


            var materialViewModel = await materialsPresenter.GetViewModelAsync(id);

            return(Json(materialViewModel));
        }