Exemplo n.º 1
0
        public IActionResult Create([FromBody] Game game)
        {
            if (game == null)
            {
                return(BadRequest());
            }

            service.Add(game);

            return(CreatedAtRoute("GetGame", new { id = game.Id }, game));
        }
Exemplo n.º 2
0
        public List <Frame> GetResult(List <Frame> frames)
        {
            foreach (var item in frames)
            {
                game.Add(item);
            }

            var computedFrames = new List <Frame>();
            var arrayOfFrame   = game.frames.OrderBy(x => x.CurrentIndex);

            foreach (var frame in arrayOfFrame)
            {
                frame.FrameScored = game.ComputeCurrentScore(frame);
                computedFrames.Add(frame);
            }
            return(computedFrames);
        }
Exemplo n.º 3
0
 private void AddGamePlayers()
 {
     _aGame.Add(new Player("Chet"));
     _aGame.Add(new Player("Pat"));
     _aGame.Add(new Player("Sue"));
 }
Exemplo n.º 4
0
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                PlatformList = new SelectList(platformdb.GetAllByName(""), "PlatformId", "Platform_name");
                return(Page());
            }

            var user = await userManager.GetUserAsync(User);

            await Task.Run(() =>
            {
                var companyId    = user.CompanyID;
                Game.CompanyID   = (int)companyId;
                Game.HtmlText    = HttpUtility.HtmlEncode(Game.HtmlText);
                Game.Price       = Math.Round(Game.Price, 2, MidpointRounding.ToEven);
                Game.ReleaseDate = DateTime.Now;
            });

            db.Add(Game);
            await db.CommitAsync();

            //PlatformOfGame
            newGamePlatform.GameId = Game.GameId;
            gamePlatformdb.Add(newGamePlatform);
            await gamePlatformdb.CommitAsync();

            //Image uploading
            if (Imgfile != null)
            {
                GamePicInfo = GamePicInfo == null ? new GamePicture() : GamePicInfo;
                //Upload to file system
                string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + Imgfile.FileName);
                string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                await Task.Run(() =>
                {
                    GamePicInfo.Path      = uniqueFileName;
                    GamePicInfo.imageType = ImageType.Icon;
                    GamePicInfo.GameId    = Game.GameId;
                });

                //Update database
                picdb.AddIcon(GamePicInfo);
                await picdb.CommitAsync();

                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    await Imgfile.CopyToAsync(fileStream);
                }
            }
            //Info images update
            if (infoImg != null)
            {
                //Remove old info image
                var oldinfo = picdb.GetById(Game.GameId, ImageType.Info);
                foreach (var r in oldinfo)
                {
                    picdb.Delete(r);
                    await picdb.CommitAsync();
                }
                foreach (var r in infoImg)
                {
                    await Task.Run(async() =>
                    {
                        string uploadsFolder  = Path.Combine(env.WebRootPath, "img");
                        string uniqueFileName = Path.Combine("g", Guid.NewGuid().ToString() + "_" + r.FileName);
                        string filePath       = Path.Combine(uploadsFolder, uniqueFileName);
                        var infoImage         = new GamePicture
                        {
                            GameId    = Game.GameId,
                            imageType = ImageType.Info,
                            Path      = uniqueFileName
                        };
                        //update database
                        picdb.Add(infoImage);
                        await picdb.CommitAsync();
                        using (var fileStream = new FileStream(filePath, FileMode.Create))
                        {
                            await r.CopyToAsync(fileStream);
                        }
                    });
                }
            }
            return(RedirectToPage("../g/Index"));
        }
 public async Task <GameViewModel> Add(GameViewModel data) => _mapper.Map <GameViewModel>(await _game.Add(_mapper.Map <Game>(data)));