public async Task <IActionResult> CreateFanfic(CreateFanficViewModel createFanficViewModel) { try { var user = await _userManager.FindByEmailAsync(User.Identity.Name); var model = new Fanfic { NameFanfic = createFanficViewModel.NameFanfic, Description = createFanficViewModel.Description, DateTimePublish = createFanficViewModel.DateTimePublish, ApplicationUser = user, FandomId = createFanficViewModel.selectedFandom, CategoryId = createFanficViewModel.selectedCategory }; foreach (var tags in createFanficViewModel.SelectedTags) { model.FanficsTags.Add(new FanficTag() { TagId = Int32.Parse(tags) }); } await _unitOfWork.Fanfic.InsertAsync(model); await _unitOfWork.SaveAsync(); return(RedirectToAction("FanficList", "Fanfic")); } catch { return(View(nameof(FanficList))); } }
public async Task <IActionResult> CreateFanfic() { var tagsFromRepo = await _unitOfWork.Tag.GetAllAsync(); var selectList = new List <SelectListItem>(); foreach (var tags in tagsFromRepo) { selectList.Add(new SelectListItem(tags.TagTitle, tags.TagId.ToString())); } var createFanficViewModel = new CreateFanficViewModel() { Fandoms = _a.Fandoms.ToList(), Categories = _a.Categories.ToList(), Tags = selectList }; return(View(createFanficViewModel)); }