Beispiel #1
0
        public async Task <ActionResult> Create(ForumCategoryCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ParentCategory = await forumCategriesManager.ListCategoriesForLinks();

                return(View(model));
            }

            ForumCategoryDetailViewModel category = await forumCategriesManager.Create(model, User.Identity.GetUserId());

            return(RedirectToAction("Index", "Forum"));
        }
        public async Task <ForumCategoryDetailViewModel> Create(ForumCategoryCreateViewModel model, string creatorId)
        {
            if (!await userManager.IsInRoleAsync(creatorId, "Administrator"))
            {
                throw new NotAuthorizedUserException();
            }

            if (model.ForumCategoryParentId != null)
            {
                if (!await Exists((int)model.ForumCategoryParentId))
                {
                    throw new ContentNotFoundException("Не е намерена категорията!");
                }
            }

            var forumCategory = Mapper.Map <ForumCategories>(model, opts => opts.Items["CreatorId"] = creatorId);

            unitOfWork.ForumCategoriesRepository.Add(forumCategory);
            await unitOfWork.SaveAsync();

            return(Mapper.Map <ForumCategoryDetailViewModel>(forumCategory));
        }