Пример #1
0
 public CRMState()
 {
     Lead          = new Lead();
     Company       = new Company();
     Product       = new Product();
     Opportunity   = new OpportunityDetailed();
     Opportunities = new List <OpportunityDetailed>();
 }
Пример #2
0
        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();
                        }
                    }
                }
            }
        }
Пример #3
0
 public void ResetOpportunity()
 {
     Lead        = new Lead();
     Product     = new Product();
     Opportunity = new OpportunityDetailed();
 }