public async Task <RecordResult> ChangeImageAsync(ChangeImagedDto gameDto) { RecordResult recordResult = new RecordResult(); UsedGamesAPIGameResponse response = await _usedGamesAPIGames.GetImagesAsync(gameDto.GameId, _loginManager.GetUserToken()); if (!response.Success) { return(recordResult); } if (!IsNewImg(response.Images, gameDto.ImgFile.FileName)) { recordResult.ErrorMessage = "This is not a new image"; return(recordResult); } recordResult = ImageHandler.Change($"{GetImgsFolder()}/{gameDto.GameId}", gameDto.OldImgRelativePath, gameDto.ImgFile); if (!recordResult.Success) { return(recordResult); } Image img = new Image(gameDto.ImgId, recordResult.Path, gameDto.GameId); response = await _usedGamesAPIGames.UpdateImageAsync(img, _loginManager.GetUserToken()); recordResult.Success = response.Success; return(recordResult); }
public async Task <Result> RegisterGameAsync(Game game) { Result result = new Result(); UsedGamesAPIGameResponse response = await _usedGamesAPIGames.CreateAsync(game, _loginManager.GetUserToken()); if (!response.Success) { return(result); } RecordResult recordResult = ImageHandler.MoveTempImgs(response.Game.Id, GetImgsTempFolder(), GetImgsFolder()); if (!recordResult.Success) { return(result); } response = await _usedGamesAPIGames.CreateImagesAsync(response.Game.Id, recordResult.Paths, _loginManager.GetUserToken()); if (!response.Success) { return(result); } ImageHandler.DeleteImgFolder(GetImgsTempFolder()); result.Success = true; return(result); }
public async Task <Result> EditGameAsync(Game game) { UsedGamesAPIGameResponse response = await _usedGamesAPIGames.UpdateAsync(game, _loginManager.GetUserToken()); Result result = new Result(response.Success); return(result); }
public async Task <UsedGamesAPIGameResponse> DeleteAsync(int id, string token) { ConfigureToken(token); HttpResponseMessage responseMsg = await _client.DeleteAsync(_client.BaseAddress + id.ToString()); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse(responseMsg.IsSuccessStatusCode); return(response); }
public async Task <UsedGamesAPIGameResponse> UpdateAsync(Game game, string token) { ConfigureToken(token); string jsonGame = JsonConvert.SerializeObject(game); HttpResponseMessage responseMsg = await _client.PutAsync($"{_client.BaseAddress}{game.Id}", new StringContent(jsonGame, Encoding.UTF8, "application/json")); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse(responseMsg.IsSuccessStatusCode); return(response); }
public async Task <List <Image> > GetImagesAsync(int id) { UsedGamesAPIGameResponse response = await _usedGamesAPIGames.GetImagesAsync(id, _loginManager.GetUserToken()); if (!response.Success) { return(null); } return(response.Images); }
public async Task <UsedGamesAPIGameResponse> CreateImagesAsync(int id, List <string> imgPaths, string token) { ConfigureToken(token); var imgs = new { Images = BuildImages(imgPaths) }; string jsonImgs = JsonConvert.SerializeObject(imgs); HttpResponseMessage responseMsg = await _client.PostAsync(_client.BaseAddress + $"{id}/images/", new StringContent(jsonImgs, Encoding.UTF8, "application/json")); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse(success: responseMsg.IsSuccessStatusCode); return(response); }
public async Task <UsedGamesAPIGameResponse> UpdateImageAsync(Image img, string token) { ConfigureToken(token); string requestUri = $"{_client.BaseAddress}{img.GameId}/images/{img.Id}"; string jsonImg = JsonConvert.SerializeObject(img); HttpResponseMessage responseMsg = await _client.PutAsync(requestUri, new StringContent(jsonImg, Encoding.UTF8, "application/json")); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse(success: responseMsg.IsSuccessStatusCode); return(response); }
public async Task <Result> DeleteGameAsync(int id) { UsedGamesAPIGameResponse response = await _usedGamesAPIGames.DeleteAsync(id, _loginManager.GetUserToken()); Result result = new Result(response.Success); if (result.Success) { ImageHandler.DeleteImgFolder($"{GetImgsFolder()}/{id}"); } return(result); }
public async Task <UsedGamesAPIGameResponse> GetImagesAsync(int id, string token) { ConfigureToken(token); HttpResponseMessage responseMsg = await _client.GetAsync($"{_client.BaseAddress}{id}/images"); string responseStr = await responseMsg.Content.ReadAsStringAsync(); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse(responseMsg.IsSuccessStatusCode); if (response.Success) { response.Images = JsonConvert.DeserializeObject <List <Image> >(responseStr); } return(response); }
public async Task <UsedGamesAPIGameResponse> GetAsync(int id, string token) { ConfigureToken(token); HttpResponseMessage responseMsg = await _client.GetAsync(_client.BaseAddress.AbsoluteUri + id); string responseStr = await responseMsg.Content.ReadAsStringAsync(); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse() { Success = responseMsg.IsSuccessStatusCode }; if (response.Success) { response.Game = JsonConvert.DeserializeObject <Game>(responseStr); } return(response); }
public async Task <UsedGamesAPIGameResponse> CreateAsync(Game game, string token) { ConfigureToken(token); string jsonGame = JsonConvert.SerializeObject(game); HttpResponseMessage responseMsg = await _client.PostAsync(_client.BaseAddress, new StringContent(jsonGame, Encoding.UTF8, "application/json")); string responseStr = await responseMsg.Content.ReadAsStringAsync(); UsedGamesAPIGameResponse response = new UsedGamesAPIGameResponse() { Success = responseMsg.IsSuccessStatusCode }; if (response.Success) { response.Game = JsonConvert.DeserializeObject <Game>(responseStr); } return(response); }
public async Task <GameViewModel> GetGameViewModelForEditAsync(int id) { UsedGamesAPIGameResponse gameResponse = await _usedGamesAPIGames.GetAsync(id, _loginManager.GetUserToken()); if (!gameResponse.Success) { return(null); } UsedGamesAPIPlatformResponse platformResponse = await _usedGamesAPIPlatforms.GetPlatformsAsync(); if (!platformResponse.Success) { return(null); } GameViewModel viewModel = new GameViewModel ( game: gameResponse.Game, platforms: new SelectList(platformResponse.Platforms, "Id", "Name"), imgsPerGame: GetImgsPerGame(), sellerId: _loginManager.GetUserId() ); return(viewModel); }