public async Task Vote(SurveyVoteModel surveyVoteModel, string authenticationToken) { try { VoteService voteService = new VoteService(); surveyVoteModel.voteDate = ""; surveyVoteModel.active = 1; var response = await voteService.Vote(surveyVoteModel, authenticationToken).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new Exception(response.StatusCode.ToString() + " - " + response.ReasonPhrase); } } catch (Exception ex) { throw new Exception(ex.Message); } }
public async Task <HttpResponseMessage> Vote(SurveyVoteModel surveyVoteModel, string authenticationToken) { try { using (var client = new HttpClient()) { List <SurveyVoteModel> surveyVotes = new List <SurveyVoteModel>(); surveyVotes.Add(surveyVoteModel); var formContent = new StringContent(JsonConvert.SerializeObject(surveyVotes, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json"); return(await client.PostAsync(EnvironmentConstants.getServerUrl() + "api/survey/vote", formContent)); } } catch (Exception ex) { throw new Exception(ex.Message); } }