public async Task <IActionResult> SetLeave(int leaveTypeId) { var leaveType = await leaveTypeRepository.FindById(leaveTypeId); var employees = userManager.GetUsersInRoleAsync("employee").Result; var numberUpdated = default(int); foreach (var employee in employees) { if (!await leaveAllocationRepository.CheackIfAllocationExistsForEmployee(leaveTypeId, employee.Id)) { var allocation = new LeaveAllocationVM { DateCreated = DateTime.Now, EmployeeId = employee.Id, LeaveTypeId = leaveTypeId, NumberOfDays = leaveType.DeafaultNumberOfDays, Period = DateTime.Now.Year }; var leaveAllocation = mapper.Map <LeaveAllocation>(allocation); await leaveAllocationRepository.Create(leaveAllocation); numberUpdated++; } } return(RedirectToAction(nameof(Index), new { numberUpdated = numberUpdated })); }