Beispiel #1
0
        public ActionResult Edit(EditProfessorViewModel professor)
        {
            if (!UserIsInRole("Admin"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var professorInput = new ProfessorInputUpdate
            {
                Degree      = professor.SelectedDegree,
                Email       = professor.Email,
                FirstName   = professor.FirstName,
                LastName    = professor.LastName,
                Phone       = professor.Phone,
                ProfessorId = Guid.Parse(professor.Id)
            };
            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"));
        }
Beispiel #2
0
        public ICommandResult Handle(ProfessorInputUpdate command)
        {
            var professor = new Professor(command.ProfessorId, command.FirstName, command.LastName,
                                          command.Email, command.Phone, command.Degree);
            var result = new StandardResult();

            result.AddRange(professor.Notifications);
            if (result.Notifications.Count == 0)
            {
                _PREP.Update(professor);
                result.Notifications.Add("Success", "O Professor foi Editado");
            }
            return(result);
        }
Beispiel #3
0
        public void ShouldUpdateProfessorWithError()
        {
            commandUpdate = new ProfessorInputUpdate()
            {
                ProfessorId = professor.Id,
                FirstName   = string.Empty,
                LastName    = string.Empty,
                Email       = string.Empty,
                Phone       = string.Empty,
                Degree      = EDegree.Master
            };
            StandardResult result = (StandardResult)handler.Handle(commandUpdate);

            Assert.IsFalse(result.IsValid);
            Assert.IsTrue(result.Notifications.Any(x => x.Key == "Email" && 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));
        }
Beispiel #4
0
        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
            };
        }