/// <summary>
        /// Creates the story.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> CreateStory(CreateStoryRequest request)
        {
            try
            {
                var client = httpClientFactory.CreateClient(BlogServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(servicesConfig.Blog + BlogServiceOperation.CreateStory(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var story = JsonConvert.DeserializeObject <StoryResponse>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(story, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateStory()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
Пример #2
0
        /// <summary>
        /// Creates the story.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> CreateStory(CreateStoryRequest request)
        {
            try
            {
                string filename   = "";
                var    folderName = Path.Combine("EventStories");
                var    pathToSave = Path.Combine("D:", "HappyWedding", folderName);

                if (request.CoverPhotoVideo.Length > 0)
                {
                    string format = System.IO.Path.GetExtension(request.CoverPhotoVideo.FileName);
                    filename = request.VendorId + "_Event_" + DateTime.Now + format;
                    string filenme  = filename.Replace(":", ".");
                    var    filePath = Path.Combine(pathToSave, filenme);
                    using var fileStream = new FileStream(filePath, FileMode.Create);
                    request.CoverPhotoVideo.CopyTo(fileStream);
                    request.CoverPhotoOrVideo = filePath;
                    request.CoverPhotoOrVideo = null;
                }
                var client = httpClientFactory.CreateClient(BlogServiceOperation.serviceName);

                var         param       = JsonConvert.SerializeObject(request);
                HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json");

                var response = await client.PostAsync(servicesConfig.Blog + BlogServiceOperation.CreateStory(), contentPost);

                if (response.IsSuccessStatusCode)
                {
                    var story = JsonConvert.DeserializeObject <StoryResponse>(await response.Content.ReadAsStringAsync());
                    return(new APIResponse(story, HttpStatusCode.Created));
                }

                return(new APIResponse(response.StatusCode));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'CreateStory()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }