Ejemplo n.º 1
0
        private async Task OnSaveRoleScoreRequest(ForwardMailMessage forwardMail, Func <MailboxMessage, Task> replyMailAction)
        {
            if (forwardMail.Id == (int)GameDBProto.MessageId.SaveRoleScoreRequestId)
            {
                var request   = GameDBProto.SaveRoleScoreRequest.Parser.ParseFrom(forwardMail.Content);
                var roleScore = await _context.GameScore.AsNoTracking().FirstOrDefaultAsync(s => s.RoleId == request.RoleId);

                if (roleScore != null)
                {
                    if (roleScore.Score < request.Score)
                    {
                        roleScore.Score     = request.Score;
                        roleScore.UpateTime = DateTime.Now;
                        await _context.SaveChangesAsync();
                    }
                }
                else
                {
                    roleScore = new GameScore {
                        RoleId = request.RoleId, Score = request.Score, CreateTime = DateTime.Now, UpateTime = DateTime.Now
                    };
                    _context.Add(roleScore);
                    await _context.SaveChangesAsync();
                }
            }
        }
Ejemplo n.º 2
0
        private void UpdateGameDb()
        {
            var gameService = new GameService.GameService(_executingDirectory);

            var gameIds = FolderUtils.GetGameIds(_executingDirectory);

            using (var db = new GameDbContext(_executingDirectory))
            {
                foreach (var existingGame in db.Games)
                {
                    db.Remove(existingGame);
                }

                foreach (var existingDisc in db.Discs)
                {
                    db.Remove(existingDisc);
                }

                db.SaveChanges();

                foreach (var id in gameIds)
                {
                    var gameInfo = gameService.GetGameInfo(id);

                    var game = new Game()
                    {
                        Id        = id,
                        Title     = gameInfo.Title,
                        Publisher = gameInfo.Publisher,
                        Year      = gameInfo.Year,
                        Players   = gameInfo.Players
                    };

                    var i = 1;

                    foreach (var discId in gameInfo.DiscIds)
                    {
                        var disc = new Disc()
                        {
                            GameId       = id,
                            DiscNumber   = i,
                            DiscBasename = discId
                        };

                        i++;

                        db.Add(disc);
                    }

                    db.Add(game);
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public bool AddGame(string name, string image, double size, decimal price, string url, string description,
                            DateTime releaseDate)
        {
            using (var db = new GameDbContext())
            {
                if (db.Games.Any(p => p.Title == name))
                {
                    return(false);
                }

                var game = new Game
                {
                    Title          = name,
                    Description    = description,
                    ImageThumbnail = image,
                    YouTubeVideoId = url,
                    Size           = size,
                    Price          = price,
                    ReleaseDate    = releaseDate
                };

                db.Add(game);
                db.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 4
0
        static string SaveSettings()
        {
            Console.Clear();

            var boardWidth   = 0;
            var boardHeight  = 0;
            var userCanceled = false;

            (boardWidth, userCanceled) = GetUserIntInput("Enter board width", 9, 20, 0);
            if (userCanceled)
            {
                return("");
            }

            (boardHeight, userCanceled) = GetUserIntInput("Enter board height", 9, 20, 0);
            if (userCanceled)
            {
                return("");
            }

            _settings.BoardHeight = boardHeight;
            _settings.BoardWidth  = boardWidth;

            _context.Add(_settings);
            _context.SaveChanges();
            return("");
        }
Ejemplo n.º 5
0
        public static async Task <GameUser> AddNewUser(GameUser newUser)
        {
            await using var dbContext = new GameDbContext();
            dbContext.Add(newUser);
            await dbContext.SaveChangesAsync().ConfigureAwait(false);

            await dbContext.GameUsers.ToListAsync().ConfigureAwait(false);

            return(newUser);
        }
Ejemplo n.º 6
0
        public async Task <bool> AddGameAppAsync(GameApp gameApp)
        {
            if (await GameAppExistsAsync(gameApp.AppId))
            {
                return(false);
            }

            dbContext.Add(gameApp);

            return(await dbContext.SaveChangesAsync() > 0);
        }
        public async Task <IActionResult> Create([FromForm] Comment comment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(Ok("Created"));
            }

            return(new BadRequestResult());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(Game game)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(game));
        }
Ejemplo n.º 9
0
        public bool AddToCart(string email, int gameId)
        {
            using (var db = new GameDbContext())
            {
                if (db.UserGames.Any(p => p.User.Email == email && p.GameId == gameId))
                {
                    return(false);
                }

                var userGame = new UserGame
                {
                    Game = db.Games.SingleOrDefault(p => p.Id == gameId),
                    User = db.Users.SingleOrDefault(p => p.Email == email)
                };

                db.Add(userGame);
                db.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 10
0
        public bool Create(string email, string name, string password)
        {
            using (var context = new GameDbContext())
            {
                if (context.Users.Any(p => p.Email == email))
                {
                    return(false);
                }

                var isAdmin = !context.Users.Any();

                var user = new User
                {
                    Email    = email,
                    FullName = name,
                    Password = password,
                    IsAdmin  = isAdmin
                };
                context.Add(user);
                context.SaveChanges();
            }

            return(true);
        }
Ejemplo n.º 11
0
 public void AddToken(RefreshToken token)
 {
     context.Add(token);
 }