예제 #1
0
        /// <summary>
        /// Create a new game
        /// </summary>
        /// <param name="playerName"></param>
        /// <param name="numberOfPlayers"></param>
        /// <returns>Game info</returns>
        public Game Create(string playerName, int numberOfPlayers)
        {
            using (IDbContextScope contextScope = _dbContextFactory.Create())
            {
                //create player
                var player = new Player()
                {
                    Name = playerName
                };

                //create game
                var game = new Game()
                {
                    NumberOfPlayers = numberOfPlayers, Status = numberOfPlayers > 1 ? 0 : 1
                };

                //add player to game
                game.Players.Add(player);

                //add game and player to database
                _gameService.Add(game);
                contextScope.SaveChanges();

                game.PlayerId = player.Id;

                return(game);
            }
        }
예제 #2
0
        private void CreateGamesFromManifest(string manifestPath)
        {
            var document  = XDocument.Load(manifestPath);
            var gameNodes = document.Descendants("game");

            if (!gameNodes.Any())
            {
                return;
            }

            foreach (var gameNode in gameNodes)
            {
                var game = new Game();
                game.Name         = gameNode.Attribute("name").Value;
                game.Description  = gameNode.Element("description").Value;
                game.CloneOf      = gameNode.Element("cloneof").Value;
                game.Crc          = gameNode.Element("crc").Value;
                game.Manufacturer = gameNode.Element("manufacturer").Value;
                game.Year         = int.Parse(gameNode.Element("year").Value);
                game.Genre        = gameNode.Element("genre").Value;
                game.Rating       = gameNode.Element("rating").Value;
                game.Enabled      = bool.Parse(gameNode.Element("enabled").Value);

                _gameService.Add(game);
            }
        }
예제 #3
0
파일: Summon.cs 프로젝트: Robrownn/TigerBot
        public async Task AddGame(SocketGuildUser user, [Remainder] string gameName)
        {
            // Create new user and new game
            var newGame = CreateNewGame(gameName);
            var newUser = CreateNewUser(user.Mention);

            // Check user table for the specified user. Insert if not exist
            if (!CheckUserExists(newUser))
            {
                _users.Add(newUser);
            }
            // Check game table if the game already exists. Insert if not exist
            if (!CheckGameExists(newGame))
            {
                _games.Add(newGame);
            }

            // Insert combo into usergame table
            if (!CheckUserGameExists(newGame, newUser))
            {
                _userGames.Add(newUser, newGame);
            }

            await ReplyAsync($"`{gameName}` successfully added to {user.Mention}'s game list!");
        }
예제 #4
0
        public IActionResult Post([FromBody] GameCreateViewModel gameCreateViewModel)
        {
            gameCreateViewModel.UserId = Convert.ToInt32(User.Identity.Name);
            _gameService.Add(gameCreateViewModel);

            return(StatusCode(StatusCodes.Status200OK));
        }
예제 #5
0
        public async Task <ImportResponse> ImportGamesAsync(GameImportRequest request)
        {
            ImportResponse response = await CheckRequest(request.UserID, request.Games.Count);

            if (!response.Successful)
            {
                return(response);
            }

            var user = await _userManager.FindByIdAsync(request.UserID);

            foreach (var game in request.Games)
            {
                try
                {
                    game.UserID  = request.UserID;
                    game.UserNum = user.UserNum;
                    game.ID      = 0;
                    _gameService.Add(game);
                    response.Imported++;
                }
                catch (Exception ex)
                {
                    response.Failed++;
                    response.Message += $"{game.Title} - {ex.Message} : {ex.InnerException?.Message}";
                }
            }

            response.Successful = true;

            return(response);
        }
예제 #6
0
        public async Task <IActionResult> AddGame(GameDTO model, int[] categoryIds, IFormFile file)
        {
            if (ModelState.IsValid == true)
            {
                var entity = new Game()
                {
                    Name        = model.Name,
                    Description = model.Description,
                    Price       = model.Price,
                };

                if (file != null)
                {
                    var randomName = Guid.NewGuid().ToString();
                    var path       = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\img", randomName + ".jpg");
                    entity.Image = randomName + ".jpg";
                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        await file.CopyToAsync(stream);
                    }
                }
                else
                {
                    entity.Image = model.Image;
                }

                _gameService.Add(entity, categoryIds);

                return(RedirectToAction("GameList"));
            }
            ViewBag.Categories = _categoryService.GetAll();
            return(View(model));
        }
