示例#1
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                Title          = model.Title,
                ReleaseDate    = model.ReleaseDate,
                Genre          = model.Genre,
                FirstSubgenre  = model.FirstSubgenre,
                SecondSubgenre = model.SecondSubgenre,
                ThirdSubgenre  = model.ThirdSubgenre,
                Rating         = model.Rating
            };

            using (var ctx = new ApplicationDbContext())
            {
                var dev = ctx.Developers.Single(d => d.DeveloperName == model.DeveloperName);
                if (dev is null)
                {
                    dev = new Developer
                    {
                        DeveloperName = model.DeveloperName,
                        Region        = Region.Unknown,
                        IsActive      = true,
                        IsMajor       = false
                    };
                    ctx.Developers.Add(dev);
                }

                entity.DeveloperID = dev.DeveloperID;
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#2
0
        public IActionResult Create([FromBody] GameCreate game)
        {
            var newGame = _mapper.Map <Game>(game);

            var createdGame = GameRepository.Create(newGame);

            _unitOfWork.SaveChanges();

            return(Created("", _mapper.Map <GameView>(createdGame)));
        }
示例#3
0
 public ActionResult Create(GameCreate gameCreate)
 {
     if (ModelState.IsValid)
     {
         _db.GameCreates.Add(gameCreate);
         _db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(gameCreate));
 }
示例#4
0
        public bool CreateGame(GameCreate model)
        {
            var entity = new Game();

            if (model.GameType == Data.Games.GameType.BoardGame)
            {
                entity = new BoardGame()
                {
                    //General Game properties
                    UserId          = _userId,
                    GameTitle       = model.GameTitle,
                    GameDescription = model.GameDescription,
                    AveragePlaytime = model.AveragePlaytime,
                    MinGamePlayers  = model.MinGamePlayers,
                    MaxGamePlayers  = model.MaxGamePlayers,
                    GameType        = model.GameType,

                    //Board Game specific properties
                    BoardGameGenre = model.BoardGameGenre,
                    Category       = model.Category,
                    BGPublisher    = model.BGPublisher,
                    IsDiceGame     = model.IsDiceGame,
                    IsCardGame     = model.IsCardGame
                };
            }
            else
            {
                entity = new VideoGame()
                {
                    //General Game properties
                    UserId          = _userId,
                    GameTitle       = model.GameTitle,
                    GameDescription = model.GameDescription,
                    AveragePlaytime = model.AveragePlaytime,
                    MinGamePlayers  = model.MinGamePlayers,
                    MaxGamePlayers  = model.MaxGamePlayers,
                    GameType        = model.GameType,

                    //Video Game specific properties
                    LocalCoop      = model.LocalCoop,
                    VideoGameGenre = model.VideoGameGenre,
                    ESRBRating     = model.ESRBRating,
                    VGPublisher    = model.VGPublisher,
                    Console        = model.Console
                };
            }

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
示例#5
0
        public async Task <GameCreated> SaveNewGame(GameCreate model)
        {
            var entity = mapper.Map <Data.Entities.Game>(model);

            entity.CreationDate = timeProvider.GetCurrentTime();

            using (var connection = connectionFactory.CreateConnection())
            {
                var game = await connection.QueryFirstAsync <GameCreated>(CreationQueries.CreateGameQuery, entity);

                return(game);
            }
        }
        public IHttpActionResult Post(GameCreate game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var service = CreateGameService();

            if (!service.CreateGame(game))
            {
                return(InternalServerError());
            }
            return(Ok());
        }
示例#7
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new GameService(userId);

            service.CreateGame(model);

            return(RedirectToAction("Index"));
        }
示例#8
0
        public bool CreateGame(GameCreate Model)
        {
            var entity =
                new Games()
            {
                DateOfGame = Model.DateOfGame,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateGame(GameCreate model)
        {
            var entity = new Game()
            {
                OwnerId      = _userID,
                GameTitle    = model.GameTitle,
                PlatformType = model.PlatformType,
                CategoryType = model.CategoryType,
                RatingType   = model.RatingType,
                Price        = model.Price
            };

            _db.Games.Add(entity);
            return(_db.SaveChanges() == 1);
        }
示例#10
0
        public void MapFromCreate()
        {
            var newGame = new GameCreate
            {
                Name       = "Pudim",
                ReleasedOn = DateTime.Now
            };

            var mappedGame = _mapper.Map <Game>(newGame);

            mappedGame.Should()
            .NotBeNull("a result is expected").And
            .BeOfType <Game>("it should be a Game class").And
            .BeEquivalentTo(newGame, "its properties should be the same as the original object");
        }
示例#11
0
        public async Task <GameCreateResult> CreateGame(GameCreate game)
        {
            await validator.ValidateGame(game);

            var createdGame = await gameRepository.SaveNewGame(game);

            var teamsToCreate = await gameTeamsGenerator.GenerateTeams(createdGame.Id, game.Teams);

            await CreateGameData(createdGame, teamsToCreate);

            return(new GameCreateResult()
            {
                GameId = createdGame.Id
            });
        }
示例#12
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Games()
            {
                GameID   = _gameID,
                GameName = model.GameName,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#13
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateGameService();

            if (service.CreateGame(model))
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
示例#14
0
        public bool CreateGame(GameCreate model)
        {
            var entity = new GameEntity
            {
                DateOfGame  = model.DateOfGame,
                StadiumID   = model.StadiumID,
                HomeTeamID  = model.HomeTeamID,
                AwayTeamID  = model.AwayTeamID,
                HomeTeamWon = model.HomeTeamWon,
                OwnerID     = _userID
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                if (ctx.SaveChanges() != 1)
                {
                    return(false);
                }

                var createdGame = ctx.Games.FirstOrDefault(g =>
                                                           g.OwnerID == _userID &&
                                                           g.StadiumID == model.StadiumID &&
                                                           g.HomeTeamID == model.HomeTeamID &&
                                                           g.AwayTeamID == model.AwayTeamID &&
                                                           g.DateOfGame == model.DateOfGame &&
                                                           g.HomeTeamWon == model.HomeTeamWon);

                if (createdGame == null)
                {
                    return(false);
                }

                foreach (var visitor in model.Visitors)
                {
                    ctx.Visits.Add(new VisitEntity
                    {
                        OwnerID   = _userID,
                        GameID    = createdGame.GameID,
                        GotPin    = visitor.GotPin,
                        TookPhoto = visitor.TookPhoto,
                        VisitorID = visitor.VisitorID
                    });
                }

                return(ctx.SaveChanges() == model.Visitors.Count());
            }
        }
示例#15
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                GameName    = model.GameName,
                Description = model.Description,
                ReleaseDate = model.ReleaseDate
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#16
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            //var service = new GameService();

            if (_gameService.CreateGame(model))
            {
                TempData["SaveResult"] = "Your game was added.";
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Game could not be added.");
            return(View(model));
        }
示例#17
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                GameName   = model.GameName,
                TypeOfGame = model.TypeOfGame,
                MinBet     = model.MinBet,
                MaxBet     = model.MaxBet
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#18
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                OwnerId     = _gameId,
                Title       = model.Title,
                Genre       = model.Genre,
                PlayerCount = model.PlayerCount
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#19
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Could not add game, please make sure all fields are filled");
                return(View(model));
            }

            GameService service = new GameService();

            if (service.CreateGame(model))
            {
                TempData["SaveResult"] = $"{model.Title} was added successfully!";
                return(RedirectToAction("AllGames"));
            }

            return(View(model));
        }
示例#20
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var svc = CreateGameService();

            if (svc.CreateGame(model))
            {
                TempData["SaveResult"] = "Game successfully added to database.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "An error occurred while attempting to add the game to the database - changes not saved.");
            return(View(model));
        }
示例#21
0
        public IActionResult Save(SaveGame request)
        {
            var game = new GameCreate()
            {
                BrandId     = request.BrandId,
                Description = request.Description,
                GameId      = request.GameId,
                GameName    = request.GameName,
                UserId      = request.UserId
            };

            game.Categorys = string.Join(",", request.Categorys);

            game.Images = saveImg(request.Images, game.GameId);
            var result = ApiHelper <GameResult> .HttpPostAsync($"game/save", "POST", game);

            return(RedirectToAction("index", "Game"));
        }
示例#22
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateGameService();

            if (service.CreateGame(model))
            {
                TempData["SaveResult"] = "The game was created.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Game could not be created.");
            return(View(model));
        }
示例#23
0
        public ActionResult Create(GameCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            var service = CreateGameService();

            if (service.CreateGame(model))
            {
                TempData["SaveResult"] = "Your game was created.";

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
示例#24
0
        public async Task ValidateGame(GameCreate gameModel)
        {
            if (gameModel == null)
            {
                throw new ValidationFailedException("No data to create the game");
            }

            if (gameModel.TeamCount != gameModel.Teams.Count())
            {
                throw new ValidationFailedException("Wrong team count");
            }

            if (gameModel.BoardHeight < 5 || gameModel.BoardWidth < 5 ||
                gameModel.BoardHeight > 8 || gameModel.BoardWidth > 8)
            {
                throw new ValidationFailedException("Wrong board size");
            }

            if (gameModel.UserId <= 0)
            {
                throw new ValidationFailedException("Game must be assigned to user");
            }

            if (gameModel.LanguageId <= 0)
            {
                throw new ValidationFailedException("Game must have selected language");
            }

            if (string.IsNullOrEmpty(gameModel.Name))
            {
                throw new ValidationFailedException("Game must have a name");
            }

            if (gameModel.Teams == null || !gameModel.Teams.Any())
            {
                throw new ValidationFailedException("Game must have teams");
            }

            if ((gameModel.Teams.Sum(x => x.FieldCount) + gameModel.TrapCount) > (gameModel.BoardHeight * gameModel.BoardWidth))
            {
                throw new ValidationFailedException("Team and trap fields count exceeeded total number of fields");
            }
        }
示例#25
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                GameID        = model.GameID,
                GameName      = model.GameName,
                Games         = model.Games,
                CreatedUtc    = DateTimeOffset.Now,
                JoiningTables = model.JoiningTables,
                GenreType     = model.Genres
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                OwnerId       = _userId,
                Name          = model.Name,
                Description   = model.Description,
                OwnerUserName = Thread.CurrentPrincipal.Identity.GetUserName(),
                GenreTags     = model.GenreTags,
                Price         = model.Price
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#27
0
        public bool CreateGame(GameCreate model)
        {
            Game newGame = new Game()
            {
                Title             = model.Title,
                Description       = model.Description,
                PosterUrl         = model.PosterUrl,
                ReleaseDate       = model.ReleaseDate,
                Genre             = model.Genre,
                DevStudio         = model.DevStudio,
                AnticipationValue = model.AnticipationValue,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(newGame);
                return(ctx.SaveChanges() == 1);
            }
        }
示例#28
0
        public IHttpActionResult Post(GameCreate game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (game.GameRating >= 0 && game.GameRating <= 10)
            {
                if (!gameServices.CreateGame(game))
                {
                    return(InternalServerError());
                }

                return(Ok());
            }

            return(BadRequest());
        }
示例#29
0
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new Game()
            {
                OwnerId     = _userId,
                Name        = model.Name,
                CategoryId  = model.CategoryId,
                Developer   = model.Developer,
                ReleaseYear = model.ReleaseYear,
                CreatedUtc  = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Games.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public bool CreateGame(GameCreate model)
        {
            var entity =
                new VideoGames()
            {
                OwnerId     = _userId,
                GameTitle   = model.GameTitle,
                Console     = model.Console,
                GenreType   = model.GenreType,
                Price       = model.Price,
                ReleaseYear = model.ReleaseYear,
                CreatedUtc  = DateTimeOffset.Now,
                Quantity    = model.Quantity
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.VideoGame.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }