public IActionResult Patch(string id, [FromBody] JsonPatchDocument <ClientAddr> clientAddrPatch) { try { if (Guid.TryParse(id, out Guid parsedId)) { //var userId = User.FindFirstValue("sub"); ClientAddress clientAddress = _unitOfWork.ClientAddresses.Get(parsedId); ClientAddr clientAddr = _mapper.Map <ClientAddr>(clientAddress); clientAddrPatch.ApplyTo(clientAddr); _mapper.Map(clientAddr, clientAddress); _unitOfWork.Complete(); return(CreatedAtRoute("Get", new { id = _mapper.Map <ClientAddr>(clientAddress).Id }, _mapper.Map <ClientAddr>(clientAddress))); } } catch (Exception e) { string message = e.Message; } return(BadRequest()); }
public IActionResult Post([FromBody] ClientAddr clientAddr) { try { if (clientAddr.Id == Guid.Empty) { ClientContact clientContact = _unitOfWork.ClientContacts.SingleOrDefault(c => c.Id == clientAddr.ClientContactId, true); if (clientContact.Id != Guid.Empty) { //var userId = User.FindFirstValue("sub"); var clientAddress = _mapper.Map <ClientAddress>(clientAddr); _unitOfWork.ClientAddresses.Add(clientAddress); _unitOfWork.Complete(); return(Created(new Uri($"{Request.Path}/{clientAddress.Id}", UriKind.Relative), _mapper.Map <ClientAddr>(clientAddress))); } } } catch (Exception e) { string message = e.Message; } return(BadRequest()); }
private async Task <bool> CreateOrUpdateAddressAsync(ClientAddr clientAddr, string apiAccessToken) { if (clientAddr != null) { if (clientAddr.Id != Guid.Empty) { var response = await _apiHelper.MakeAPICallAsync(apiAccessToken, HttpMethod.Get, APITypes.CLIENT, $"Address/{clientAddr.Id}"); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var foundClientAddr = response.ContentAsType <ClientAddr>(); if (foundClientAddr != null) { if (!await _modelHelper.ProcessPatch(foundClientAddr, clientAddr, foundClientAddr.Id, apiAccessToken, APITypes.CLIENT, "Address")) { return(false); } } } } else { HttpContent contentPost = new StringContent(JsonConvert.SerializeObject(clientAddr), Encoding.UTF8, "application/json"); try { var response = await _apiHelper.MakeAPICallAsync(apiAccessToken, HttpMethod.Post, APITypes.CLIENT, $"Address", contentPost); if (response.StatusCode != System.Net.HttpStatusCode.Created) { return(false); } } catch (Exception ex) { var responseString = $"Error calling API: {ex.Message}"; return(false); } } } return(true); }
//private static string GetStringBetween(string strSource, string strStartTag, string strEndTag) //{ // int start, end; // if(strSource.Contains(strStartTag) && strSource.Contains(strEndTag)) // { // start = strSource.IndexOf(strStartTag, 0) + strStartTag.Length; // end = strSource.IndexOf(strEndTag, start); // return strSource.Substring(start, end - start); // } // return string.Empty; //} private ClientHead GenerateDummyClientHeadModel() { var dummyClientHead = new ClientHead(); dummyClientHead.Id = Guid.Empty; var dummyClientCon = new ClientCon() { Id = Guid.Empty, FirstName = string.Empty, MiddleName = string.Empty, LastName = string.Empty, Email = string.Empty, Phone = string.Empty }; var dummyClientAddr = new ClientAddr() { ClientContactId = Guid.Parse("11111111-1111-1111-1111-111111111111"), Id = Guid.Empty, AddressLine1 = string.Empty, AddressLine2 = string.Empty, AddressLine3 = string.Empty, AddressLine4 = string.Empty, AddressLine5 = string.Empty, Country = string.Empty, Email1 = string.Empty, Email2 = string.Empty, Email3 = string.Empty, Phone1 = string.Empty, Phone2 = string.Empty, Phone3 = string.Empty, PostalCode = string.Empty, Region = string.Empty }; dummyClientCon.ClientAddresses.Add(dummyClientAddr); dummyClientHead.ClientContacts.Add(dummyClientCon); return(dummyClientHead); }
public bool Equals(DeviceDescriptor a) { return(ClientAddr.Equals(a.ClientAddr) && DeviceName.Equals(a.DeviceName)); }
public void Visit(ClientAddr clientAddr) { string serviceName = null; AddBinaryAnnotation(zipkinCoreConstants.CLIENT_ADDR, true, serviceName, clientAddr.Endpoint); }