Esempio n. 1
0
        public async Task <FeedbackResultViewModel> FeedbackResultBuilder(FeedbackViewModel feedback)
        {
            feedback.DateAdded = DateTime.Now;
            feedback.PageData  = await _pageDateViewModelBuilder.PageDataBuilder(feedback.PageData);

            feedback.PageId = feedback.PageData.ToString();
            try
            {
                var request = new JsonRestRequest(_configuration.FeedbackAddFeedbackUrl, Method.POST);
                request.AddJsonBody(feedback);
                if (!string.IsNullOrEmpty(_configuration.FeedbackApiUsername) && !string.IsNullOrEmpty(_configuration.FeedbackApiPassword))
                {
                    request.Credentials = new NetworkCredential(_configuration.FeedbackApiUsername, _configuration.FeedbackApiPassword);
                }
                var response = await _restClient.ExecuteAsync(request);

                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
                {
                    return(new FeedbackConfirmationResultViewModel(feedback));
                }
            }
            catch
            {
                return(new FeedbackErrorResultViewModel(feedback));
            }
            return(new FeedbackErrorResultViewModel(feedback));
        }
        public async Task <FeedbackConfirmation> FeedbackBuilder(FeedbackViewModel feedback)
        {
            feedback.DateAdded = DateTime.Now;
            feedback.PageData  = await _pageDateViewModelBuilder.PageDataBuilder(feedback.PageData);

            feedback.PageId = feedback.PageData.ToString();
            try {
                var request = new HttpRequestMessage {
                    Content = new StringContent(JsonConvert.SerializeObject(feedback), Encoding.UTF8, "application/json")
                };
                var httpHeaders = new Dictionary <string, string> {
                    { "Authorization", _configuration.FeedbackAuthorization }
                };
                var response = await _restfulHelper.PostAsync(_configuration.FeedbackAddFeedbackUrl, request, httpHeaders);

                if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created)
                {
                    return(FeedbackConfirmation.Success);
                }
            } catch {
                return(FeedbackConfirmation.Error);
            }
            return(FeedbackConfirmation.Error);
        }