public void AddGameToUser([FromHeader] string Authorization, int gameId) { try { var userId = TokenParcer.GetUserIdByToken(Authorization); _gameServise.AddGame(userId, gameId); } catch (Exception e) { HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; Console.WriteLine(e.Message); } }
public IEnumerable <UserInfoForSearchDTO> GetFriendsByToken([FromHeader] string Authorization) { try { var id = TokenParcer.GetUserIdByToken(Authorization); return(GetFriends(id)); } catch (Exception e) { Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(null); } }
public async Task SetInfo([FromHeader] string Authorization, UserInfoDTO userInfo) { try { await _personService.AddUserInfo(TokenParcer.GetUserIdByToken(Authorization), userInfo); } catch (InvalidImageException) { HttpContext.Response.StatusCode = (int)HttpStatusCode.ExpectationFailed; } catch (FileLoadException) { HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; } }
public List <LastMessageDTO> LastMessage([FromHeader] string Authorization) { try { //Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjE1MT... var senderId = TokenParcer.GetUserIdByToken(Authorization); return(_messageService.GetLastMessages(senderId)); } catch (Exception e) { Console.WriteLine($"{e.Message}"); Console.WriteLine($"{e.StackTrace}"); HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; return(null); } }
public IEnumerable <GameDTO> Get([FromHeader] string Authorization) { List <GameDTO> result; try { var userId = TokenParcer.GetUserIdByToken(Authorization); result = _gameServise.GetGames(userId); } catch (Exception e) { HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError; Console.WriteLine(e); result = null; } return(result); }
public async Task Message([FromHeader] string Authorization, MessageInputDTO messageInput) { //Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6IjE1MT... try { var senderId = TokenParcer.GetUserIdByToken(Authorization); await _messageService.AddMessage(senderId, messageInput); } catch (MessageAndMediaEmptyException e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; } catch (Exception e) { Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.ExpectationFailed; } }
public UserProfileDTO Get([FromHeader] string Authorization, int id) { /* * Я заходжу на сторінку юзера. * мені приходять вся інфа про нього. + список френдів з іменами і фотками. (більше нетреба) * бо коли я заходжу на френда, все повторяється, тобто "мені приходять вся інфа про нього. + список френдів з іменами і фотками" */ var currentUserId = TokenParcer.GetUserIdByToken(Authorization); var result = _personService.GetLoggedUserProfileById(id, currentUserId); if (result?.userDTO != null) { this.HttpContext.Response.StatusCode = (int)HttpStatusCode.OK; return(result); } else { this.HttpContext.Response.StatusCode = (int)HttpStatusCode.BadRequest; return(new UserProfileDTO()); } }
public async Task <WriteUserResponseDTO> EditProfile([FromHeader] string Authorization, EditProfileDTO data) { try { var response = await _personService.EditProfile(TokenParcer.GetUserIdByToken(Authorization), data); if (!response.IsSuccessful) { HttpContext.Response.StatusCode = (int)HttpStatusCode.Conflict; } return(response); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("\n"); Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; return(null); } }
public async Task FirstMessage([FromHeader] string Authorization, MessageInputDTO messageInput) { try { var senderId = TokenParcer.GetUserIdByToken(Authorization); await _messageService.AddFirstMessage(senderId, messageInput); } catch (MessageAndMediaEmptyException e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.NoContent; } catch (Exception exception) { Console.WriteLine("======================================"); Console.WriteLine(exception.Message); Console.WriteLine("======================================"); Console.WriteLine(exception.StackTrace); HttpContext.Response.StatusCode = (int)HttpStatusCode.ExpectationFailed; } }
public AllMessageResponseDTO GetAllMessages(int id, [FromHeader] string Authorization) { var senderId = TokenParcer.GetUserIdByToken(Authorization); return(_messageService.GetMessages(senderId, id)); }