public async Task <ThemeDetailsViewModel> Create(ThemeCreateViewModel model, string agentId) { if (!(await userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Agent)) || await userManager.IsInRoleAsync(agentId, Enum.GetName(typeof(Role), Role.Administrator)))) { throw new NotAuthorizedUserException("Не сте оторизирани да изпълнявате тези действия"); } var category = await unitOfWork.ForumCategoriesRepository.Where(fc => fc.ForumCategoryId == model.CategoryId).FirstOrDefaultAsync(); if (category == null) { throw new ContentNotFoundException("Не е намерена категорията!"); } if (!category.IsOpenForThemes) { throw new ArgumentException("Категорията не е отворена за добавяне на теми!"); } var theme = Mapper.Map <Themes>(model, opt => opt.Items.Add("UserId", agentId)); unitOfWork.ThemesRepository.Add(theme); await unitOfWork.SaveAsync(); return(Mapper.Map <ThemeDetailsViewModel>(theme)); }
public async Task <ActionResult> Create(ThemeCreateViewModel model) { _logger.Info("Creating Theme! Params: " + model.ToJson()); if (!ModelState.IsValid) { _logger.Error("Creating Theme Form Invalid! Errors: " + ModelState.ToJson()); ViewBag.Categories = await forumCategoriesManager.ListCategoriesForLinks(); return(View(model)); } if (!await forumCategoriesManager.Exists(model.CategoryId)) { ModelState.AddModelError("CategoryId", "Категорията не съществува!"); _logger.Error("Creating Theme Form Invalid! Errors: " + ModelState.ToJson()); ViewBag.Categories = await forumCategoriesManager.ListCategoriesForLinks(); return(View(model)); } try { await themesManager.Create(model, User.Identity.GetUserId()); _logger.Info("Creating Theme Successfully!"); return(RedirectToAction("Index", "Forum")); } catch (Exception ex) { _logger.Error(ex, "Creating Theme Failed!"); throw; } }
public ActionResult Create(ThemeCreateViewModel themeModel) { return this.View(); }
public ActionResult Create() { var model = new ThemeCreateViewModel(); return this.View(model); }