/// <summary> /// Insert entity. /// </summary> /// <param name="client">SugarRestClient object.</param> /// <param name="request">The request object.</param> /// <param name="modelInfo">The entity model info.</param> /// <returns>SugarRestResponse object.</returns> public static SugarRestResponse ExecuteInsert(this SugarRestClient client, SugarRestRequest request, ModelInfo modelInfo) { var sugarRestResponse = new SugarRestResponse(); var loginResponse = new LoginResponse(); try { var loginRequest = new LoginRequest { Url = request.Url, Username = request.Username, Password = request.Password }; loginResponse = Authentication.Login(loginRequest); JObject jobject = JsonConverterHelper.Serialize(request.Parameter, modelInfo.Type); var selectFields = modelInfo.GetJsonPropertyNames(request.Options.SelectFields); var insertEntryResponse = InsertEntry.Run(loginResponse.SessionId, loginRequest.Url, request.ModuleName, jobject, selectFields); if (insertEntryResponse != null) { sugarRestResponse.JsonRawRequest = insertEntryResponse.JsonRawRequest; sugarRestResponse.JsonRawResponse = insertEntryResponse.JsonRawResponse; if (!string.IsNullOrEmpty(insertEntryResponse.Id)) { sugarRestResponse.Data = insertEntryResponse.Id; sugarRestResponse.JData = (insertEntryResponse.Id == null) ? null : JToken.FromObject(insertEntryResponse.Id).ToString(); sugarRestResponse.StatusCode = insertEntryResponse.StatusCode; } else { sugarRestResponse.Error = insertEntryResponse.Error; sugarRestResponse.StatusCode = insertEntryResponse.StatusCode; } } return(sugarRestResponse); } catch (Exception exception) { sugarRestResponse.StatusCode = HttpStatusCode.InternalServerError; sugarRestResponse.Error = ErrorResponse.Format(exception, string.Empty); } finally { Authentication.Logout(request.Url, loginResponse.SessionId); } return(sugarRestResponse); }
private Entry ModelToDb(InsertEntry entry, int collectionId) { return(new Entry { CollectionId = collectionId, PhoneHash = _hashService.GeneratePrivateHash(entry.PhoneHash), IdHash = _hashService.GeneratePrivateHash(entry.IdHash), HasBirthdate = entry.HasBirthdate, HasComingPlace = entry.HasComingPlace, HasEmail = entry.HasEmail, HasGender = entry.HasGender, HasLivingPlace = entry.HasLivingPlace, HasName = entry.HasName, HasRelationshipStatus = entry.HasRelationshipStatus, HasWorkplace = entry.HasWorkplace }); }