public ActionResult SetLeave(int id) { var leaveTypes = _repoLeaveType.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (!_repoLeaveAllocation.CheckLeaveAllocation(id, emp.Id)) { 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); _repoLeaveAllocation.Create(leaveallocation); } } return(RedirectToAction(nameof(Index))); }