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))); }