/// <summary> /// /// </summary> /// <param name="requestDto"></param> /// <returns></returns> public async Task <int> AddEmployeeProfile(EmployeeProfileDto requestDto) { try { var employeeProfile = new EmployeeProfile { FirstName = requestDto.FirstName, LastName = requestDto.LastName, CellPhone = requestDto.CellPhone, City = requestDto.City, DateOfBirth = requestDto.DateOfBirth, HomePhone = requestDto.HomePhone, MiddleInitial = requestDto.MiddleInitial, JobTitle = requestDto.JobTitle, State = requestDto.State, StreetAddress = requestDto.StreetAddress, FkInitiatedById = requestDto.FkInitiatedById, WorkEmail = requestDto.WorkEmail, ZipCode = requestDto.ZipCode, FkGenderId = requestDto.GenderId, FkUserId = requestDto.FkUserId, CreatedOn = DateTime.Now, }; _context.EmployeeProfile.Add(employeeProfile); _context.SaveChanges(); return(await Task.FromResult(employeeProfile.PkEmployeeProfileId)); } catch (Exception e) { Console.WriteLine(e); throw; } }
/// <summary> /// /// </summary> /// <param name="requestDto"></param> /// <returns></returns> public async Task <int> UpdateEmployeeProfile(EmployeeProfileDto requestDto) { try { var employeeModel = _context.EmployeeProfile.Find(requestDto.EmployeeProfileId); employeeModel.LastName = requestDto.LastName; employeeModel.CellPhone = requestDto.CellPhone; employeeModel.City = requestDto.City; employeeModel.HomePhone = requestDto.HomePhone; employeeModel.MiddleInitial = requestDto.MiddleInitial; employeeModel.JobTitle = requestDto.JobTitle; employeeModel.StreetAddress = requestDto.StreetAddress; employeeModel.UpdatedOn = DateTime.Now; _context.EmployeeProfile.Update(employeeModel); _context.SaveChanges(); return(await Task.FromResult(employeeModel.PkEmployeeProfileId)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public IActionResult UpdateEmployee(EmployeeProfileDto requestDto) { try { _employeeProfileService.UpdateEmployeeProfile(requestDto); return(RedirectToAction("Employee")); } catch (Exception) { throw; } }
public IActionResult Employee() { var userId = GetUserid().ToString(); var employeeModel = _employeeProfileService.GetEmployeeProfileByUserId(userId); if (employeeModel == null) { var model = new EmployeeProfileDto(); return(View("Employee", model)); } return(View("Employee", employeeModel)); }
public async Task <IActionResult> CreateUser(Host.Models.AccountViewModels.UserInfoModel user) { if (!ModelState.IsValid) { return(View("NewHire", user)); } if (user.Id != null) { using (var scope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); var userMgr = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var userEmail = userMgr.FindByEmailAsync(user.Email).Result; var userProfile = userMgr.FindByEmailAsync(user.Email); userEmail.UserName = user.UserName; userEmail.Email = user.Email; userEmail.Status = true; // userEmail.PasswordHash = user.Password; userEmail.NormalizedUserName = user.NormalizeUserName; //var applicationUser = new ApplicationUser //{ // Email = user.Email, // Id = user.Id, // NormalizedEmail = user.NormalizeEmail, // AccessFailedCount = user.AccessFailedCount, // EmailConfirmed = user.EmailConfirmed, // PhoneNumber = user.PhoneNumber, // UserName = user.UserName, //}; //await _userManager.ChangePasswordAsync(applicationUser, user.ConfrimedPassword, user.Password); var result = userMgr.UpdateAsync(userEmail).Result; if (!result.Succeeded) { ModelState.AddModelError(result.Errors.ToString(), result.Errors.ToString()); throw new Exception(result.Errors.First().Description); } _roleService.UpdateUserRole(userEmail.Id, user.RoleId); Console.WriteLine("User Updated"); return(RedirectToAction("EmployeeProfile", "Employee")); } return(View()); } using (var scope = _serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var context = scope.ServiceProvider.GetService <ApplicationDbContext>(); context.Database.Migrate(); var userMgr = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var userEmail = userMgr.FindByEmailAsync(user.Email).Result; if (userEmail == null) { var userName = new ApplicationUser { UserName = user.UserName, Email = user.Email, Status = true }; var result = userMgr.CreateAsync(userName, user.Password).Result; if (!result.Succeeded) { ModelState.AddModelError(result.Errors.ToString(), result.Errors.ToString()); throw new Exception(result.Errors.First().Description); } result = userMgr.AddClaimsAsync(userName, new Claim[] { new Claim(JwtClaimTypes.Name, user.UserName), new Claim(JwtClaimTypes.GivenName, user.UserName), new Claim(JwtClaimTypes.FamilyName, user.UserName), new Claim(JwtClaimTypes.Email, user.Email), new Claim(JwtClaimTypes.EmailVerified, "true", ClaimValueTypes.Boolean) }).Result; if (!result.Succeeded) { throw new Exception(result.Errors.First().Description); } _roleService.AddUserRole(userName.Id, user.RoleId); Console.WriteLine("User Created"); var employeProfile = new EmployeeProfileDto { FirstName = user.UserName, FkInitiatedById = GetUserid().ToString(), FkUserId = userName.Id, CreatedOn = DateTime.Now, WorkEmail = user.Email, }; await _employeeProfileService.AddEmployeeProfile(employeProfile); if (user.RoleId == "cd149620-3f5c-4081-94d1-f24b2408aa72") { var company = new CompanyDto { Name = user.UserName, UserId = userName.Id }; await _companyService.AddCompany(company); } return(RedirectToAction("EmployeeProfile", "Employee")); } return(View()); } }