public async Task <ActionResult> SetLeave(int id) { var leavetype = await _leaverepo.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var employee in employees) { var isExist = await _leaveallocationrepo.CheckAllocation(id, employee.Id); if (isExist) { continue; } var allocation = new LeaveAllocationViewModel { 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 _unitOfWork.LeaveTypes.Find(q => q.Id == id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); int allocationCount = 0; foreach (var employee in employees) { if (await _unitOfWork.LeaveAllocations.Exists(q => q.LeaveTypeId == id && q.Period == DateTime.Now.Year && q.EmployeeId == employee.Id)) { continue; } var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocation); await _unitOfWork.LeaveAllocations.Create(leaveAllocation); allocationCount++; } await _unitOfWork.Save(); return(RedirectToAction(nameof(Index), new { numberUpdated = allocationCount })); }
/// <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) //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 ActionResult SetLeave(int id) { var leavetype = _leaveTypeRepository.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (_leaveAllocationRepository.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); _leaveAllocationRepository.Create(leaveallocation); } return(RedirectToAction(nameof(Index))); }
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) { 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 _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 _unitOfWork.LeaveTypes.Find(q => q.Id == id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { var checkAllocationResult = await _unitOfWork.LeaveAllocations.FindAll(x => x.EmployeeId == emp.Id && x.LeaveTypeId == id && x.Period == DateTime.Now.Year); if (checkAllocationResult.Any()) { 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 _unitOfWork.LeaveAllocations.Create(leaveAllocation); await _unitOfWork.Save(); } return(RedirectToAction(nameof(Index), "Home")); }
public async Task <ActionResult> SetLeave(int id) { //var leavetype = await _leaveTypeRepository.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 _leaveAllocation.CheckAllocation(id, emp.Id)) var period = DateTime.Now.Year; if (await _unitOfWork.LeaveAllocations.IsExists(q => (q.EmployeeId == emp.Id && q.Period == period && q.LeaveTypeId == id))) { continue; } var allocations = new LeaveAllocationViewModel { EmployeeId = emp.Id, DateCreated = DateTime.Now, LeaveTypeId = id, NumberOfDays = leavetype.DefaultNumberOfDays, Period = DateTime.Now.Year }; var leaveAllocation = _mapper.Map <LeaveAllocation>(allocations); //await _leaveAllocation.Create(leaveAllocation); await _unitOfWork.LeaveAllocations.Create(leaveAllocation); await _unitOfWork.Save(); } return(RedirectToAction(nameof(Index))); }
public ActionResult Edit(int id, LeaveAllocationViewModel model) { try { var leaveAllocation = _mapper.Map <LeaveAllocation>(model); if (!_repo.Update(leaveAllocation)) { ModelState.AddModelError("", "Something went wrong...."); return(View(model)); } return(RedirectToAction(nameof(ListEmployees))); } catch { ModelState.AddModelError("", "Something went wrong...."); return(View()); } }
public async Task <ActionResult> SetLeave(int leaveTypeId) { var leaveType = await _unitOfWork.LeaveTypes.Find(type => type.Id == leaveTypeId); var employees = await _userManager.GetUsersInRoleAsync("Employee"); var period = DateTime.Now.Year; foreach (var emp in employees) { //To avoid duplicates do not create a new allocation if employee //already has allocation var exist = await _unitOfWork.LeaveAllocations.Exists(allocation => allocation.LeaveTypeId == leaveTypeId && allocation.EmployeeId == emp.Id && allocation.Period == period); if (!exist) { continue; } var allocation = new LeaveAllocationViewModel { DateCreated = DateTime.Now, EmployeeId = emp.Id, LeaveTypeId = leaveTypeId, NumberOfDays = leaveType.DefaultDays, Period = period }; 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 _unitOfWork.LeaveTypes.Find(q => q.Id == id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); var period = DateTime.Now.Year; foreach (var employee in employees) { var isExists = await _unitOfWork.LeaveAllocations.isExists( q => q.Id == id && q.EmployeeId == employee.Id && q.Period == period ); if (isExists) { continue; } var allocation = new LeaveAllocationViewModel { EmployeeId = employee.Id, LeaveTypeId = id, NumberOfDays = leaveType.DefaultDays, Period = DateTime.Now.Year, DateCreated = DateTime.Now }; var leaveAllocaiton = _mapper.Map <LeaveAllocation>(allocation); await _unitOfWork.LeaveAllocations.Create(leaveAllocaiton); await _unitOfWork.Save(); } return(RedirectToAction("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 })); }
public ActionResult AddEditLeaveAllocation(LeaveAllocationViewModel leaveAllocationVM) { return(View()); }