public async Task <IActionResult> Add(PaperCreateViewModel model) { if (model == null) { StatusMessage = "Error. Something went wrong."; return(View(model)); } if (ModelState.IsValid) { if (_paperRepository.TitleTaken(model.Title)) { StatusMessage = "Error. This title is already taken."; return(RedirectToAction(nameof(Add))); } var user = await _userManager.GetUserAsync(HttpContext.User); var participancy = _participanciesRepository.GetUserCurrentParticipancy(user.Id); PaperDTO paper = Mapper.Map <PaperDTO>(model); paper.ParticipancyId = model.ParticipancyId; paper.Status = 0; var result = _paperRepository.AddPaper(paper); if (result == 1) { StatusMessage = "Succesfully created."; return(RedirectToAction(nameof(MyPapers))); } return(RedirectToAction(nameof(MyPapers))); } StatusMessage = "Error. Entered data is not valid."; return(View(model)); }
public async Task <IActionResult> Add() { var user = await _userManager.GetUserAsync(HttpContext.User); if (user == null) { return(RedirectToAction("Index", "Home")); } var participancy = _participanciesRepository.GetUserCurrentParticipancy(user.Id); if (participancy == null) { return(RedirectToAction("Index", "Home")); } if (participancy.User.Id != user.Id) { StatusMessage = "You cannot add topic for this person!"; return(RedirectToAction("Index", "Home")); } var model = new PaperCreateViewModel { ParticipancyId = participancy.Id, AuthorId = user.Id, SeasonId = participancy.SeasonId, Status = 0, StatusMessage = "Before uploading a paper administration have to accept topic." }; return(View(model)); }