public AddEmployeeWindow() { InitializeComponent(); employeeInfo = new EmployeeInfoViewModel(); this.DataContext = employeeInfo; cboxDepart.ItemsSource = new DepartmentManageViewModel().departmentsModel; }
public async Task UpdateEmployeeInfo(EmployeeInfoViewModel model) { var employeeState = new EmployeeStateModel { EmployeeId = model.EmployeeId, ShiftId = (byte)model.ShiftId, LevelId = model.LevelId, PositionId = model.JobPositionId, JobFunctionId = model.JobFunctionId, BusStationId = model.BusStationId, JoinDate = model.JoinDate, ChangedDate = DateTime.Now }; var existEmployeeState = await _employeeStateService.ExistsAsync(model.EmployeeId); if (existEmployeeState) { await _employeeStateService.UpdateAsync(employeeState); } else { await _employeeStateService.AddAsync(employeeState); } }
public async Task <ActionResult> EmployeeInfo(Guid?id) { if (id == null || id.Value == Guid.Empty) { return(RedirectToAction("Index")); } var employee = await adminManager.GetEmployee(id.Value); if (employee == null) { return(RedirectToAction("Index")); } var reports = await reportPassingManager.GetReportByEmployeeId(id); var employeeInfo = new EmployeeInfoViewModel { Id = employee.EmployeeId, FullName = $"{employee.FirstName} {employee.Prefix} {employee.LastName}", Reports = reports, IsDeleted = employee.IsDeleted }; return(View(employeeInfo)); }
public IActionResult Index() { Employee emp = new Employee() { id = 1, name = "Mayura", location = "Bangalore", department = "Technology" }; EmployeeDetails empdetails = new EmployeeDetails() { id = 45, city = "Bangalore", state = "Karnataka", country = "India" }; EmployeeInfoViewModel employeeInfoViewModel = new EmployeeInfoViewModel() { employee = emp, employeeDetails = empdetails, title = "Employee Information Page", footer = "CopyRight @Euromonitor!!!" }; return(View(employeeInfoViewModel)); }
public ActionResult EditInfo() { int id = 1; EmployeeInfoViewModel infoViewModel = _employeeService.ViewEmployeeInfo(id); return(View(infoViewModel)); }
public void UpdateEmployeeProfile(EmployeeInfoViewModel evm) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeInfoViewModel, ApplicationUser>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); ApplicationUser e = mapper.Map <EmployeeInfoViewModel, ApplicationUser>(evm); _hrRepository.UpdateEmployeeProfile(e); }
public void UpdateEmployeeInfo(EmployeeInfoViewModel evm) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeInfoViewModel, EmployeeInfo>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); EmployeeInfo e = mapper.Map <EmployeeInfoViewModel, EmployeeInfo>(evm); er.UpdateEmployeeInfo(e); }
public void UpdateEmployeeEducation(EmployeeInfoViewModel evm) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeInfoViewModel, EmployeeEducation>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); EmployeeEducation e = mapper.Map <EmployeeInfoViewModel, EmployeeEducation>(evm); _employeeRepository.UpdateEmployeeEducation(e); }
public ActionResult UploadImage(EmployeeInfoViewModel evm) { string uid = _employeeService.GetUserID(); EmployeeInfoViewModel ivm = _employeeService.ViewEmployeeInfo(uid); evm.EmployeeInfoID = ivm.EmployeeInfoID; _employeeService.UpdateEmployeeInfo(evm); return(View("EditInfo", evm)); }
public EmployeeInfoViewModel ViewEmployeeInfo(int eid) { EmployeeInfo e = _employeeRepository.ViewEmployeeInfo(eid); var config = new MapperConfiguration(cfg => { cfg.CreateMap <EmployeeInfo, EmployeeInfoViewModel>(); cfg.IgnoreUnmapped(); }); IMapper mapper = config.CreateMapper(); EmployeeInfoViewModel evm = mapper.Map <EmployeeInfo, EmployeeInfoViewModel>(e); return(evm); }
public ActionResult EditInfo() { var appDbContext = new LeaveManagementDbContext(); var userStore = new ApplicationUserStore(appDbContext); var userManager = new ApplicationUserManager(userStore); string uid = _employeeService.GetUserID(); EmployeeInfoViewModel ivm = _employeeService.ViewEmployeeInfo(uid); return(View(ivm)); }
public ActionResult Create() { EmployeeInfoViewModel model = new EmployeeInfoViewModel() { Actived = true }; CreateViewBag(); return(View(model)); }
public async Task <IActionResult> EditTransportInfo(EmployeeInfoViewModel viewModel) { if (ModelState.IsValid) { await _profileViewModelService.UpdateEmployeeInfo(viewModel); return(RedirectToAction(nameof(Index), new { employeeId = viewModel.EmployeeId })); } return(View(viewModel)); }
public ActionResult EditInfo(EmployeeInfoViewModel evm) { string uid = _employeeService.GetUserID(); EmployeeInfoViewModel ivm = _employeeService.ViewEmployeeInfo(uid); evm.EmployeeInfoID = ivm.EmployeeInfoID; evm.EmployeeID = uid; _employeeService.UploadUserImage(evm); _employeeService.UpdateEmployeeInfo(evm); return(RedirectToAction("EditInfo")); }
public async Task <EmployeeInfoViewModel> GetEmployeeInfo(string employeeId) { var viewModel = new EmployeeInfoViewModel(); var employee = await _employeeService.GetByEmployeeIdWithDetailAsync(employeeId); if (employee != null) { viewModel.Departments = await _employeeDetailService.GetDepartments(); viewModel.Shifts = await _employeeDetailService.GetShifts(); viewModel.JobPosition = await _employeeDetailService.GetPositions(); viewModel.JobLevels = await _employeeDetailService.GetLevels(); viewModel.Routes = await _employeeDetailService.GetRoutes(); //viewModel.BusStations = await _employeeDetailService.GetBusStations(); if (employee.EmployeeState != null) { viewModel.EmployeeId = employee.EmployeeState.EmployeeId; viewModel.DepartmentId = employee.EmployeeState.JobFunction.Section.Department.DepartmentId; viewModel.SectionId = employee.EmployeeState.JobFunction.Section.SectionId; viewModel.ShiftId = employee.EmployeeState.ShiftId; viewModel.JobPositionId = employee.EmployeeState.PositionId; viewModel.JobFunctionId = employee.EmployeeState.JobFunctionId; viewModel.LevelId = employee.EmployeeState.LevelId; viewModel.RouteId = employee.EmployeeState.BusStation.Route.RouteId; viewModel.BusStationId = employee.EmployeeState.BusStationId; viewModel.JoinDate = employee.EmployeeState.JoinDate; viewModel.Sections = await _employeeDetailService.GetSectionsByDepartmentId(viewModel.DepartmentId); viewModel.JobFunctions = await _employeeDetailService.GetJobFunctionsBySectionId(viewModel.SectionId); viewModel.BusStations = await _employeeDetailService.GetGetBusStationsByRouteId(viewModel.RouteId); } var profileHeader = new ProfileHeaderViewModel() { FullName = $"{employee.Title}.{employee.FirstName} {employee.LastName}", FullNameThai = $"{employee.TitleThai}.{employee.FirstNameThai} {employee.LastNameThai}", ProfileImage = await GetProfileImage(employeeId) }; viewModel.ProfileHeader = profileHeader; } return(viewModel); }
public ActionResult Create(EmployeeInfoViewModel model, bool isRedirectToIndex = true) { try { if (ModelState.IsValid) { EmployeeModel modelAdd = new EmployeeModel(); Mapper.CreateMap <EmployeeInfoViewModel, EmployeeModel>(); modelAdd = Mapper.Map <EmployeeModel>(model); _context.Entry(modelAdd).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); AccountModel accountmodel = new AccountModel() { UserName = model.UserName, Password = model.Password, RolesId = model.RolesId, CustomerId = null, EmployeeId = modelAdd.EmployeeId, isCustomer = false, Actived = true }; _context.Entry(accountmodel).State = System.Data.Entity.EntityState.Added; _context.SaveChanges(); if (isRedirectToIndex) { return(RedirectToAction("Index")); } else { EmployeeInfoViewModel newmodel = new EmployeeInfoViewModel(); CreateViewBag(); return(View(newmodel)); } } } catch (Exception) { throw; } CreateViewBag(model.RolesId, model.StoreId, model.ParentId, model.EmployeeId); return(View(model)); }
public async Task <IActionResult> InfoAsync(int id) { var employeeViewModel = new EmployeeInfoViewModel(); var player = dbContext.Players.Where(p => p.PlayerId == id).FirstOrDefault(); var user = _userManager.Users.Where(u => u == player.User).First(); var role = await _userManager.GetRolesAsync(user); employeeViewModel.FirstName = player.FirstName; employeeViewModel.LastName = player.LastName; employeeViewModel.PlayerId = id; if (dbContext.Teams.Where(x => x.Developers.Contains(player)).FirstOrDefault() != null) { employeeViewModel.Team = dbContext.Teams.Where(x => x.Developers.Contains(player)).FirstOrDefault().Name; } employeeViewModel.Role = role.FirstOrDefault(); return(View(employeeViewModel)); }
protected EmployeeInfoViewModel GetEmployeeViewModel(EmployeeInfo employeeInfo) { var viewModel = new EmployeeInfoViewModel(); GetDropDowns(viewModel, employeeInfo.EmployeeId); if (employeeInfo != null) { viewModel.EmployeeInfo = employeeInfo; viewModel.ImagePath = employeeInfo.Employee.Picture != null?Url.Content(employeeInfo.Employee.Picture) : "/Images/noimage.jpg"; viewModel.PositionId = Convert.ToInt32(employeeInfo.PositionId); viewModel.Gender = employeeInfo.Employee.Gender; viewModel.PaymentFrequency = (int)employeeInfo.SalaryFrequency; viewModel.EmploymentStatus = employeeInfo.EmploymentStatus; } return(viewModel); }
public ActionResult Edit(int id = 0) { //EmployeeModel employee = _context.EmployeeModel // .Where(p => p.EmployeeId == id) // .FirstOrDefault(); //ViewModels.EmployeeInfoViewModel employee2 = _context.EmployeeModel // .Where(p => p.EmployeeId == id) // .FirstOrDefault(); //AccountModel account = _context.AccountModel // .Where(p => p.EmployeeId == employee.EmployeeId) // .FirstOrDefault(); EmployeeModel employeemodel = _context.EmployeeModel .Where(p => p.EmployeeId == id) .FirstOrDefault(); if (employeemodel == null) { return(HttpNotFound()); } else { EmployeeInfoViewModel model = new EmployeeInfoViewModel(); Mapper.CreateMap <EmployeeModel, EmployeeInfoViewModel>(); model = Mapper.Map <EmployeeInfoViewModel>(employeemodel); AccountModel accountmodel = _context.AccountModel .Where(p => p.EmployeeId == employeemodel.EmployeeId) .FirstOrDefault(); if (accountmodel != null) { model.UserName = accountmodel.UserName; model.Password = accountmodel.Password; model.retypePassword = accountmodel.Password; model.RolesId = accountmodel.RolesId.Value; model.RolesId = accountmodel.RolesId.Value; model.Actived = (accountmodel.Actived == true); } CreateViewBag(model.RolesId, model.StoreId, model.ParentId, model.EmployeeId); return(View(model)); } }
public EmployeeInfoViewModel GetEmployeeInfo(Guid employeeId) { var employee = _applicationDbContext.Employees.SingleOrDefault(p => p.Id == employeeId); if (employee == null) { throw new Exception($"Работника с id {employeeId} в базе нет"); } EmployeeInfoViewModel model = new EmployeeInfoViewModel() { EmployeeId = employee.Id.ToString(), PositionName = employee.EmployeePosition.Name, FirstName = employee.FirstName, LastName = employee.LastName, DoB = employee.DoB, Email = employee.Email }; return(model); }
public ActionResult Index() { EmployeeModel emp = _context.EmployeeModel.Find(currentAccount.EmployeeId); if (emp == null) { return(HttpNotFound()); } EmployeeInfoViewModel model = new EmployeeInfoViewModel(); Mapper.CreateMap <EmployeeModel, EmployeeInfoViewModel>(); model = Mapper.Map <EmployeeInfoViewModel>(emp); var account = _context.AccountModel.Find(currentAccount.UserId); if (account != null) { model.UserName = account.UserName; model.RolesId = account.RolesId.Value; model.RolesName = account.RolesModel.RolesName; } model.ParentName = _context.EmployeeModel.Where(p => p.EmployeeId == model.ParentId).Select(p => p.FullName).FirstOrDefault(); return(View(model)); }
public ActionResult Edit(EmployeeInfoViewModel model) { if (ModelState.IsValid) { try { AccountModel account = _context.AccountModel .Where(p => p.EmployeeId == model.EmployeeId) .FirstOrDefault(); if (account != null) { account.Password = model.Password; account.UserName = model.UserName; account.RolesId = model.RolesId; account.Actived = model.Actived; _context.Entry(account).State = System.Data.Entity.EntityState.Modified; } _context.SaveChanges(); EmployeeModel modelAdd = new EmployeeModel(); Mapper.CreateMap <EmployeeInfoViewModel, EmployeeModel>(); modelAdd = Mapper.Map <EmployeeModel>(model); // update EmployeeModel _context.Entry(modelAdd).State = System.Data.Entity.EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("Index")); } catch { CreateViewBag(model.RolesId, model.StoreId, model.ParentId, model.EmployeeId); return(RedirectToAction("Index")); } } CreateViewBag(model.RolesId, model.StoreId, model.ParentId, model.EmployeeId); return(View(model)); }
public ActionResult _SearchEmployee(EmployeeInfoViewModel model) { var myRoleOrderBy = _context.RolesModel.Where(p => p.RolesId == model.RolesId).Select(p => p.OrderBy).FirstOrDefault(); var currentRole = _context.RolesModel.Find(currentAccount.RolesId); var list = from emp in _context.EmployeeModel join acc in _context.AccountModel on emp.EmployeeId equals acc.EmployeeId join rol in _context.RolesModel on acc.RolesId equals rol.RolesId join empPaTmp in _context.EmployeeModel on emp.ParentId equals empPaTmp.EmployeeId into empPaLst from empPa in empPaLst.DefaultIfEmpty() where (model.EmployeeId == 0 || model.EmployeeId == emp.EmployeeId) && (model.Phone == null || emp.Phone.Contains(model.Phone)) // tìm theo thông tin role // tất cả && ((model.RolesId == 0 && (rol.OrderBy >= currentRole.OrderBy || currentRole.Code == "DEV") ) //Tìm theo role được chọn || (rol.OrderBy == myRoleOrderBy)) && emp.Actived == model.Actived && rol.Actived == true select new EmployeeInfoViewModel() { FullName = emp.FullName, Gender = emp.Gender, BirthDay = emp.BirthDay, RolesName = rol.RolesName, Actived = emp.Actived, Phone = emp.Phone, ParentName = empPa.FullName, EmployeeId = emp.EmployeeId }; return(PartialView(list.ToList())); }
public async Task <IActionResult> Create(EmployeeInfoViewModel employee) { if (ModelState.IsValid) { var userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; List <Document> teaList = new List <Document>(); if (employee.DocumentProfile != null) { foreach (IFormFile photo in employee.DocumentProfile) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images/Document", photo.FileName); var stream = new FileStream(path, FileMode.Create); photo.CopyTo(stream); Document teas = new Document() { DocumentImagePath = "../images/Document/" + photo.FileName }; teaList.Add(teas); } } ; EmployeeInfo str = new EmployeeInfo() { EmployeeName = employee.EmployeeName, FatherName = employee.FatherName, NRC = employee.NRC, Nationality = employee.Nationality, Gender = employee.Gender, MartialStatus = employee.MartialStatus, MobilePhone = employee.MobilePhone, DateOfBirth = employee.DateOfBirth, CurrentAddress = employee.CurrentAddress, EmergencyNo = employee.EmergencyNo, AccountNo = employee.AccountNo, ATMNumber = employee.ATMNumber, IsActive = employee.IsActive, CreatedDate = DateTime.Now, CreatedBy = userId, UserId = userId, Document = teaList, DepartmentId = employee.DepartmentId, DesignationId = employee.DesignationId, BranchId = employee.BranchId, BasicSalary = employee.BasicSalary }; if (employee.EmployeeProfile != null) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", employee.EmployeeProfile.FileName); var stream = new FileStream(path, FileMode.Create); employee.EmployeeProfile.CopyTo(stream); str.EmployeeProfile = "../images/" + employee.EmployeeProfile.FileName; } await employeeInfoRepository.Save(str); return(RedirectToAction(nameof(Index))); } ViewData["BranchId"] = new SelectList(branchRepository.GetBranchList(), "Id", "Id", employee.BranchId); ViewData["DepartmentId"] = new SelectList(departmentRepository.GetDepartmentList(), "Id", "Id", employee.DepartmentId); ViewData["DesignationId"] = new SelectList(designationRepository.GetDesignationList(), "Id", "Id", employee.DesignationId); return(View(employee)); }
public void EditEmployeeInfo(EmployeeInfoViewModel model) { var employee = _applicationDbContext.Employees.SingleOrDefault(p => p.Id.ToString() == model.EmployeeId); if (employee == null) { throw new Exception($"Работника с id {model.EmployeeId} в базе нет"); } var position = _applicationDbContext.EmployeePositions.SingleOrDefault(p => p.Name == model.PositionName); if (position == null) { EmployeePosition pos = new EmployeePosition() { Id = Guid.NewGuid(), Name = model.PositionName }; _applicationDbContext.EmployeePositions.Add(pos); _applicationDbContext.SaveChanges(); position = pos; } var oldEmail = employee.Email; employee.FirstName = model.FirstName; employee.LastName = model.LastName; employee.DoB = model.DoB; employee.Email = model.Email; employee.EmployeePositionId = position.Id; _applicationDbContext.SaveChanges(); var user = _identityDbContext.ApplicationUsers.Include("ApplicationUserPasswordHistories") .SingleOrDefault(p => p.AssosiatedEmployeeId.ToString() == model.EmployeeId && p.IsActive == true); var userPasswordHistory = user.ApplicationUserPasswordHistories .SingleOrDefault(p => p.InvalidatedDate == null); if (oldEmail != model.Email) { user.IsActive = false; userPasswordHistory.InvalidatedDate = DateTime.Now; _identityDbContext.SaveChanges(); ApplicationUser newUser = new ApplicationUser() { Id = Guid.NewGuid(), Email = model.Email, IsActive = true, FailedSignInCount = 0, CreatedDate = DateTime.Now, AssosiatedEmployeeId = employee.Id }; _identityDbContext.ApplicationUsers.Add(newUser); _identityDbContext.SaveChanges(); ApplicationUserPasswordHistory newUserPasswordHistory = new ApplicationUserPasswordHistory() { Id = Guid.NewGuid(), SetupDate = DateTime.Now, Password = model.Password, ApplicationUserId = newUser.Id }; _identityDbContext.ApplicationUserPasswordHistories.Add(newUserPasswordHistory); _identityDbContext.SaveChanges(); } else { if (userPasswordHistory.Password != model.Password) { userPasswordHistory.InvalidatedDate = DateTime.Now; _identityDbContext.SaveChanges(); ApplicationUserPasswordHistory userNewPasswordHistory = new ApplicationUserPasswordHistory() { Id = Guid.NewGuid(), SetupDate = DateTime.Now, Password = model.Password, ApplicationUserId = user.Id }; _identityDbContext.ApplicationUserPasswordHistories.Add(userNewPasswordHistory); _identityDbContext.SaveChanges(); } } }
public void EmployeeManagementService_CreateEmployeeByCeo() { ApplicationDbContext applicationDb = new ApplicationDbContext(); IdentityDbContext identityDb = new IdentityDbContext(); applicationDb.Database.CreateIfNotExists(); identityDb.Database.CreateIfNotExists(); OrganizationType organizationType = new OrganizationType() { Id = Guid.NewGuid(), Name = "TestTypeE_01" }; applicationDb.OrganizationTypes.Add(organizationType); applicationDb.SaveChanges(); Organization organization = new Organization() { Id = Guid.NewGuid(), FullName = "TestCompanyE_01", IdentificationNumber = "1111111", Address = "Almaty, Abai ave", Email = "*****@*****.**", Contacts = "+7777123456", Site = "test.org", RegistrationDate = DateTime.Now, OrganizationTypeId = organizationType.Id }; applicationDb.Organizations.Add(organization); applicationDb.SaveChanges(); var ceoPos = applicationDb.EmployeePositions.SingleOrDefault(p => p.Name == "CEO"); if (ceoPos == null) { EmployeePosition employeePosition = new EmployeePosition() { Id = Guid.NewGuid(), Name = "CEO" }; applicationDb.EmployeePositions.Add(employeePosition); applicationDb.SaveChanges(); ceoPos = employeePosition; } Employee ceo = new Employee() { Id = Guid.NewGuid(), FirstName = "TestECeo_01", LastName = "TestECeo_01", DoB = new DateTime(1985, 3, 4), Email = "*****@*****.**", OrganizationId = organization.Id, EmployeePositionId = ceoPos.Id }; applicationDb.Employees.Add(ceo); applicationDb.SaveChanges(); EmployeeInfoViewModel model = new EmployeeInfoViewModel() { PositionName = "TestE_Position01", FirstName = "TestEmployee_01", LastName = "TestEmployee_01", DoB = new DateTime(1983, 5, 22), Email = "*****@*****.**", Password = "******", PasswordConfirm = "ttt01qwerty123" }; EmployeeManagementService sut = new EmployeeManagementService(); var ceoId = ceo.Id; sut.CreateEmployeeByCeo(model, ceoId); Employee emp = applicationDb.Employees .SingleOrDefault(p => p.FirstName == "TestEmployee_01" && p.LastName == "TestEmployee_01"); ApplicationUser user = identityDb.ApplicationUsers.SingleOrDefault(p => p.Email == "*****@*****.**"); ApplicationUserPasswordHistory userPasswordHistory = identityDb.ApplicationUserPasswordHistories .SingleOrDefault(p => p.ApplicationUserId == user.Id && p.Password == "ttt01qwerty123"); Assert.IsNotNull(emp); Assert.IsNotNull(user); Assert.IsNotNull(userPasswordHistory); }
public void CreateEmployeeByCeo(EmployeeInfoViewModel model, Guid ceoId) { var employee = _applicationDbContext.Employees.SingleOrDefault(p => p.Id == ceoId); if (employee == null) { throw new Exception($"Работника с id {ceoId} в базе нет"); } var ceo = _applicationDbContext.EmployeePositions.SingleOrDefault(p => p.Name == "CEO"); if (ceo == null) { EmployeePosition pos = new EmployeePosition() { Id = Guid.NewGuid(), Name = "CEO" }; _applicationDbContext.EmployeePositions.Add(pos); _applicationDbContext.SaveChanges(); ceo = pos; } if (employee.EmployeePositionId != ceo.Id) { throw new Exception($"Работник с id {ceoId} не может создавать аккаунты других сотрудников компании"); } var position = _applicationDbContext.EmployeePositions.SingleOrDefault(p => p.Name == model.PositionName); if (position == null) { EmployeePosition pos = new EmployeePosition() { Id = Guid.NewGuid(), Name = model.PositionName }; _applicationDbContext.EmployeePositions.Add(pos); _applicationDbContext.SaveChanges(); position = pos; } Employee newEmployee = new Employee() { Id = Guid.NewGuid(), FirstName = model.FirstName, LastName = model.LastName, DoB = model.DoB, Email = model.Email, EmployeePositionId = position.Id, OrganizationId = employee.OrganizationId }; _applicationDbContext.Employees.Add(newEmployee); _applicationDbContext.SaveChanges(); ApplicationUser user = new ApplicationUser() { Id = Guid.NewGuid(), Email = model.Email, IsActive = true, FailedSignInCount = 0, CreatedDate = DateTime.Now, AssosiatedEmployeeId = newEmployee.Id }; _identityDbContext.ApplicationUsers.Add(user); _identityDbContext.SaveChanges(); ApplicationUserPasswordHistory userPasswordHistory = new ApplicationUserPasswordHistory() { Id = Guid.NewGuid(), SetupDate = DateTime.Now, Password = model.Password, ApplicationUserId = user.Id }; _identityDbContext.ApplicationUserPasswordHistories.Add(userPasswordHistory); _identityDbContext.SaveChanges(); }
public IActionResult UploadFile(IFormFile file) { int row = 0; Stream fileStream = file.OpenReadStream(); List <EmployeeInfo> employeesInfo = new List <EmployeeInfo>(); Dictionary <int, (int EmployeeId, int DaysWorked)> result = new Dictionary <int, (int EmployeeId, int DaysWorked)>(); using (var reader = new StreamReader(file.OpenReadStream())) { while (reader.Peek() >= 0) { row++; string line = reader.ReadLine(); string fromDateValue = string.Empty; string toDateValue = string.Empty; if (!line.ToLower().Contains("empid")) { string[] data = line.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); if (data.Length < 4) { continue; } else if (data.Length > 4) { data[3] = string.Join(", ", data.Skip(3)); } int employeeId = 0; int.TryParse(data[0], out employeeId); int projectId = 0; int.TryParse(data[1], out projectId); if (employeeId == 0 || projectId == 0) { continue; } fromDateValue = ValidateToDate(data[2]); toDateValue = ValidateToDate(data[3]); DateTime fromDate; DateTime.TryParse(fromDateValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out fromDate); DateTime toDate; DateTime.TryParse(toDateValue, CultureInfo.InvariantCulture, DateTimeStyles.None, out toDate); if (fromDate == default(DateTime) || toDate == default(DateTime)) { continue; } EmployeeInfo employeeInfo = new EmployeeInfo() { EmployeeId = employeeId, ProjectId = projectId, FromDate = fromDate, ToDate = toDate }; employeesInfo.Add(employeeInfo); } } } List <int> projects = employeesInfo.Select(x => x.ProjectId).Distinct().ToList(); EmployeeInfoViewModel model = new EmployeeInfoViewModel(); foreach (int project in projects) { EmployeeInfoDto dto = new EmployeeInfoDto() { ProjectId = project }; double maxDays = 0; List <EmployeeInfo> employeesWorkedOnSameProject = employeesInfo.Where(x => x.ProjectId == project).ToList(); if (employeesWorkedOnSameProject.Count < 2) { continue; } for (int i = 0; i < employeesWorkedOnSameProject.Count - 1; i++) { int firstEmployeeId = employeesWorkedOnSameProject[i].EmployeeId; DateTime firstPersonFromDate = employeesWorkedOnSameProject[i].FromDate; DateTime firstPersonToDate = employeesWorkedOnSameProject[i].ToDate; for (int j = i + 1; j < employeesWorkedOnSameProject.Count; j++) { int secondEmployeeId = employeesWorkedOnSameProject[j].EmployeeId; if (firstEmployeeId == secondEmployeeId) { continue; } DateTime secondPersonFromDate = employeesWorkedOnSameProject[j].FromDate; DateTime secondPersonToDate = employeesWorkedOnSameProject[j].ToDate; double days = OverlappingDays(firstPersonFromDate, firstPersonToDate, secondPersonFromDate, secondPersonToDate); if (days > maxDays) { maxDays = days; dto.DaysOnSameProject = (int)maxDays; dto.FirstEmployeeId = firstEmployeeId; dto.SecondEmployeeId = secondEmployeeId; } } } model.EmployeesInfo.Add(dto); } model.EmployeesInfo = model.EmployeesInfo.OrderBy(x => x.ProjectId).ToList(); return(View("Result", model)); }
public async Task <IActionResult> Create(EmployeeInfoViewModel employee) { if (ModelState.IsValid) { List <Document> teaList = new List <Document>(); if (employee.DocumentProfile != null) { foreach (IFormFile photo in employee.DocumentProfile) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", photo.FileName); var stream = new FileStream(path, FileMode.Create); photo.CopyTo(stream); Document teas = new Document() { DocumentImagePath = photo.FileName }; teaList.Add(teas); } } ; if (employee.EmployeeProfile != null) { foreach (IFormFile photos in employee.EmployeeProfile) { var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images", photos.FileName); var stream = new FileStream(path, FileMode.Create); photos.CopyTo(stream); EmployeeInfo str = new EmployeeInfo() { EmployeeName = employee.EmployeeName, FatherName = employee.FatherName, NRC = employee.NRC, Nationality = employee.Nationality, Gender = employee.Gender, MartialStatus = employee.MartialStatus, MobilePhone = employee.MobilePhone, DateOfBirth = employee.DateOfBirth, CurrentAddress = employee.CurrentAddress, EmergencyNo = employee.EmergencyNo, AccountNo = employee.AccountNo, ATMNumber = employee.ATMNumber, IsActive = employee.IsActive, CreatedDate = employee.CreatedDate, CreatedBy = employee.CreatedBy, EmployeeProfile = photos.FileName, Document = teaList, DepartmentId = employee.DepartmentId, DesignationId = employee.DesignationId, BranchId = employee.BranchId }; await employeeInfoRepository.Save(str); } return(RedirectToAction(nameof(Index))); } } ViewData["BranchId"] = new SelectList(branchRepository.GetBranchList(), "Id", "Id", employee.BranchId); ViewData["DepartmentId"] = new SelectList(departmentRepository.GetDepartmentList(), "Id", "Id", employee.DepartmentId); ViewData["DesignationId"] = new SelectList(designationRepository.GetDesignationList(), "Id", "Id", employee.DesignationId); return(View(employee)); }
public ActionResult EditInfo(EmployeeInfoViewModel evm) { _employeeService.UpdateEmployeeInfo(evm); return(View()); }