public static int GetMinDuration()
 {
     using (var db = new GameStoreDB())
     {
         return((from game in db.Game select game.Min_Duration).Min());
     }
 }
Пример #2
0
        public static List <GamesToReportViewModel> PrepareGamesToReport(GameStoreDB db, DateTime dateFrom, DateTime dateTo)
        {
            var gamesToReport = new List <GamesToReportViewModel>();
            var games         = new List <Game>();
            var actualDateTo  = dateTo.AddDays(1);
            var orders        = (from order in db.Order
                                 where order.Date >= dateFrom &&
                                 order.Date <= actualDateTo
                                 select order).ToList();

            foreach (var order in orders)
            {
                foreach (var game in order.Game)
                {
                    games.Add(game);
                }
            }
            var groupedGames = from game in games group games by game.Name;

            foreach (var game in groupedGames)
            {
                gamesToReport.Add(new GamesToReportViewModel()
                {
                    Name     = game.Key,
                    Quantity = game.Count(),
                    Price    = game.First().First().Price,
                    Total    = game.First().First().Price *game.Count()
                });
            }
            return(gamesToReport);
        }
 public static double GetMaxPrice()
 {
     using (var db = new GameStoreDB())
     {
         return((from game in db.Game select game.Price).Max());
     }
 }
 public static int GetMaxPlayers()
 {
     using (var db = new GameStoreDB())
     {
         return((from game in db.Game select game.Max_Players).Max());
     }
 }
 public static void RemoveAllEntites()
 {
     using (var db = new GameStoreDB())
     {
         foreach (var entity in db.Order)
         {
             db.Order.Remove(entity);
         }
         foreach (var entity in db.Genre)
         {
             db.Genre.Remove(entity);
         }
         foreach (var entity in db.Type)
         {
             db.Type.Remove(entity);
         }
         foreach (var entity in db.Manufacturer)
         {
             db.Manufacturer.Remove(entity);
         }
         foreach (var entity in db.Author)
         {
             db.Author.Remove(entity);
         }
         foreach (var entity in db.Client)
         {
             db.Client.Remove(entity);
         }
         foreach (var entity in db.Review)
         {
             db.Review.Remove(entity);
         }
         foreach (var entity in db.Game)
         {
             db.Game.Remove(entity);
         }
         try
         {
             db.SaveChanges();
         }
         catch (DbEntityValidationException e)
         {
             foreach (var eve in e.EntityValidationErrors)
             {
                 Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                   eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                       ve.PropertyName, ve.ErrorMessage);
                 }
             }
         }
     }
 }
        public static List <Game> GetGamesParamsWithFilter(GameStoreDB db, string startsWith,
                                                           double minPrice, double maxPrice,
                                                           int minDuration, int maxDuration,
                                                           int minDifficulty, int maxDifficulty,
                                                           int minPlayers, int maxPlayers,
                                                           string genre, string type)
        {
            var selectedGames = from game in db.Game
                                where
                                maxPrice >= game.Price &&
                                minPrice <= game.Price &&
                                minDuration <= game.Min_Duration &&
                                maxDuration >= game.Max_Duration &&
                                minDifficulty <= game.Difficulty &&
                                maxDifficulty >= game.Difficulty &&
                                minPlayers <= game.Min_Players &&
                                maxPlayers >= game.Max_Players
                                select game;

            if (genre != null)
            {
                selectedGames = from game in selectedGames
                                where game.Genre.Name == genre
                                select game;
            }
            if (type != null)
            {
                selectedGames = from game in selectedGames
                                where game.Type.Name == type
                                select game;
            }
            if (startsWith != string.Empty)
            {
                selectedGames = from game in selectedGames
                                where game.Name.StartsWith(startsWith)
                                select game;
            }
            return(selectedGames.ToList <Game>());
        }
        public static void InitializeDB()
        {
            using (var db = new GameStoreDB())
            {
                var genreCard = new Genre
                {
                    Name        = "Карточная игра",
                    Description = "Игроки используют карточки"
                };
                var genreRole = new Genre
                {
                    Name        = "Ролевая игра",
                    Description = "Игроки исполняют роль персонажа"
                };
                var manufacturerHB = new Manufacturer
                {
                    Name   = "Hobby World",
                    Adress = "Москва"
                };
                var authorSomeone = new Author
                {
                    Name   = "Неизвестный автор",
                    Adress = "Неизвестно"
                };
                var typeCompetetive = new Type
                {
                    Name        = "Соревновательная игра",
                    Description = "Игроки соревнуются друг с другом ради победы"
                };
                var typeCooperative = new Type
                {
                    Name        = "Кооперативная игра",
                    Description = "Игроки объединяются для достижения общей цели"
                };
                var clientIvan = new Client
                {
                    Name  = "Иванов Иван Иванович",
                    Email = "[email protected]"
                };
                var clientPetr = new Client
                {
                    Name  = "Петров Петр Петрович",
                    Email = "[email protected]"
                };
                var order1 = new Order
                {
                    Date = DateTime.Now
                };
                var order2 = new Order
                {
                    Date = DateTime.Now
                };
                var imageConverter = new ImageConverter();
                var game1          = new Game
                {
                    Description  = "Дикий запад!",
                    Name         = "Бэнг!",
                    Manufacturer = manufacturerHB,
                    Author       = authorSomeone,
                    Genre        = genreCard,
                    Difficulty   = 1,
                    Type         = typeCompetetive,
                    Min_Duration = 15,
                    Max_Duration = 60,
                    Min_Players  = 2,
                    Max_Players  = 10,
                    Quantity     = 5,
                    Price        = 990.99,
                    //Image = (byte[])imageConverter.ConvertTo(.resources.Bang, typeof(byte[]))
                };
                var game2 = new Game
                {
                    Description  = "Война гномов!",
                    Name         = "Манчкин",
                    Manufacturer = manufacturerHB,
                    Author       = authorSomeone,
                    Genre        = genreRole,
                    Difficulty   = 2,
                    Type         = typeCooperative,
                    Min_Duration = 5,
                    Max_Duration = 180,
                    Min_Players  = 3,
                    Max_Players  = 10,
                    Quantity     = 10,
                    Price        = 1990.99,
                    //Image = (byte[])imageConverter.ConvertTo(GameStoreAppCF.Properties.resources.Munchkin, typeof(byte[]))
                };
                order1.Client = clientIvan;
                order1.Game.Add(game1);
                order2.Client = clientPetr;
                order2.Game.Add(game2);

                db.Game.Add(game1);
                db.Game.Add(game2);
                db.Genre.Add(genreCard);
                db.Genre.Add(genreRole);
                db.Author.Add(authorSomeone);
                db.Manufacturer.Add(manufacturerHB);
                db.Type.Add(typeCompetetive);
                db.Type.Add(typeCooperative);
                db.Client.Add(clientIvan);
                db.Client.Add(clientPetr);
                db.Order.Add(order1);
                db.Order.Add(order2);
                try
                {
                    db.SaveChanges();
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                }
            }
        }