public async Task <string> UpdateByLogin(string login, ForUpdateModel userModel) { var findUser = _unitOfWork.Users.FindAsync(x => x.AccountDB.Login == login).Result.FirstOrDefault().ProfileDB; if (findUser == null) { return("Not Found"); } var profileDB = _mapper.Map <ForUpdateModel, ProfileDB>(userModel); await _unitOfWork.Profiles.UpdateProfileAsync(profileDB, findUser.Id); return("Ok"); }
/// <summary> /// /// </summary> /// <param name="login"></param> /// <param name="userModel"></param> /// <returns>bool?</returns> public bool?UserUpdateByLogin(string login, ForUpdateModel userModel) { // verify the required parameter 'login' is set if (login == null) { throw new ApiException(400, "Missing required parameter 'login' when calling UserUpdateByLogin"); } // verify the required parameter 'userModel' is set if (userModel == null) { throw new ApiException(400, "Missing required parameter 'userModel' when calling UserUpdateByLogin"); } var path = "/api/users/{login}"; path = path.Replace("{format}", "json"); path = path.Replace("{" + "login" + "}", ApiClient.ParameterToString(login)); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(userModel); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.PUT, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling UserUpdateByLogin: "******"Error calling UserUpdateByLogin: " + response.ErrorMessage, response.ErrorMessage); } return((bool?)ApiClient.Deserialize(response.Content, typeof(bool?), response.Headers)); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// </param> /// <param name='userModel'> /// </param> public static object Update(this IUser operations, string id, ForUpdateModel userModel) { return(operations.UpdateAsync(id, userModel).GetAwaiter().GetResult()); }
/// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='id'> /// </param> /// <param name='userModel'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <object> UpdateAsync(this IUser operations, string id, ForUpdateModel userModel, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(id, userModel, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public async Task <IActionResult> Update(string id, [FromBody] ForUpdateModel userModel) { var result = await _service.Update(id, userModel); return(Ok(result)); }
/// <param name='id'> /// </param> /// <param name='userModel'> /// </param> /// <param name='customHeaders'> /// Headers that will be added to request. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> /// <exception cref="HttpOperationException"> /// Thrown when the operation returned an invalid status code /// </exception> /// <exception cref="SerializationException"> /// Thrown when unable to deserialize the response /// </exception> /// <exception cref="ValidationException"> /// Thrown when a required parameter is null /// </exception> /// <exception cref="System.ArgumentNullException"> /// Thrown when a required parameter is null /// </exception> /// <return> /// A response object containing the response body and response headers. /// </return> public async Task <HttpOperationResponse <object> > UpdateWithHttpMessagesAsync(string id, ForUpdateModel userModel, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (id == null) { throw new ValidationException(ValidationRules.CannotBeNull, "id"); } if (userModel == null) { throw new ValidationException(ValidationRules.CannotBeNull, "userModel"); } if (userModel != null) { userModel.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("id", id); tracingParameters.Add("userModel", userModel); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "Update", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "api/users/{id}").ToString(); _url = _url.Replace("{id}", System.Uri.EscapeDataString(id)); // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("PUT"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (userModel != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(userModel, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json-patch+json; charset=utf-8"); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200 && (int)_statusCode != 400) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); if (_httpResponse.Content != null) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); } else { _responseContent = string.Empty; } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <object>(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 200) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <bool?>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } // Deserialize Response if ((int)_statusCode == 400) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); try { _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <string>(_responseContent, Client.DeserializationSettings); } catch (JsonException ex) { _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw new SerializationException("Unable to deserialize the response.", _responseContent, ex); } } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }