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