Exemple #1
0
        public void SetGame(GameViewModel model)
        {
            GameRoom          gameRoom = db.GameRooms.FirstOrDefault(e => e.Id == model.RoomId);
            List <PieceModel> fark     = new List <PieceModel>();

            gameRoom.Pieces.ToList().ForEach(g => {
                PieceModel aPiece = model.Pieces.FirstOrDefault(e => e.Id == g.Id && (e.Row != g.Row || e.Col != g.Col || e.Name != g.Name || e.Status != g.Status));
                if (aPiece != null)
                {
                    fark.Add(aPiece);
                }
            });
            fark.ForEach(e =>
            {
                var aPiece = gameRoom.Pieces.Single(k => k.Id == e.Id);
                if (e.Col == 0 && e.Row == 0)
                {
                    db.Entry(aPiece).State = EntityState.Deleted;
                    db.SaveChanges();
                }
                else
                {
                    aPiece.Col    = e.Col;
                    aPiece.Row    = e.Row;
                    aPiece.Name   = e.Name;
                    aPiece.Status = e.Status;
                    aPiece.Symbol = e.Symbol;
                }
            });
            gameRoom.GameStatus      = model.GameStatus;
            gameRoom.Turn            = model.Turn;
            db.Entry(gameRoom).State = EntityState.Modified;
            db.SaveChanges();
        }
        public void UpdateUser(User user)
        {
            User eUser = db.Users.FirstOrDefault(e => e.UId == user.UId);

            eUser.LoseCount       = user.LoseCount;
            eUser.Name            = user.Name;
            eUser.Surname         = user.Surname;
            eUser.Title           = user.Title;
            eUser.WonCount        = user.WonCount;
            eUser.DrawCount       = user.DrawCount;
            db.Entry(eUser).State = EntityState.Modified;
            db.SaveChanges();
        }
Exemple #3
0
 public void RemoveConnection(String ConnectionId)
 {
     using (var db = new ChessContext())
     {
         var userConnection = db.UserConnections.Single(e => e.Connectionid == ConnectionId);
         db.Entry(userConnection).State = EntityState.Deleted;
         db.SaveChanges();
     }
 }
Exemple #4
0
        public bool SendInvitation(string senderUId, string receiverUId, InvitationType invitationType)
        {
            if (db.Invitations.Any(e => e.InvitationFrom == senderUId && e.InvitationTo == receiverUId && e.InvitationState == InvitationState.Pending && e.InvitationType == invitationType))
            {
                return(false);
            }
            Invitation invitation = new Invitation()
            {
                InvitationFrom  = senderUId,
                InvitationTo    = receiverUId,
                InvitationType  = invitationType,
                InvitationState = InvitationState.Pending
            };

            db.Invitations.Add(invitation);
            db.SaveChanges();
            return(true);
        }
Exemple #5
0
 public void AddConnection(String UserId, String ConnectionId)
 {
     using (var db = new ChessContext())
     {
         db.UserConnections.Add(new UserConnection()
         {
             Userid = UserId, Connectionid = ConnectionId
         });
         db.SaveChanges();
     }
 }
Exemple #6
0
        public GameProgress PostStartGame([FromBody] StartGameRequest request)
        {
            // limit difficulty between 1 and 8
            request.difficulty = Math.Min(8, Math.Max(1, request.difficulty));
            var game = context.Game.Add(new Game()
            {
                Name         = request.name,
                Opponent     = "AI",
                AIDifficulty = request.difficulty,
            });

            ;
            context.SaveChanges();

            var chess = chessService.ReplayMoves(new List <Models.Move>());

            var progress = new GameProgress()
            {
                GameId = game.Entity.Id,
                State  = CoordinateOutput.GameToState(chess),
            };

            return(progress);
        }
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider       = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return(RedirectToAction("Manage"));
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (ChessContext db = new ChessContext())
                {
                    UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.UserProfiles.Add(new UserProfile {
                            UserName = model.UserName
                        });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return(RedirectToLocal(returnUrl));
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl           = returnUrl;
            return(View(model));
        }
Exemple #8
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    using (var db = new ChessContext())
                    {
                        //  var UsersContext = new ApplicationDbContext();
                        // string uid = UsersContext.Users.ToList().FirstOrDefault(e => e.Email == user.UserName).Id;
                        User newUser = new User()
                        {
                            EMail = user.UserName,
                            UId   = user.Id,
                        };
                        db.Users.Add(newUser);
                        db.SaveChanges();
                    }
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public void Save()
 {
     context.SaveChanges();
 }