Exemplo n.º 1
0
        /// <summary>
        /// Method to Add the Player passed in the parameters to the database
        /// </summary>
        /// <param name="game">Object Player to Add</param>
        public async Task <ApiResponse> Add(Player player)
        {
            try
            {
                if (!await _playerBusiness.Check(player))
                {
                    player.Picture = await _imageBusiness.UploadImage(player.ImageBase64, $"{player.FirstName}-{player.LastName}-{player.Login}-{DateTime.Now.ToString("yyyyMMddHHmmss")}");

                    player.Password = _cryption.Encrypt(player.Password);
                    await _context.Players.AddAsync(player);

                    await _context.SaveChangesAsync();

                    return(new ApiResponse {
                        Status = ApiStatus.Ok, Message = ApiAction.Add, Response = player
                    });
                }
                else
                {
                    return(new ApiResponse {
                        Status = ApiStatus.CantDelete, Message = "Le pseudo et l'e-mail doivent être uniques."
                    });
                }
            }
            catch (Exception e)
            {
                return(TranslateError.Convert(e));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Definition of the function that will authentificate the Player passed in the parameters to the database
 /// </summary>
 /// <param name="player">Object Player to authentificate</param>
 public async Task <Player> Authentificate(Player player)
 {
     return(await _context.Players.FirstOrDefaultAsync(p => p.Login == player.Login && p.Password == _cryption.Encrypt(player.Password)));
 }