public static void TestClientDb() { APIRequests request = new APIRequests(); ClientDBPerson clientDBPerson2 = new ClientDBPerson("*****@*****.**", "bugs", 1); var json2 = JsonConvert.SerializeObject(clientDBPerson2); var responseFromApi = request.SendPOSTRequestDataInBodyNoAuth("http://*****:*****@t.com", "bugs", id); var json = JsonConvert.SerializeObject(clientDBPerson); //logger.Info(json); var response = request.SendPOSTRequestDataInBodyNoAuth(request.clientSiteRegUrl, json); Console.WriteLine(response); }
public async Task <IHttpActionResult> Add(AddClientRequest request) { try { var client = new Client { Id = Guid.NewGuid(), Name = request.Name, Country = request.Country }; var id = await _repository.Add(client); if (id == Guid.Empty) { return(BadRequest()); } client = await _repository.Get <Client>(id); var response = new AddClientResponse { Result = client }; return(Ok(response)); } catch (Exception) { // TODO: Log exception } return(InternalServerError()); }
public bool AddClientToClientDb(string responseFromApi) { string response = responseFromApi; AddClientResponse addClientResponse = new AddClientResponse(response); int id = Convert.ToInt32(addClientResponse.clientId); ClientDBPerson clientDBPerson = new ClientDBPerson("*****@*****.**", "bugs", id); var json = JsonConvert.SerializeObject(clientDBPerson); APIRequests request = new APIRequests(); var responseFromClientDb = request.SendPOSTRequestDataInBodyNoAuth(request.clientSiteRegUrl, json); if (responseFromClientDb.Contains("success")) { return(true); } else { return(false); } }
public AddClientResponse add(AddClientRequest request) { try { var response = new AddClientResponse(); var bc = new ClientComponent(); response.Result = bc.Add(request.Client); return(response); } catch (Exception ex) { var httpError = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, ReasonPhrase = ex.Message }; throw new HttpResponseException(httpError); } }
private static AddClientResponse ToClientModel(JObject jObj) { if (jObj == null) { throw new ArgumentNullException(nameof(jObj)); } var result = new AddClientResponse { CustomerId = jObj.Value <string>(Constants.DtoNames.ClientNames.Id) }; var personalDetails = jObj.GetValue(Constants.DtoNames.ClientNames.PersonalDetails) as JObject; if (personalDetails != null) { result.Name = personalDetails.Value <string>(Constants.DtoNames.ClientNames.Name); result.Phone = personalDetails.Value <string>(Constants.DtoNames.ClientNames.Phone); var addressObj = personalDetails.GetValue(Constants.DtoNames.ClientNames.Address) as JObject; if (addressObj != null) { result.Address = new AddClientAddressResponse { AddressLine1 = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.AddressLine1), AddressLine2 = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.AddressLine2), City = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.City), Country = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.Country), CountryEnName = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.CountryEnName), CountryNativeName = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.CountryNativeName), LandLine = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.LandLine), Line1 = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.Line1), Line2 = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.Line2), PostalCode = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.PostalCode), PostCode = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.PostCode), RegionId = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.RegionId), RegionName = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.RegionName), State = addressObj.Value <string>(Constants.DtoNames.ClientResponseAddressNames.State) }; } } return(result); }