Exemple #1
0
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> UpdateUser(UserIdDetails details, UpdateUserRequest request)
        {
            try
            {
                var client = httpClientFactory.CreateClient(IdentityServiceOperation.serviceName);

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

                var response = await client.PutAsync(servicesConfig.Identity + IdentityServiceOperation.UpdateUser(details.UserId), contentPost);

                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    var user = new User {
                        Id = details.UserId, FirstName = request.FirstName, LastName = request.LastName
                    };
                    usernameUpdateSender.SendUserName(user);
                }

                return(JsonConvert.DeserializeObject <APIResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'UpdateUser()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="details">The details.</param>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <APIResponse> UpdateUserProfile(ProfileIdDetails details, UpdateUserProfileRequest request)
        {
            try
            {
                string filename   = "";
                var    folderName = Path.Combine("UserProfiles");
                var    pathToSave = Path.Combine("D:", "HappyWedding", folderName);

                if (request.ProfilePhoto.Length > 0)
                {
                    string format = System.IO.Path.GetExtension(request.ProfilePhoto.FileName);
                    filename = request.UserId + "_UserProfiles_" + DateTime.Now + format;
                    string filenme  = filename.Replace(":", ".");
                    var    filePath = Path.Combine(pathToSave, filenme);
                    using var fileStream = new FileStream(filePath, FileMode.Create);
                    request.ProfilePhoto.CopyTo(fileStream);
                    request.Photo        = filePath;
                    request.ProfilePhoto = null;
                }

                var client = httpClientFactory.CreateClient(IdentityServiceOperation.serviceName);

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

                var response = await client.PutAsync(servicesConfig.Identity + IdentityServiceOperation.UpdateUser(details.ProfileId), contentPost);

                if (response.StatusCode == HttpStatusCode.NoContent)
                {
                    var user = new User {
                        Id = details.ProfileId, FirstName = request.FirstName, LastName = request.LastName
                    };
                    usernameUpdateSender.SendUserName(user);
                }

                return(JsonConvert.DeserializeObject <APIResponse>(await response.Content.ReadAsStringAsync()));
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception in method 'UpdateUser()'");
                var exMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                return(new APIResponse(exMessage, HttpStatusCode.InternalServerError));
            }
        }