public TotalDto GetTotal(bool isSearch, int rows, int page, string sortBy, string sortOrder, string filters) { TotalDto total = new TotalDto(); IEnumerable <Line> query = GetFilteredAll(isSearch, filters); Line[] filteredAll = query.ToArray(); foreach (var line in filteredAll) { if (line.IsActive) { var busesToLines = line.BusesToLines.FirstOrDefault(); if (busesToLines != null) { var bus = busesToLines.Bus; DateHelper.IterDays(7, weekDay => { if (LineHelper.IsLineActiveAtDay(line, (DayOfWeek)(weekDay - 1))) { total.Seats += bus.seats.HasValue ? busesToLines.Bus.seats.Value : 0; total.Students += line.totalStudents.HasValue ? line.totalStudents.Value : 0; total.WeekDayPrices[weekDay - 1] += bus.price ?? 0; total.Price += bus.price.HasValue ? busesToLines.Bus.price.Value : 0; } }); } } } return(total); }
public void AutoCorrectLineSchedules(int LineID, DateTime periodStart_incl, DateTime periodEnd_excl) { var line = DB.Lines.First(x => x.Id == LineID); IQueryable <tblSchedule> schedules = DB .tblSchedules .Where(x => x.LineId == LineID); DateTime dateSt = periodStart_incl, dateEnd = periodStart_incl; Expression <Func <tblSchedule, bool> > scheduleDayPredicate = x => x.Date >= dateSt && x.Date < dateEnd; int days = DateHelper.GetDatesPeriodInDays(periodStart_incl, periodEnd_excl); if (days <= 0) { throw new ArgumentException("start date and end date periods must be in one day range at least, start should come first"); } ScheduleService schedServ = new ScheduleService(); DateHelper.IterDays(periodStart_incl, days, (i, date) => { dateSt = date; dateEnd = dateSt.AddDays(1); if (LineHelper.IsLineActiveAtDay(line, (DayOfWeek)i - 1)) { if (!schedules.Any(scheduleDayPredicate)) { var newSch = schedServ.GenerateSingleSchedule(line, date, true, true); SaveItem(newSch); } } else if (schedules.Any(scheduleDayPredicate)) { DB.tblSchedules.RemoveRange(schedules.Where(scheduleDayPredicate)); } }); DB.SaveChanges(); }