Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int Id, BlogCategory viewModel, IFormFile file)
        {
            if (Id == null)
            {
                return(NotFound());
            }

            if (User.IsInRole(Roles.Client) || !User.Identity.IsAuthenticated)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await _blogCategoryService.AddFile(viewModel, file);

                    await _blogCategoryService.Update(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)));
                }
                catch (DBConcurrencyException)
                {
                    var exists = await Exists(viewModel.Id);

                    if (!exists)
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            var categories = await _blogCategoryService.GetAll();

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


            return(View(viewModel));
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Update(ForumPostCategoryViweModel model)
        {
            await _manageBlogCategory.Update(model);

            return(View());
        }