public async Task <bool> DeleteConversation(int conversationId) { HttpResponseMessage response; try { var model = new SingleIdModelForPostRequests { Id = conversationId }; var stringContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json"); response = await client.PostAsync($"{WebApiConsts.CONVERSATION_CONTROLLER}/DeleteConversation", stringContent); } catch { response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); } if (response.IsSuccessStatusCode) { return(true); } return(false); }
private void AddToFavourites() { AlertsService.ShowConfirmDialog(this, "Czy na pewno dodaæ to og³oszenie do ulubionych?", async() => { var idApiModel = new SingleIdModelForPostRequests { Id = this.advertisement.Id }; var responseMessage = await this.advertisementItemService.AddToUserFavouritesAdvertisements(idApiModel); AlertsService.ShowLongToast(this, responseMessage); }); }
public IActionResult AddToUserFavourites([FromBody] SingleIdModelForPostRequests advertisementId) { try { var userId = this.identityService.GetUserId(User.Identity); var success = this.advertisementItemService.AddToUserFavourites(userId, advertisementId.Id); var messeage = success ? "Ogłoszenie zostało dodane do schowka." : "Ogłoszenie jest już w Twoim schowku"; return(Json(messeage)); } catch (Exception exc) { Response.StatusCode = (int)HttpStatusCode.InternalServerError; logger.LogError("Wystąpił wyjątek w trakcie dodawania ogłoszenia do ulubionych: " + exc); return(Json("Wystąpił błąd na serwerze. Spróbuj ponownie później")); } }
public IActionResult DeleteConversation([FromBody] SingleIdModelForPostRequests conversationIdModel) { try { var userId = this.identityService.GetUserId(User.Identity); var success = this.conversationService.DeleteConversation(userId, conversationIdModel.Id); return(Json(success)); } catch (Exception exc) { this.logger.LogError("Wyst¹pi³ b³¹d podczas oznaczania rozmowy jako usunietej: " + exc); Response.StatusCode = (int)HttpStatusCode.InternalServerError; return(Json(false)); } }
public async Task <string> AddToUserFavouritesAdvertisements(SingleIdModelForPostRequests advertisementId) { HttpResponseMessage response; try { response = await client.PostAsync(WebApiConsts.ADVERTISEMENT_CONTROLLER + "AddToUserFavourites", new StringContent(JsonConvert.SerializeObject(advertisementId), Encoding.UTF8, "application/json")); } catch { response = new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError); } var responseContentString = await response.Content.ReadAsStringAsync(); return(responseContentString.Replace("\"", "")); }