예제 #7
0
        public async Task <ActionResult <Result> > Add(GameDto gameDto)
        {
            var loginId = await GetLoginId();

            var result = await _gameService.Add(gameDto, loginId);

            return(Ok(result));
        }
예제 #8
0
        public IActionResult Add(Game game)
        {
            var result = _gameService.Add(game);

            if (result.Success)
            {
                return(Ok(result));
            }
            return(BadRequest(result));
        }
예제 #9
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,GameTypeId")] GameAddOrEditDTO game)
        {
            if (ModelState.IsValid)
            {
                _gameService.Add(game);
                return(RedirectToAction("Index"));
            }

            ViewBag.GameTypeId = new SelectList(_gameService.GetGameTypes(), "Id", "Title", game.GameTypeId);
            return(View(game));
        }
예제 #10
0
        public IHttpActionResult Games(GameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            model.UserId = GetUserID();
            var game = _gameService.Add(MapGameViewModelToDTO(model));

            return(Ok(Mapper.Map <GameViewModel>(game)));
        }
예제 #11
0
        public HttpResponseMessage AddGameDetails(ResultDto result)
        {
            _gameService.Add(result.Winner, result.Loser);

            var response = new HttpResponseMessage
            {
                StatusCode = HttpStatusCode.Created,
                Content    = new StringContent(string.Format("Game registered, winner {0}, loser {1}", result.Winner, result.Loser))
            };

            return(response);
        }
예제 #12
0
        public HttpResponseMessage Post(GameAddUpdateViewModel gameAddUpdateViewModel)
        {
            GameLocalizationViewModel englishLocalization = GetLocalization(gameAddUpdateViewModel, "en");

            if (IsLocalizationEmpty(englishLocalization))
            {
                ModelState.AddModelError("localizationError", GlobalRes.EnglishLocalizationShouldExist);
            }

            if (ModelState.IsValid)
            {
                CleanEmptyLocalizations(gameAddUpdateViewModel);

                var gameModel = Mapper.Map <GameModel>(gameAddUpdateViewModel);
                _gameService.Add(gameModel);

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
        }
예제 #13
0
        public ActionResult Save(Game game)
        {
            if (game.Id == 0)   // id 0 gelirse yeni kayıttır ekleme yapar
            {
                _gameService.Add(game);
            }
            else
            {
                _gameService.Update(game); // id varolan bir id ise update yapar
            }

            return(RedirectToAction("Index", "Category"));
        }
예제 #14
0
        public IHttpActionResult Post(GameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Content(HttpStatusCode.BadRequest, CreateError()));
            }

            var game = _mapper.Map <GameViewModel, Game>(model);

            _gameService.Add(game, CurrentLanguage);

            return(Ok());
        }
예제 #15
0
        public ActionResult Add(GameFormViewModel viewModel)
        {
            _gameService.AddTags(viewModel.Game, viewModel.selectedTagsId);
            _gameService.AddLanguages(viewModel.Game, viewModel.selectedLanguagesId);

            if (ModelState.IsValid)
            {
                _gameService.Add(viewModel.Game);
                return(RedirectToAction("Manage"));
            }
            var newViewModel = GetFullGameForm(null);

            newViewModel.Game = viewModel.Game;
            return(View(newViewModel));
        }
예제 #16
0
        public ActionResult GetCommentsForGame(string gameKey)
        {
            if (gameKey != null)
            {
                var game = _gameService.GetItemByKey(gameKey, CurrentLanguageCode);
                // If user come with direct link to game's comments then copy game to the sql databse if necessary
                if (game.IsSqlEntity == false)
                {
                    _gameService.Add(game, CurrentLanguageCode);
                }

                return(View(InitComments(gameKey)));
            }

            throw new ArgumentException("The game was not specified!!!");
        }
예제 #17
0
        public ActionResult AddGame(GameViewModel gameViewModel)
        {
            if (ModelState.IsValid)
            {
                var game = _mapper.Map <GameViewModel, Game>(gameViewModel);
                _gameService.Add(game, CurrentLanguageCode);

                return(RedirectToAction("games"));
            }

            gameViewModel.Genres        = _mapper.Map <IEnumerable <Genre>, IList <GenreViewModel> >(_genreService.GetAllGenresAndMarkSelected(gameViewModel.NameGenres, CurrentLanguageCode));
            gameViewModel.PlatformTypes = _mapper.Map <IEnumerable <PlatformType>, IList <PlatformTypeViewModel> >(_platformTypeService.GetAllPlatformTypesAndMarkSelected(gameViewModel.NamePlatformtypes, CurrentLanguageCode));
            gameViewModel.Publishers    = _mapper.Map <IEnumerable <Publisher>, IList <PublisherViewModel> >(_publisherService.Get(CurrentLanguageCode));

            return(View(gameViewModel));
        }
