public CRMState() { Lead = new Lead(); Company = new Company(); Product = new Product(); Opportunity = new OpportunityDetailed(); Opportunities = new List <OpportunityDetailed>(); }
public async Task PostOpportunityAsync(string token, OpportunityDetailed opportunity) { if (token == null) { throw new InvalidTokenException("Token is null"); } var path = $"api/opportunities"; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var strictOpportunity = new Opportunity(opportunity); using (var request = new HttpRequestMessage(HttpMethod.Post, path)) { var json = JsonConvert.SerializeObject(strictOpportunity); using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json")) { request.Content = stringContent; using (var response = await _httpClient .SendAsync(request, HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { switch (response.StatusCode) { case HttpStatusCode.Created: break; case HttpStatusCode.Forbidden: throw new AccessForbiddenException(); default: throw new OpportunityNotCreatedException(); } } } } }
public void ResetOpportunity() { Lead = new Lead(); Product = new Product(); Opportunity = new OpportunityDetailed(); }