示例#1
0
        public ActionResult CreateLoginForExistentEmployee(Employee employee)
        {
            try
            {
                if (String.IsNullOrEmpty(employee.Email))
                {
                    ModelState.AddModelError("", "Para criar um login para o funcionário, preencha o E-mail do mesmo.");
                    return View("Edit", employee);
                }

                //TODO it should be great to try not need to go to the database get the instance of the user, but use the same instace it was used in the GET of this page

                _employeeLoginFacade.CreateNewUserForExistentEmployeeAccount(employee);

                return RedirectToAction("Index");
            }
            catch (EmployeeWithExistentEmailException ex)
            {
                ModelState.AddModelError("EmailExists", ex.Message);
                return View("Edit", employee);
            }
            catch
            {
                return View("Edit");
            }
        }
示例#2
0
 public ActionResult Edit(Employee employee, string submitButton)
 {
     switch (submitButton)
     {
         case "Atualizar":
             return (UpdateEmployee(employee));
         case "CriarLogin":
             return (CreateLoginForExistentEmployee(employee));
         default:
             return View();
     }
 }
示例#3
0
        public ActionResult UpdateEmployee(Employee employee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _employeeLoginFacade.UpdateEmployee(employee);

                    return RedirectToAction("Index");
                }

                return View("Edit", employee);
            }
            catch
            {
                return View("Edit");
            }
        }
示例#4
0
        public ActionResult DeleteConfirmed(Employee employee)
        {
            try
            {
                _employeeLoginFacade.DeleteEmployee(employee.Id);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        public void Given_A_Employee_Data_Without_Email_When_Creating_Login_For_Existent_Employee_Then_Should_Not_Create_New_User_For_Employee_And_Return_Error_Message()
        {
            var employee = new Employee
            {
                Name = "Quezia",
                LastName = "Mello",
                Company = CompanyDummies.CreateMjrCompany()
            };

            var result = _employeeController.CreateLoginForExistentEmployee(employee);

            Assert.IsNotNull(result);
            Assert.AreEqual("Para criar um login para o funcionário, preencha o E-mail do mesmo.", _employeeController.ModelState[""].Errors[0].ErrorMessage);
        }
 private void AssertUpdatedEmployeeFields(Employee employee, Employee employeeInDb)
 {
     Assert.AreEqual(employee.Phone, employeeInDb.Phone);
     Assert.AreEqual(employee.Name, employeeInDb.Name);
     Assert.AreEqual(employee.LastName, employeeInDb.LastName);
     Assert.AreEqual(employee.Email, employeeInDb.Email);
 }
        public void Given_A_Valid_Employee_Data_When_Creating_Login_For_Existent_Employee_Then_Should_Update_Employee_Datas_And_Create_New_User_For_Employee_And_Send_An_Email_To_Updated_Employee()
        {
            var employee = new Employee
            {
                Name = "Quezia",
                LastName = "Miceli",
                Email = "*****@*****.**",
                Phone = "(21) 98802-3922"
            };

            var employeeInDb = new Employee
            {
                Name = "Quezia",
                LastName = "Mello",
                Company = CompanyDummies.CreateMjrCompany()
            };

            _emailServiceMock.Setup(x => x.SendFirstLoginToEmployee(It.IsAny<string>(), employee.Email, employee.Name, employee.LastName));
            _employeeRepositoryMock.Setup((x => x.GetById(It.IsAny<object>()))).Returns(employeeInDb);
            _flexMembershipRepositoryMock.Setup(x => x.GetUserByUsername(employee.Email)).Returns((User)null);
            _flexMembershipRepositoryMock.Setup(x => x.Add(It.IsAny<User>()));

            var result = _employeeController.CreateLoginForExistentEmployee(employee) as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
            AssertUpdatedEmployeeFields(employee, employeeInDb);

            _employeeRepositoryMock.VerifyAll();
            _flexRoleStoreMock.VerifyAll();
            _emailServiceMock.VerifyAll();
            _flexMembershipRepositoryMock.VerifyAll();
        }
        public void Given_A_Employee_Data_With_Email_Existent_When_Creating_Login_For_Existent_Employee_Then_Should_Not_Create_New_User_For_Employee_And_Return_Error_Message()
        {
            var employee = new Employee
            {
                Name = "Quezia",
                LastName = "Mello",
                Email = "*****@*****.**",
                Company = CompanyDummies.CreateMjrCompany()
            };

            _employeeRepositoryMock.Setup((x => x.GetById(It.IsAny<object>()))).Returns(employee);
            _flexMembershipRepositoryMock.Setup(x => x.GetUserByUsername(employee.Email)).Returns(UserDummies.ReturnOneMjrActiveUser);

            var result = _employeeController.CreateLoginForExistentEmployee(employee);

            Assert.IsNotNull(result);
            Assert.AreEqual("Este E-mail já existe para outro funcionário", _employeeController.ModelState["EmailExists"].Errors[0].ErrorMessage);

            _employeeRepositoryMock.VerifyAll();
            _flexRoleStoreMock.VerifyAll();
        }