public async Task<ActionResult> WorkingHours(IList<WorkingHoursView> workingHours) { var workingHoursList = new List<WorkingHours>(); foreach (var input in workingHours) { if (input.LunchBreak == true) { workingHoursList.Add(new WorkingHours { WeekDayId = input.WeekdayId, StartTime = input.StartTime, EndTime = input.LunchStart }); workingHoursList.Add(new WorkingHours { WeekDayId = input.WeekdayId, StartTime = input.LunchEnd, EndTime = input.EndTime }); } else { workingHoursList.Add(new WorkingHours { WeekDayId = input.WeekdayId, StartTime = input.StartTime, EndTime = input.EndTime }); } } int? workingHoursId = null; foreach (var schedule in workingHoursList) { workingHoursId = await _salaryRepository.InsertWorkingHours((Weekday)schedule.WeekDayId, schedule.StartTime, schedule.EndTime, workingHoursId); } var sessionId = _sessionManager.GetSessionId(Request, Response); if (workingHoursId.HasValue) { await _salaryRepository.AddWorkingScheduleToLatestSalaryDetail(sessionId, workingHoursId.Value); } return RedirectToAction("Index"); }