Ejemplo n.º 1
0
        public Guid EndGame(Guid gameId, Guid winnerId)
        {
            var id = Guid.NewGuid();

            using (var db = new SpeedCheckers.DAL.SpeedCheckersContext())
            {
                var game = db.Games.First(x => x.ID == gameId);
                game.EndTime  = DateTime.Now;
                game.WinnerId = winnerId;
                db.SaveChanges();
            }
            return(id);
        }
Ejemplo n.º 2
0
        public Guid CreateUser(string name)
        {
            var id = Guid.NewGuid();

            using (var db = new SpeedCheckers.DAL.SpeedCheckersContext())
            {
                db.Users.Add(new Models.User
                {
                    ID   = id,
                    Name = name
                });
                db.SaveChanges();
            }
            return(id);
        }
Ejemplo n.º 3
0
 public Guid StartGame(Guid id, Guid playerWhite, Guid playerBlack)
 {
     using (var db = new SpeedCheckers.DAL.SpeedCheckersContext())
     {
         db.Games.Add(new Models.Game
         {
             ID            = id,
             StartTime     = DateTime.Now,
             PlayerWhiteId = playerWhite,
             PlayerBlackId = playerBlack,
         });
         db.SaveChanges();
     }
     return(id);
 }
Ejemplo n.º 4
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     using (var db = new SpeedCheckers.DAL.SpeedCheckersContext()) {
         db.Users.Add(new Models.User
         {
             ID   = Guid.NewGuid(),
             Name = "Init"
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 5
0
        // the function accepts the unique game id and the unique player id and the moveement details and saves it to the db moves history
        public Models.GameMove AddMove(Guid gameId, Guid playerId, string from, string to)
        {
            var id = Guid.NewGuid();

            using (var db = new SpeedCheckers.DAL.SpeedCheckersContext())
            {
                var lastMove = db.Moves.OrderByDescending(x => x.Number).FirstOrDefault();
                var number   = lastMove?.Number + 1 ?? 1;

                var move = new Models.GameMove {
                    ID       = id,
                    GameId   = gameId,
                    MoveFrom = from,
                    MoveTo   = to,
                    Number   = number,
                    PlayerId = playerId,
                };
                db.Moves.Add(move);
                db.SaveChanges();
                return(move);
            }
        }