private static List <TrainDestinations> GetTrainDestinationsByHelpInfo(List <TrainsDestinationHelp> help) { List <TrainDestinations> res = new List <TrainDestinations>(); RailwaysEntities context = RailwaysData.sharedContext; foreach (TrainsDestinationHelp h in help) { List <int> ids = context.ExecuteStoreQuery <int>("select STOPS.STATION_ID\n" + "from STOPS\n" + "where STOPS.TRAIN_ID={0} And (STOPS.STOP_NUMBER={1} Or STOPS.STOP_NUMBER={2})\n" + "order by STOPS.STOP_NUMBER\n", h.ID, h.MIN, h.MAX).ToList(); int mn = ids[0]; int mx = ids[1]; List <string> names = context.ExecuteStoreQuery <string>("select STATIONS.NAME\n" + "from STATIONS\n" + "where STATIONS.ID={0}\n", mn).ToList(); TrainDestinations dest = new TrainDestinations(); dest.ID = h.ID; dest.start = names[0]; names = context.ExecuteStoreQuery <string>("select STATIONS.NAME\n" + "from STATIONS\n" + "where STATIONS.ID={0}\n", mx).ToList(); dest.finish = names[0]; res.Add(dest); } return(res); }
public static List <ProfitRecord> GetProfits() { RailwaysEntities context = RailwaysData.sharedContext; Dictionary <int, ProfitRecord> groups = new Dictionary <int, ProfitRecord>(); List <TICKET> tickets = context.TICKETS.ToList(); foreach (TICKET ticket in tickets) { int?id = ticket.RACE_ID; if (!groups.ContainsKey((int)id)) { ProfitRecord record = new ProfitRecord(); TrainDestinations dest = GetOneTrainDestination((int)ticket.RACE.TRAIN_ID); record.raceID = (int)id; record.trainID = (int)dest.ID; record.start = dest.start; record.finish = dest.finish; if (ticket.RACE.FORWARD == 1) { string x = record.start; record.start = record.finish; record.finish = x; } record.ticketsSold = 0; record.profit = 0; groups.Add((int)id, record); } ProfitRecord profRec = groups[(int)ticket.RACE_ID]; profRec.profit += (float)ticket.PRICE; profRec.ticketsSold++; context.SaveChanges(); } List <ProfitRecord> res = groups.Values.ToList(); res.Sort(profitRecordComparer); return(res); }