public async Task <HttpResponseMessage> EditUserProfile() { var provider = await Request.Content.ReadAsMultipartAsync <InMemMultiFDSProvider>(new InMemMultiFDSProvider()); //access form data UserLoginVM _UserLoginVM = new UserLoginVM(); NameValueCollection formData = provider.FormData; if (formData["FirstName"] != null) { _UserLoginVM.FirstName = formData["FirstName"].Trim(); } if (formData["LastName"] != null) { _UserLoginVM.LastName = formData["LastName"].Trim(); } if (!string.IsNullOrWhiteSpace(formData["Password"])) { _UserLoginVM.Password = Common.EncryptedPassword(formData["Password"].Trim()); } if (!string.IsNullOrWhiteSpace(formData["NewPassword"])) { _UserLoginVM.NewPassword = Common.EncryptedPassword(formData["NewPassword"].Trim()); } if (!string.IsNullOrWhiteSpace(_UserLoginVM.Password) && string.IsNullOrWhiteSpace(_UserLoginVM.NewPassword)) { String _FailureCode = String.Empty; _Message = "\"message\":\"Invalid New Password\","; _strJSONContent = Common.FailureResponseRequest(_FailureCode, _Message); } else if (Common.IsTokenAuthenticated(Request.Headers, ref _userId, ref _strJSONContent)) { try { string filename = String.Empty; string directoryName = String.Empty; Stream input = null; _UserLoginVM.UserID = _userId; if (provider.Files.Count > 0) { List <BusinessImageVM> lstBusinessImage = new List <BusinessImageVM>(); HttpContent file1 = provider.Files[0]; var thisFileName = file1.Headers.ContentDisposition.FileName.Trim('\"'); input = await file1.ReadAsStreamAsync(); string URL = String.Empty; string tempDocUrl = ConfigurationManager.AppSettings["APIURL"]; string fileExtension = thisFileName.Substring(thisFileName.LastIndexOf(".") + 1); var path = HttpRuntime.AppDomainAppPath; directoryName = Path.Combine(path, "Uploads\\" + UserTypes.User + "\\" + _UserLoginVM.UserID); filename = Path.Combine(directoryName, thisFileName); _UserLoginVM.ProfileImageUrl = tempDocUrl + "/Uploads/" + UserTypes.User + "/" + _UserLoginVM.UserID + "/" + thisFileName; } else { _UserLoginVM.ProfileImageUrl = String.Empty; } _UserLoginVM = _userBLL.EditUserProfile(_UserLoginVM); if (_UserLoginVM != null) { if (!string.IsNullOrWhiteSpace(_UserLoginVM.ProfileImageUrl)) { if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } else { string[] filePaths = Directory.GetFiles(directoryName); foreach (string filePath in filePaths) { File.Delete(filePath); } } if (File.Exists(filename)) { File.Delete(filename); } using (Stream file = File.OpenWrite(filename)) { input.CopyTo(file); file.Close(); } } String _SuccessCode = String.Empty; _Message = "\"message\":\"Successfully Updated\","; JSONSuccessResult(_UserLoginVM, _SuccessCode, _UserLoginVM.HeaderToken); } else { String _FailureCode = String.Empty; _Message = "\"message\":\"Invalid Password\","; _strJSONContent = Common.FailureResponseRequest(_FailureCode, _Message); } } catch (Exception ex) { _Message = ex.Message; _strJSONContent.Append("{\"status\":\"Failed\"}"); } } return(Common.ResponseOutput(_strJSONContent)); }