public ActionResult SetRoom(int id) { var roomtype = _roomrepo.FindById(id); var employees = _userManager.GetUsersInRoleAsync("Employee").Result; foreach (var emp in employees) { if (_bookrepo.CheckAllocation(id, emp.Id)) { continue; } var allocation = new BookingViewModel { // BookingDate is the same as DateCreated BookingDate = DateTime.Now, EmployeeId = emp.Id, RoomTypeId = id, NumberOfDays = roomtype.DefaultDays, Period = DateTime.Now.Year }; var roomallocation = _mapper.Map <Booking>(allocation); _bookrepo.Create(roomallocation); } return(RedirectToAction(nameof(Index))); }