public async Task <ActionResult> SetLeave(int id)//find which leave type is clicked { var leavetype = await _leaverepo.FindById(id); //set the number that assosiated with this type in the employee var employees = await _userManager.GetUsersInRoleAsync("Employee"); //now i have the type and the employee //retrive leave type and the employee and add ech recored to the employees foreach (var emp in employees) { if (await _leaveallocationrepo.CheckAllocation(id, emp.Id)) { continue; //if yes enter the iteration } 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))); }