public async Task <IActionResult> Create(DirectorViewModel collection) { try { if (ModelState.IsValid) { var director = new Director { DirectorId = collection.DirectorId, Nome = collection.Nome, Email = collection.Email, Telefone = collection.Telefone, FaculdadeId = collection.FaculdadeId }; if (await _userManager.FindByEmailAsync(collection.Email) != null) { ModelState.AddModelError(string.Empty, $"O { collection.Email} já existe. Por favor tente com outro email."); } else { var result = _directorRepository.Adicionar(director); if (result != null) { if (await EnviarConfirmacao(result)) { return(RedirectToAction("Index", new { msg = "Director registado.", type = "success" })); } else { ModelState.AddModelError(string.Empty, "Erro ao enviar o email de confirmação de conta."); } } else { ModelState.AddModelError(string.Empty, "Erro ao registar director."); } } } ViewBag.FaculdadeId = ObterFaculdades(); return(View(collection)); } catch { ViewBag.FaculdadeId = ObterFaculdades(); return(View(collection)); } }