public ActionResult SaveEmpolyeeRegistartion(EmployeeRegistrationViewModel model) { string currentuser = HttpContext.Request.RequestContext.HttpContext.User.Identity.Name; var data = BusinessAccessLayer.EmployeeBAL.SaveEmployeeRegistration(Helpers.Converter.ConverToDomainModel(model), currentuser); return(Json(data, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> AddEmployee(EmployeeRegistrationViewModel model) { if (ModelState.IsValid) { var user = _mapper.MapEmployeeRegistrationViewModelToApplicationUser(model); var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!_roleManager.Roles.Any(x => x.Name == "Employee")) { var role = new IdentityRole { Name = ERole.Employee.ToString() }; await _roleManager.CreateAsync(role); } await _userManager.AddToRoleAsync(user, ERole.Employee.ToString()); return(RedirectToAction("Success", "Success")); } else { _logger.LogWarning("Can't create Employee user, something wrong with User Identity"); return(View(model)); } } else { _logger.LogWarning("While creating user occur invalid model"); return(View(model)); } }
public async Task AddEmployee_ReturnsRedirectToAction_ForValidModelAndSuccessfulCreateMethod() { //Arrange var model = new EmployeeRegistrationViewModel { UserName = "******", Password = "******", ConfirmPassword = "******", Adress = "Adress", City = "City", Country = "Country", ZipCode = "12345", Email = "*****@*****.**", FirstName = "FirstName", LastName = "LastName" }; //Arrange mockUserManager.Setup(s => s.CreateAsync(It.IsAny <ApplicationUser>(), model.Password)) .ReturnsAsync(IdentityResult.Success); //Act var result = await _controller.AddEmployee(model); //Assert var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result); Assert.Equal("Success", redirectToActionResult.ActionName); Assert.Equal("Success", redirectToActionResult.ControllerName); }
// GET: Employee public ActionResult RTrequestApproval() { HostelManagementSystemEntities7 db = new HostelManagementSystemEntities7(); List <StudentRegistrationViewModel> log = new List <StudentRegistrationViewModel>(); List <EmployeeRegistrationViewModel> emp = new List <EmployeeRegistrationViewModel>(); foreach (LoginDb l in db.LoginDbs) { if (l.Status == "NO" && l.Designation == "Student") { foreach (StudentDb d in db.StudentDbs) { if (l.Email == d.Email) { StudentRegistrationViewModel s = new StudentRegistrationViewModel(); s.Email = l.Email; log.Add(s); } } } if (l.Status == "NO" && l.Designation == "Mess Employee") { foreach (EmployeeDb d in db.EmployeeDbs) { if (l.Email == d.Email) { EmployeeRegistrationViewModel e = new EmployeeRegistrationViewModel(); e.email = l.Email; emp.Add(e); } } } } var model = new multitables(); model.emp = emp.ToList(); model.s = log.ToList(); //HostelManagementSystemEntities7 db = new HostelManagementSystemEntities7(); //List<LOGIN> lg = new List<LOGIN>(); //foreach(LoginDb l in db.LoginDbs) //{ // if(l.Status == "NO" && l.Designation== "Student") // { // LOGIN login = new LOGIN(); // login.Email = l.Email; // lg.Add(login); // } //} //return View(lg); return(View(model)); }
public static EmployeeRegistartion ConverToDomainModel(EmployeeRegistrationViewModel model) { EmployeeRegistartion employeeRegistartion = new EmployeeRegistartion(); employeeRegistartion.first_name = model.FirstName; employeeRegistartion.middle_name = model.MiddleName; employeeRegistartion.last_name = model.LastName; employeeRegistartion.username = model.UserName; employeeRegistartion.password = model.Password; employeeRegistartion.confirmpassword = model.ConfirmPassword; employeeRegistartion.department_id = model.Department; employeeRegistartion.date_of_birth = model.DateOfBirth; return(employeeRegistartion); }
public async Task AddEmployee_ReturnsAViewResult_ForInvalidModel() { //Arrange var model = new EmployeeRegistrationViewModel(); _controller.ModelState.AddModelError("eror", "some error"); //Act var result = await _controller.AddEmployee(model); //Assert Assert.IsType <ViewResult>(result); mockLogger.Verify( x => x.Log( It.Is <LogLevel>(l => l == LogLevel.Warning), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => v.ToString() == "While creating user occur invalid model"), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true))); }
public async Task AddEmployee_ReturnsAViewResult_ForValidModelAndUnsuccessfulCreateMethod() { //Arrange var model = new EmployeeRegistrationViewModel { UserName = "******", Password = "******", ConfirmPassword = "******", Adress = "Adress", City = "City", Country = "Country", ZipCode = "12345", Email = "*****@*****.**", FirstName = "FirstName", LastName = "LastName" }; mockUserManager.Setup(s => s.CreateAsync(It.IsAny <ApplicationUser>(), model.Password)) .ReturnsAsync(IdentityResult.Failed()); //Act var result = await _controller.AddEmployee(model); //Assert var viewResult = Assert.IsType <ViewResult>(result); var modelResult = Assert.IsType <EmployeeRegistrationViewModel>(viewResult.ViewData.Model); Assert.Equal(model.UserName, modelResult.UserName); mockLogger.Verify( x => x.Log( It.Is <LogLevel>(l => l == LogLevel.Warning), It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => v.ToString() == "Can't create Employee user, something wrong with User Identity"), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true))); }
public ActionResult EmployeeRegistration(EmployeeRegistrationViewModel reg) { try { bool flag = false; HostelManagementSystemEntities7 db = new HostelManagementSystemEntities7(); EmployeeDb s = new EmployeeDb(); foreach (EmployeeDb e in db.EmployeeDbs) { if (e.Email == reg.email) { flag = true; ModelState.AddModelError("", "Email already exist"); if (e.CNIC == reg.CNIC) { flag = true; ModelState.AddModelError("", "CNIC already exist"); break; } break; } if (e.CNIC == reg.CNIC) { flag = true; ModelState.AddModelError("", "CNIC already exist"); break; } } if (flag == true) { return(View()); } else { s.Address = reg.Address; s.BloodGroup = reg.BloodGroup; s.CNIC = reg.CNIC; s.ContactNo = reg.ContactNo; s.FatherName = reg.FatherName; s.Name = reg.Name; s.DOB = reg.DOB; s.Password = reg.password; s.Email = reg.email; s.Designation = reg.Designation; LoginDb l = new LoginDb(); l.Designation = reg.Designation; l.Email = reg.email; l.Password = reg.password; l.Status = "NO"; db.LoginDbs.Add(l); db.EmployeeDbs.Add(s); db.SaveChanges(); ModelState.Clear(); ViewBag.Message = "You are Registered Successfully"; return(RedirectToAction("login")); } } catch (Exception e) { throw (e); } }
public ApplicationUser MapEmployeeRegistrationViewModelToApplicationUser(EmployeeRegistrationViewModel employeeRegistrationViewModel) { return(_mapper.Map <ApplicationUser>(employeeRegistrationViewModel)); }