예제 #18
0
        private async Task AddGameToGameTable(SocketGuildUser game)
        {
            try
            {
                var newGame = new TigerGame
                {
                    GameName = game.Game.ToString()
                };
                _games.Add(newGame);

                await Log(CreateLogMessage(LogSeverity.Info, "Add game to game table", $"Added {newGame.GameName}"));
            }
            catch (Exception ex)
            {
                await Log(CreateLogMessage(LogSeverity.Critical, $"{ex.Source}", $"Exception: {ex.Message}"));
            }
        }
예제 #19
0
        private static bool CreateGame(Data.System system, XElement gameElement)
        {
            var gameName = gameElement.Attribute("name")?.Value;

            if (GameService.Exists(gameName))
            {
                return(false);
            }

            Console.WriteLine($"Importing {gameName}");

            var genre        = gameElement.Element("genre")?.Value;
            var manufacturer = gameElement.Element("manufacturer")?.Value;
            var rating       = gameElement.Element("rating")?.Value;

            var game = new Game
            {
                Name         = gameName,
                Description  = gameElement.Element("description")?.Value,
                Crc          = gameElement.Element("crc")?.Value,
                Manufacturer = manufacturer,
                Genre        = genre,
                Rating       = gameElement.Element("rating")?.Value,
                CloneOf      = gameElement.Element("cloneof")?.Value,
                Enabled      = gameElement.Element("enabled")?.Value.ToUpper() == "YES",
                System       = system
            };

            int year;

            if (int.TryParse(gameElement.Element("year")?.Value, out year))
            {
                game.Year = year;
                AddTag(game, year.ToString());
            }

            AddTag(game, system.Name);
            AddTag(game, genre);
            AddTag(game, manufacturer);
            AddTag(game, rating);

            GameService.Add(game);
            return(true);
        }
예제 #20
0
        public async Task <IActionResult> Post([FromBody] GameRequest gameRequest)
        {
            var tenantId = this.GetTenantId();

            var game = await _gameService.CreateGame(
                tenantId,
                gameRequest.PlayerOneId,
                gameRequest.PlayerTwoId,
                gameRequest.MatchDayId);

            game = await _gameService.Add(game);

            var gameResponse = _mapper.Map <GameResponse>(game);

            return(CreatedAtAction(
                       nameof(GetById),
                       new { id = game.Id },
                       gameResponse));
        }
예제 #21
0
        public ActionResult Create(GameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }

            try
            {
                var game = Mapper.Map <Game>(model);
                _gameSvc.Add(game);
                TempData["SuccessMessage"] = "New fantasy game has been successfully added";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View("Create", model));
        }
예제 #22
0
        public async Task <IActionResult> Novo(GameViewModel gameViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(gameViewModel));
                }

                gameViewModel.Disponivel = true;
                await _gameService.Add(gameViewModel);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception)
            {
                TratarErro();
            }

            return(View());
        }
