public async Task <IActionResult> Create(DocumentViewModel documentViewModel) { if (ModelState.IsValid) { string path = string.Empty; if (documentViewModel.DocumentFile != null) { path = await _documentHelper.UploadDocumentAsync(documentViewModel.DocumentFile, "document"); } DocumentEntity document = await _converterHelper.ToDocumentEntity(documentViewModel, path, true); document.User = _context.Users.FirstOrDefault(u => u.Email == User.Identity.Name); _context.Add(document); await _context.SaveChangesAsync(); TempData["Sent"] = "Your document has been sent and it will be reviewed soon."; return(RedirectToAction(nameof(Index))); } documentViewModel.Genders = _combosHelper.GetComboGenders(); documentViewModel.Authors = _combosHelper.GetComboAuthors(); documentViewModel.TypeOfDocuments = _combosHelper.GetComboTypeOfDocuments(); documentViewModel.DocumentLanguages = _combosHelper.GetComboDocumentLanguages(); return(View(documentViewModel)); }
public async Task <IActionResult> Register(AddUserViewModel model) { if (ModelState.IsValid) { string path = string.Empty; if (model.PictureFile != null) { path = await _imageHelper.UploadDocumentAsync(model.PictureFile, "image"); } UserEntity user = await _userHelper.AddUserAsync(model, path, UserType.User); if (user == null) { ModelState.AddModelError(string.Empty, "This email is already used."); return(View(model)); } var myToken = await _userHelper.GenerateEmailConfirmationTokenAsync(user); var tokenLink = Url.Action("ConfirmEmail", "Account", new { userid = user.Id, token = myToken }, protocol: HttpContext.Request.Scheme); var response = _mailHelper.SendMail(model.Username, "Email confirmation", $"<h1>Email Confirmation</h1>" + $"To allow the user, " + $"plase click in this link:</br></br><a href = \"{tokenLink}\">Confirm Email</a>"); if (response.IsSuccess) { ViewBag.Message = "The instructions to allow your user has been sent to email."; return(View(model)); } ModelState.AddModelError(string.Empty, response.Message); } return(View(model)); }