public ActionResult Create(CreateProfessorViewModel professor) { if (!UserIsInRole("Admin")) { return(RedirectToAction("Index", "Home")); } var professorInput = new ProfessorInputRegister { CPF = professor.CPF, Degree = professor.SelectedDegree, Email = professor.Email, FirstName = professor.FirstName, LastName = professor.LastName, Phone = professor.Phone }; var result = _professorCommand.Handle(professorInput); if (!result.IsValid) { foreach (var n in result.Notifications) { ModelState.AddModelError(n.Key, n.Value); } professor.Degrees = GetComboboxDegree(); return(View(professor)); } return(RedirectToAction("Index")); }
public void ShouldCreateProfessorWithError() { commandRegister = new ProfessorInputRegister() { FirstName = string.Empty, LastName = string.Empty, CPF = string.Empty, Email = string.Empty, Phone = string.Empty, Degree = EDegree.Master }; StandardResult result = (StandardResult)handler.Handle(commandRegister); Assert.IsFalse(result.IsValid); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Email" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "CPF" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "FirstName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "LastName" && x.Value != null)); Assert.IsTrue(result.Notifications.Any(x => x.Key == "Telefone" && x.Value != null)); }
public void Init() { conection = new MSSQLDB(new DBConfiguration()); _PREP = new ProfessorRepository(conection); _encryptor = new Encryptor(); handler = new ProfessorCommandHandler(_PREP, _encryptor); var db = conection.GetCon(); var cpf = "357.034.413-40"; string password = cpf.Replace("-", "").Replace(".", ""); password = _encryptor.Encrypt(password, out string salt); professor = new Professor("Lívia", "Emanuelly Elisa", cpf, "*****@*****.**", "(21) 2682-8370", EDegree.Master, password, salt); _PREP.Create(professor); commandRegister = new ProfessorInputRegister() { FirstName = "Lívia", LastName = "Emanuelly Elisa", CPF = cpf, Email = "*****@*****.**", Phone = "(21) 2682-8370", Degree = EDegree.Master }; commandUpdate = new ProfessorInputUpdate() { ProfessorId = professor.Id, FirstName = "Lívia", LastName = "Emanuelly Elisa", Email = "*****@*****.**", Phone = "(21) 2682-8370", Degree = EDegree.Master }; }