public ActionResult EmployeeRegisterWithRole() { var departments = departmentManager.GetAll(); var divisions = divisionManager.GetAll(); EmployeeRegisterWithRoleViewModel model = new EmployeeRegisterWithRoleViewModel(); model.Designations = new List <Designation>(); model.Districts = new List <District>(); model.Thanas = new List <Thana>(); ViewBag.Departments = departments; ViewBag.DesignationId = new SelectListItem[] { new SelectListItem() { Value = "", Text = "Select Department First...." } }; ViewBag.Divisions = divisions; ViewBag.DistrictId = new SelectListItem[] { new SelectListItem() { Value = "", Text = "Select Division First....." } }; ViewBag.ThanaId = new SelectListItem[] { new SelectListItem() { Value = "", Text = "Select District First...." } }; return(View(model)); }
private void CreateEmployee(EmployeeRegisterWithRoleViewModel model, ApplicationUser user, byte[] imageData) { IEmployeeManager employeeManager = new EmployeeManager(); Employee employee = new Employee { Name = model.Name, UserId = user.Id, Email = model.Email, DepartmentId = model.DepartmentId, DesignationId = model.DesignationId, DivisionId = model.DivisionId, DistrictId = model.DistrictId, ThanaId = model.ThanaId, Address1 = model.Address1, //Address2 = model.Address2, ContactNo = model.ContactNo, IsDriver = false, Image = imageData, ImagePath = "~/EmployeeImages/" + model.Name + DateTime.Now, IsDeleted = false, UserRole = "Employee" }; employeeManager.Add(employee); //} }
private void CreateDriver(EmployeeRegisterWithRoleViewModel model, ApplicationUser user, byte[] imageData) { IEmployeeManager employeeManager = new EmployeeManager(); Employee employee = new Employee { Name = model.Name, UserId = user.Id, Email = model.Email, DepartmentId = model.DepartmentId, DesignationId = model.DesignationId, DivisionId = model.DivisionId, DistrictId = model.DistrictId, ThanaId = model.ThanaId, Address1 = model.Address1, //Address2 = model.Address2, ContactNo = model.ContactNo, LicenceNo = model.LicenceNo, IsDriver = true, Image = imageData, ImagePath = "~/EmployeeImages/" + model.Name + DateTime.Now, IsDeleted = false, UserRole = "Driver" }; employeeManager.Add(employee); var allEmployees = employeeManager.GetAll(); var maxEmployeeId = allEmployees.Max(c => c.Id); AddDataToDriverStatusTable(maxEmployeeId); }
public ActionResult EmployeeRegisterWithRole([Bind(Exclude = "UserPhoto")] EmployeeRegisterWithRoleViewModel model) { // ModelState.Remove("UserPhoto"); if (ModelState.IsValid) { var imageData = GetImageData(model.Name); if (HasFile(imageData)) { // To convert the user uploaded Photo as Byte Array before save to DB var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; user.Id = Guid.NewGuid().ToString(); var password = "******"; user.UserPhoto = imageData; if (model.Role == "Employee") { AddEmployeeRole(user); CreateEmployee(model, user, imageData); } if (model.Role == "Operator") { AddOperatorRole(user); CreateEmployee(model, user, imageData); } if (model.Role == "Driver") { AddDriverRole(user); CreateDriver(model, user, imageData); } var result = UserManager.Create(user, password); if (result.Succeeded) { TempData["msg"] = model.Role + " Saved Successfully!"; return(RedirectToAction("EmployeeRegisterWithRole")); } AddErrors(result); } else { TempData["msgPhoto"] = "Please give user photo"; GetDropDownsValues(model); return(View(model)); } } TempData["msg"] = model.Role + " Not Saved!"; GetDropDownsValues(model); return(View(model)); }
private void GetDropDownsValues(EmployeeRegisterWithRoleViewModel model) { var departments = departmentManager.GetAll(); var designations = designationManager.GetAll(); var divisions = divisionManager.GetAll(); var districts = districtManager.GetAll(); var thanas = thanaManager.GetAll(); ViewBag.Departments = departments; ViewBag.Divisions = divisions; model.Designations = designations; model.Districts = districts; model.Thanas = thanas; }