Beispiel #1
0
        public bool PlayerAdd(PlayerAddFormViewModel newPlayer)
        {
            PlayersBaseViewModel player = new PlayersBaseViewModel(newPlayer);

            if (newPlayer.PlayerImage != null)
            {
                byte[] photoBytes = new byte[newPlayer.PlayerImage.Length];

                using (MemoryStream ms = new MemoryStream())
                {
                    newPlayer.PlayerImage.OpenReadStream().CopyTo(ms);
                    photoBytes = ms.ToArray();
                }

                player.PLAYER_AVATAR     = photoBytes;
                player.PLAYER_AVATARTYPE = newPlayer.PlayerImage.ContentType;
            }
            else
            {
                player.PLAYER_AVATAR     = null;
                player.PLAYER_AVATARTYPE = null;
            }

            var addedPlayer = ds.Players.Add(mapper.Map <PlayersBaseViewModel, Players>(player));

            ds.SaveChanges();

            return(addedPlayer == null ? false : true);
        }
Beispiel #2
0
        public string PlayerChangeUser(string newUsername, int id)
        {
            var player        = ds.Players.Find(id);
            var username      = player.PLAYER_USERNAME;
            var updatedPlayer = new PlayersBaseViewModel();

            updatedPlayer = mapper.Map <Players, PlayersBaseViewModel>(player);

            try
            {
                if (updatedPlayer != null)
                {
                    updatedPlayer.PLAYER_USERNAME = newUsername;

                    ds.Entry(player).CurrentValues.SetValues(updatedPlayer);
                    ds.SaveChanges();

                    return("Username Updated Sucessfully!");
                }
                else
                {
                    return("There was a problem updating your username. Please try again");
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    player.PLAYER_USERNAME = username;
                    return("There was a problem updating your username. " + ex.InnerException.Message);
                }

                return("There was a problem updating your username. " + ex.Message);
            }
        }
Beispiel #3
0
        public void AuthenticateUser(PlayersBaseViewModel player)
        {
            var userClaim = new List <Claim>()
            {
                new Claim(ClaimTypes.Name, player.PLAYER_ID.ToString())
            };

            var userIdentity = new ClaimsIdentity(userClaim, "User Identity");

            var userPrincipal = new ClaimsPrincipal(new[] { userIdentity });

            HttpContext.SignInAsync(userPrincipal);
        }
Beispiel #4
0
        public void PlayerChangeAvatar(PlayersBaseViewModel player, IFormFile file)
        {
            var oPlayer = ds.Players.Find(player.PLAYER_ID);

            if (oPlayer != null)
            {
                byte[] photoBytes = new byte[file.Length];

                using (MemoryStream ms = new MemoryStream())
                {
                    file.OpenReadStream().CopyTo(ms);
                    photoBytes = ms.ToArray();
                }

                player.PLAYER_AVATAR     = photoBytes;
                player.PLAYER_AVATARTYPE = file.ContentType;

                ds.Entry(oPlayer).CurrentValues.SetValues(player);
                ds.SaveChanges();
            }
        }