예제 #23
0
        public ActionResult Create([FromBody] Game game)
        {
            Game gameResult;

            try
            {
                if (game != null)
                {
                    gameResult = _service.Add(game);
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception e)
            {
                return(StatusCode(500, e));
            }

            return(Ok(gameResult));
        }
예제 #24
0
        public ActionResult AddGame(GameAddUpdateViewModel gameAddUpdateViewModel)
        {
            GameLocalizationViewModel englishLocalization = GetLocalization(gameAddUpdateViewModel, "en");

            if (IsLocalizationEmpty(englishLocalization))
            {
                ModelState.AddModelError("localizationError", GlobalRes.EnglishLocalizationShouldExist);
            }

            if (ModelState.IsValid)
            {
                CleanEmptyLocalizations(gameAddUpdateViewModel);

                var gameModel = Mapper.Map <GameModel>(gameAddUpdateViewModel);
                _gameService.Add(gameModel);

                MessageSuccess("The game has been added successfully!");
                return(RedirectToAction("Get"));
            }

            AdjustCollections(gameAddUpdateViewModel);

            return(View(gameAddUpdateViewModel));
        }
예제 #25
0
        public async Task <ActionResult <GameDto> > Add([FromBody] GameDto game)
        {
            var addedGame = await _gameService.Add(game);

            return(Created(addedGame.Id.ToString(), addedGame));
        }
예제 #26
0
 public void Add(GameCommand obj)
 {
     _gameService.Add(_gameMap.MapToEntity(obj));
 }
예제 #27
0
 public IActionResult Post([FromBody] GameModel model)
 {
     _gameService.Add(model);
     return(Ok());
 }
        public async Task <IActionResult> CreateAsync([Bind("Id,GameType,GameName,GameDescription,LoginRule,LoginWithFacbook,LoginWithGoogle,LoginWithTwitter,Logo,Banner,CSSSkin,PrivacyAndGameConditions,EnableAnonymous,GameSlotType,EnableTimer,TimerMaxPerQuestion,DisplayScore")] GameViewModel model)
        {
            if (ModelState.IsValid || model.Id > 0)
            {
                try
                {
                    if (model.GameType == (int)Game.GameTypeEnum.Slot && model.GameSlotType == 0)
                    {
                        ModelState.AddModelError("GameSlotType", "must select 1 field");
                        return(View("Create", model));
                    }

                    if (model.LoginRule == (int)Game.LoginRuleTypeEnum.SocialMediaLogin && !(model.LoginWithFacbook || model.LoginWithGoogle || model.LoginWithTwitter))
                    {
                        ModelState.AddModelError("LoginRule", "must check 1 field for socialmedia login");
                        return(View("Create", model));
                    }
                    _gameService.BeginTransaction();
                    var game = _gameService.Get(x => x.Id == model.Id);
                    if (game != null)
                    {
                        game.DisplayScore             = model.DisplayScore;
                        game.EnableAnonymous          = model.EnableAnonymous;
                        game.EnableTimer              = model.EnableTimer;
                        game.GameDescription          = model.GameDescription;
                        game.GameName                 = model.GameName;
                        game.GameSlotType             = model.GameSlotType;
                        game.GameType                 = model.GameType;
                        game.LoginRule                = model.LoginRule;
                        game.LoginWithFacbook         = model.LoginWithFacbook;
                        game.LoginWithGoogle          = model.LoginWithGoogle;
                        game.LoginWithTwitter         = model.LoginWithTwitter;
                        game.PrivacyAndGameConditions = model.PrivacyAndGameConditions;
                        game.TimerMaxPerQuestion      = model.TimerMaxPerQuestion;
                        game.GameSlotsCount           = model.GameSlotsCount;

                        if (model.Banner != null)
                        {
                            game.Banner = helper.GetFileName(model.Banner);
                            await helper.FileUploadAsync(model.Banner, game.Banner, "Game");
                        }
                        if (model.Logo != null)
                        {
                            game.Logo = helper.GetFileName(model.Logo);
                            await helper.FileUploadAsync(model.Logo, game.Logo, "Game");
                        }
                        if (model.CSSSkin != null)
                        {
                            game.CSSSkin = helper.GetFileName(model.CSSSkin);
                            await helper.FileUploadAsync(model.CSSSkin, game.CSSSkin, "Game");
                        }
                        _gameService.Update(game);
                    }
                    else if (ModelState.IsValid)
                    {
                        var newGame = helper.GetGame(model);
                        model.Id = _gameService.Add(newGame);
                        await helper.FileUploadAsync(model.Banner, newGame.Banner, "Game");

                        await helper.FileUploadAsync(model.Logo, newGame.Logo, "Game");

                        await helper.FileUploadAsync(model.CSSSkin, newGame.CSSSkin, "Game");
                    }
                    _gameService.CommitTransaction();
                    if (model.GameType == (int)Game.GameTypeEnum.Slot)
                    {
                        return(Redirect($"~/BackOffice/Offer/Index?GameId={model.Id}"));
                    }
                    else
                    {
                        return(Redirect($"~/BackOffice/QuizCategory/Index?id={model.Id}"));
                    }
                }
                catch (Exception ex)
                {
                    _gameService.RollbackTransaction();
                }
            }
            return(View(model));
        }
 public IActionResult Add(GameFormViewModel model)
 {
     _logger.LogInformation("Started method Add");
     _gameService.Add(model);
     return(Ok());
 }
예제 #30
0
 public void Add(GameDTO obj)
 {
     _gameService.Add(_gameMapper.MapperToEntity(obj));
 }