コード例 #1
0
        static void Main(string[] args)
        {
            using (TicketDbContext ctx = new TicketDbContext())
            {
                ctx.Venues.Select(x => x.Name).ToConsole("VENUES");
                string[] sectors = ctx.Sectors.Select(x => x.Code).ToArray();
                sectors.ToConsole("SECTORS");
                string[] sellers = ctx.Sellers.Select(x => x.Name).ToArray();
                sellers.ToConsole("SELLERS");

                DailySaleGenerator gen = new DailySaleGenerator(sellers, sectors);
                var list = gen.GenerateSales(10, 600, 10);
                list.ToConsole("LIST");

                var xdoc = XmlGenerator.GenerateXML(list);

                Console.WriteLine(xdoc);

                var perseller = from sellerNode in xdoc.Descendants("seller")
                                group sellerNode by sellerNode.Attribute("name").Value into grp
                                orderby grp.Key
                                select new
                {
                    Seller    = grp.Key,
                    TotalSold = grp.Sum(x => (int)x.Element("sold"))
                };

                perseller.ToConsole("PER SELLER");

                var perSector = from sectornode in xdoc.Descendants("sector")
                                group sectornode by sectornode.Attribute("code").Value into grp
                                orderby grp.Key
                                select new
                {
                    Sector    = grp.Key,
                    TotalSold = grp.Sum(x => (int)x.Element("sold"))
                };

                perSector.ToConsole("PER SECTOR");

                var remainingSeats = ctx.Sectors.ToList().Select(sector => new
                {
                    Total     = sector.Capacity,
                    Remaining = sector.Capacity - perSector.SingleOrDefault(stat => stat.Sector == sector.Code)?.TotalSold ?? 0
                });

                remainingSeats.ToConsole("REMAING SEATS");

                var errors = from seat in remainingSeats
                             where seat.Remaining < 0
                             select seat;

                Console.WriteLine($"errors : {errors.Count()}");
                errors.ToConsole("ERRO SALES");
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Cernyr/TicketSales
        static void Main(string[] args)
        {
            using (TicketDbContext ctx = new TicketDbContext())
            {
                ctx.Venues.Select(x => x.Name).ToConsole("VENUES");
                string[] sectors = ctx.Sectors.Select(x => x.Code).ToArray();
                sectors.ToConsole("SECTORS");
                string[] sellers = ctx.Sellers.Select(x => x.Name).ToArray();
                sellers.ToConsole("SELLERS");

                DailySaleGenerator gen = new DailySaleGenerator(sellers, sectors);
                var list = gen.GenerateSales(10, 6, 10);
                list.ToConsole("LIST");

                var xdoc = XmlGenerator.GenerateXML(list);
            }
        }