public async Task <ActionResult> SetLeave(int id) { var leaveType = await _leaverepo.FindById(id); var employees = await _userManager.GetUsersInRoleAsync("Employee"); foreach (var emp in employees) { if (await _leaveallocationrepo.CheckAlloaction(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))); }