public async Task <IActionResult> MyPaperEdit(MyPaperEditViewModel model) { if (ModelState.IsValid) { try { var paper = _paperRepository.GetPaper(model.Id); if (paper.Title == model.Title) { StatusMessage = "Error. The title has not been corrected."; return(RedirectToAction(nameof(MyPaperEdit), model.Id)); } if (_paperRepository.TitleTakenExcept(model.Title, paper.Id)) { StatusMessage = "Error. This title is already taken."; return(RedirectToAction(nameof(MyPaperEdit), model.Id)); } var user = await _userManager.GetUserAsync(HttpContext.User); var participancy = _participanciesRepository.GetParticipancy(paper.ParticipancyId); if (participancy.User.Id != user.Id) { StatusMessage = "You cannot edit this topic!"; return(RedirectToAction("Index", "Home")); } var newPaper = Mapper.Map <PaperDTO>(model); var result = _paperRepository.UpdatePaperTitle(newPaper); if (result == 1) { StatusMessage = "Succesfully updated."; return(RedirectToAction(nameof(MyPapers))); } } catch { StatusMessage = "Error. Something went wrong."; return(RedirectToAction(nameof(MyPapers))); } } StatusMessage = "Error. Something went wrong."; return(RedirectToAction(nameof(MyPapers))); }