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)); }
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)); }