예제 #1
0
        public async Task <IActionResult> Create(BlogCategory viewModel, IFormFile file)
        {
            if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                await _blogCategoryService.AddFile(viewModel, file);

                var Id = await _blogCategoryService.Add(viewModel);

                if (!String.IsNullOrEmpty(Request.Form["continue"]))
                {
                    return(RedirectToAction("Edit", new { Id = Id }));
                }
                if (!String.IsNullOrEmpty(Request.Form["new"]))
                {
                    return(RedirectToAction(nameof(Create)));
                }
                return(RedirectToAction(nameof(Index)));
            }
            var categories = await _blogCategoryService.GetAll();

            ViewBag.Categories = new SelectList(categories.ToList(), "Id", "Title", viewModel.ParentId);

            return(View(viewModel));
        }
예제 #2
0
        public IActionResult SaveEntity(BlogCategoryViewModel BlogVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }

            BlogVm.SeoAlias = TextHelper.ToUnsignString(BlogVm.Name);
            if (BlogVm.Id == 0)
            {
                _blogCategoryService.Add(BlogVm);
            }
            else
            {
                _blogCategoryService.Update(BlogVm);
            }
            _unitOfWork.Commit();
            return(new OkObjectResult(BlogVm));
        }