示例#1
0
        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);
        }
示例#2
0
 //comparer
 private static int profitRecordComparer(ProfitRecord a, ProfitRecord b)
 {
     return(a.raceID - b.raceID);
 }