public ActionResult SetLeave(int id) { var leavetype = _leaverepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (_leaveallocationrepo.CheckLeaveAllocation(emp.Id, 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))); }