public async Task <APIResponse> CreateCategoryDetails(CreateCategoryDetailsRequest request) { try { string filename = ""; var folderName = Path.Combine("Profilepics"); var pathToSave = Path.Combine("D:", "HappyWedding", folderName); if (request.UploadProfilePicture != null) { foreach (var item in request.UploadProfilePicture) { request.ProfilePictures = new List <ProfilePictures>(); if (item.Length > 0) { string format = System.IO.Path.GetExtension(item.FileName); filename = request.VendorId + "_ProfilePicture_" + DateTime.Now + format; string filenme = filename.Replace(":", "."); var filePath = Path.Combine(pathToSave, filenme); using var fileStream = new FileStream(filePath, FileMode.Create); item.CopyTo(fileStream); request.ProfilePictures.Add(new ProfilePictures { ProfilePicturePath = filePath }); } } request.UploadProfilePicture = null; } if (request.ProfileImage != null) { var profilePicture = request.ProfileImage; if (profilePicture.Length > 0) { string format = System.IO.Path.GetExtension(profilePicture.FileName); filename = request.VendorId + "_ProfilePicture_" + DateTime.Now + format; string filenme = filename.Replace(":", "."); var filePath = Path.Combine(pathToSave, filenme); using var fileStream = new FileStream(filePath, FileMode.Create); profilePicture.CopyTo(fileStream); request.ProfilePicture = filePath; } request.ProfileImage = null; } var client = httpClientFactory.CreateClient(VendorServiceOperation.serviceName); var param = JsonConvert.SerializeObject(request); HttpContent contentPost = new StringContent(param, Encoding.UTF8, "application/json"); var response = await client.PostAsync(servicesConfig.Vendor + VendorServiceOperation.CreateCategoryDetails(), contentPost); if (response.IsSuccessStatusCode) { var profilecategory = JsonConvert.DeserializeObject <CategoryDetailsResponse>(await response.Content.ReadAsStringAsync()); return(new APIResponse(profilecategory, HttpStatusCode.Created)); } return(new APIResponse(response.StatusCode)); } catch (Exception ex) { logger.Error(ex, "Exception in method 'CreateCategoryDetails()'"); var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(new APIResponse(exMessage, HttpStatusCode.InternalServerError)); } }