public async Task <ActionResult> SetLeave(int id) { var leaveType = await _leaveTypeRepo.FindById(id); var employee = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employee) { if (await _leaveAllocationRepo.isLeaveExiss(id, emp.Id)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, leaveId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); await _leaveAllocationRepo.Create(leaveAllocation); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leavetype = await _leaverepo.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employees) { /* in case that leaveallcoation for this type of leave for this employee already exists */ if (await _leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _leaveallocationrepo.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
public ActionResult SetLeave(int id) { var leaveType = _repoLeaveType.FindById(id); var people = _people.GetUsersInRoleAsync("Member").Result; //int numUpdated = 0; foreach (var p in people) { if (_repo.CheckAllocation(id, p.Id)) { continue; //continue means skip this record } // else create a new record var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, PersonId = p.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); _repo.Create(leaveAllocation); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leaveType = await _leaveTypeRepo.FindById(id); //get all users that are employees (in employee role) var employees = await _userManager.GetUsersInRoleAsync("Employee"); //for each employee, create an allocation foreach (var employee in employees) { var check = await _LeaveAllocationrepo.CheckAllocation(leaveType.id, employee.Id); //skip leave allocation if the employee already has the leave if (check) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); await _LeaveAllocationrepo.Create(leaveAllocation); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leaveType = await _leaveRepo.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); int counter = 0; foreach (var e in employees) { bool isAllocationAvailable = await _leaveAllocationRepo.CheckAllocation(id, e.Id); if (isAllocationAvailable) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = e.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); await _leaveAllocationRepo.Create(leaveAllocation); counter++; } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leavetype = await _leaveTypeRepository.FindById(id); var employees = await _userManager.Users.ToListAsync(); foreach (var emp in employees) { if (await _leaveAllocationRepository.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _leaveAllocationRepository.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
public ActionResult SetLeave(int id) { var leavetype = _leaverepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (_leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); _leaveallocationrepo.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
public ActionResult SetLeave(int id) { var leaveType = _leaverepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; var noUpdated = 0; foreach (var emp in employees) { if (_leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocationVM() { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); _leaveallocationrepo.Create(leaveallocation); noUpdated++; } System.Diagnostics.Debug.WriteLine("No Updated: " + noUpdated); return(RedirectToAction(nameof(Index), new { id = noUpdated })); }
public async Task <ActionResult> SetLeave(int id) { var leavetype = await _unitofworkRepo.LeaveTypes.Find(q => q.Id == id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (await _unitofworkRepo.LeaveAllocations.isExists(q => q.EmployeeId == emp.Id && q.LeaveTypeId == id && q.Period == DateTime.Now.Year)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _unitofworkRepo.LeaveAllocations.Create(leaveallocation); await _unitofworkRepo.Save(); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leavetype = await _repoleaveTypes.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employees) { var checkallocation = await _repoleaveAllocation.CheckAllocation(id, emp.Id); if (checkallocation) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year, }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _repoleaveAllocation.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> SetLeave(int leaveTypeId) { var leaveType = await leaveTypeRepository.FindById(leaveTypeId); var employees = userManager.GetUsersInRoleAsync("employee").Result; var numberUpdated = default(int); foreach (var employee in employees) { if (!await leaveAllocationRepository.CheackIfAllocationExistsForEmployee(leaveTypeId, employee.Id)) { var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = leaveTypeId, NumberOfDays = leaveType.DeafaultNumberOfDays, Period = DateTime.Now.Year }; var leaveAllocation = mapper.Map <LeaveAllocation>(allocation); await leaveAllocationRepository.Create(leaveAllocation); numberUpdated++; } } return(RedirectToAction(nameof(Index), new { numberUpdated = numberUpdated })); }
public IActionResult AllocateLeave(int id) { var leaveType = _leaveTypeRepo.FindById(id); var employeeList = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employeeList) { //Check if employee is not already assigned with the leaves. //Number of Days should be default of each leave type //Period for which leave has been allocated should be defined. if (_leaveAllocationRepo.CheckEmployeeHasLeaveAssigned(id, emp.Id) == true) { continue; } var allocation = new LeaveAllocationVM { LeaveTypeId = id, EmployeeId = emp.Id, NumberOfDays = 10, DateCreated = DateTime.Now }; var leaveAllocationEntity = _mapper.Map <LeaveAllocation>(allocation); _leaveAllocationRepo.Create(leaveAllocationEntity); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id)//find which leave type is clicked { var leavetype = await _leaverepo.FindById(id); //set the number that assosiated with this type in the employee var employees = await _userManager.GetUsersInRoleAsync("Employee"); //now i have the type and the employee //retrive leave type and the employee and add ech recored to the employees foreach (var emp in employees) { if (await _leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; //if yes enter the iteration } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetype.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _leaveallocationrepo.create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { //var leaveType = await _leaveRepo.FindById(id); var leaveType = await _unitOfWork.LeaveTypes.Find(_ => _.Id == id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var employee in employees) { //if (await _leaveAllocationRepo.CheckAllocation(id, employee.Id)) if (await _unitOfWork.LeaveAllocations.IsExists(_ => _.EmployeeId == employee.Id && _.LeaveTypeId == id && _.Period == DateTime.Now.Year)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = leaveType.Id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); //await _leaveAllocationRepo.Create(leaveAllocation); await _unitOfWork.LeaveAllocations.Create(leaveAllocation); await _unitOfWork.Save(); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leavetypes = await _unitOfWork.LeaveTypes.Find(k => k.Id == id); var Employees = await _userManager.GetUsersInRoleAsync("Employee"); var period = DateTime.Now.Year; foreach (var emp in Employees) { //var isAllocated = await _leaveallocationrepo.CheckAllocation(id, emp.Id); if (await _unitOfWork.LeaveAllocations.IsExists(k => k.EmployeeId == emp.Id && k.LeaveTypeId == leavetypes.Id && k.Period == period)) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetypes.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); await _unitOfWork.LeaveAllocations.Create(leaveallocation); await _unitOfWork.Save(); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { //var leaveType = await _leaverepo.FindById(id); var leaveType = await _unitOfWork.LeaveTypes.Find(q => q.Id == id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; int numOfEmployeesUpdated = 0; var period = DateTime.Now.Year; foreach (var emp in employees) { //var checkAlloc = await _leaveallocationrepo.CheckAllocation(id, emp.Id); var checkAlloc = await _unitOfWork.LeaveAllocations.isExists(q => q.EmployeeId == emp.Id && q.LeaveTypeId == id && q.Period == period); if (checkAlloc) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leaveType.Days, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocation>(allocation); //await _leaveallocationrepo.Create(leaveallocation); await _unitOfWork.LeaveAllocations.Create(leaveallocation); await _unitOfWork.Save(); numOfEmployeesUpdated++; } return(RedirectToAction(nameof(Index), new { num = numOfEmployeesUpdated, leaveId = id })); }
public async Task <ActionResult> SetLeave(int id) { var leaveType = await _TypeRepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result.ToList(); foreach (var emp in employees) { if (await _AllocationRepo.CheckAllocation(id, emp.Id)) { continue; } if ((leaveType.Name == "Maternity Leave") && (emp.Gender == "Male" || emp.Gender == "Others")) { continue; } if ((leaveType.Name == "Paternity Leave") && (emp.Gender == "Female" || emp.Gender == "Others")) { continue; } var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveallocation = _mapper.Map <LeaveAllocationVM, LeaveAllocation>(allocation); await _AllocationRepo.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }