public async Task <ActionResult> SetLeave(int Id) { LeaveType leaveType = await _leavetyperepo.FindById(Id); IList <Employee> employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (Employee emp in employees) { bool hasAllocation = await _leaveallocationrepo.CheckAllocation(Id, emp.Id); if (hasAllocation) { continue; } LeaveAllocationViewModel allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = Id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; LeaveAllocation leaveAllocation = _mapper .Map <LeaveAllocation>(allocation); await _leaveallocationrepo.Create(leaveAllocation); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { // var leavetype = await _leavetyperepo.FindById(id); var leavetype = await _unitOfWork.LeaveTypes.Find(q => q.Id == id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employees) { 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); 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 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 async Task <ActionResult> SetLeave(int id) { var leaveType = await _leaverepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { /* * Checks if an existing row is found: * if found: we should skip past and not create a new object. * if NOT found: create the allocation object, map to type and call the _allocationrepo.Create. */ if (await _allocationrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); await _allocationrepo.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 async Task <ActionResult> SetLeave(int Id) { var leaveType = await _leaverepo.FindById(Id); var employees = await _userManager.GetUsersInRoleAsync("employee"); foreach (var emp in employees) { var myAllocation = await _leaveallocationrepo.CheckAllocation(Id, emp.Id); if (myAllocation) { continue; } var allocation = new LeaveAllocation { 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 = _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 })); }
/// <summary> /// GET: Allocating all the leave types for all the employees for the specific period /// </summary> /// <param name="id">The id of the leave type</param> /// <returns></returns> public ActionResult SetLeave(int id) { var leaveType = _leaveTypeRepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var employee in employees) { //If the leave type was already allocated to the employee continue with the next iteration if (_leaveAllocationRepo.CheckAllocation(id, employee.Id)) { continue; } //If the leave type was not allocated to the employee create the allocation view model var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; //Map the allocation view model to the allocation repository data var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); //Create the leave allocations entry in the database _leaveAllocationRepo.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; foreach (var emp in employees) //Go through the list of employee's { if (_leaveallocationrepo.CheckAllocation(id, emp.Id)) { //if their is leave allocation for this employee then continue continue; //skip iteration } var allocation = new LeaveAllocationViewModel { 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))); // Redirect back to 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 IActionResult SetLeave(Guid Id) { var leaveType = _leaveTypeRepository.FindById(Id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var employee in employees) { if (_repository.CheckAllocation(Id, employee.Id)) { continue; } var leaveAllocation = new LeaveAllocation { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = Id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; _repository.Create(leaveAllocation); _numberUpdated++; } return(RedirectToAction("Index", new { numberUpdated = _numberUpdated })); }
public ActionResult SetLeave(int id) { var leaveType = _typeRepo.FindById(id); // get all users with Employee role var employees = _userManager.GetUsersInRoleAsync("Employee").Result; // iterate the users with employee role foreach (var item in employees) { // check if they already allocated to prevent duplicates if (_repo.CheckAllocation(id, item.Id)) { continue; } var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = item.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; // map the allocated user var leaveAllocated = _mapper.Map <LeaveAllocation>(allocation); //create mapped user for leavement _repo.Create(leaveAllocated); } return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> SetLeave(int id) { var leavetypes = await _leaverepo.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employees) { //retriving leave type for which we are setting the employee if (await _leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new LeaveAllocaitionVM { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = id, NumberOfDays = leavetypes.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 _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))); }
public ActionResult SetLeave(int id) { var count = 0; try { var leaveType = _leaveTypeRepo.FindById(id.ToString()); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var item in employees) { if (!_repo.CheckAllocation(id, item.Id, DateTime.Now.Year)) { var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.UtcNow, EmployeeId = item.Id, LeaveTypeId = id, NumberofDays = leaveType.DefaultDays, LeaveYear = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); _repo.Create(leaveAllocation); count++; } } } catch { ModelState.AddModelError("", "Error occured, Action may not be fully completed."); } return(RedirectToAction(nameof(Index), new { @count = count })); }