public BusinessPartnerResponse Put(UpdateBusinessPartner request) { try { BusinessPartnerModel bpModel = request.ConvertTo <BusinessPartnerModel>(); var replaceResult = businessPartnerRepository.Upsert(bpModel); BusinessPartnerResponse response = bpModel.ConvertTo <BusinessPartnerResponse>(); if (!replaceResult.IsAcknowledged) { Log.Error($"Upsert operation was not Acknowledged for BusinessPartner with Id:{request.Id} Name:{request.Name}."); throw new Exception($"Upsert operation was not Acknowledged for BusinessPartner with Id:{request.Id} Name:{request.Name}."); } if (replaceResult.UpsertedId != null) { response.Id = replaceResult.UpsertedId.AsGuid; } return(response); } catch (Exception ex) { Log.Error(ex, "Something went wrong while upserting BusinessPartner."); throw; } }
public BusinessPartnerResponse Post(CreateBusinessPartner request) { try { BusinessPartnerModel result = request.ConvertTo <BusinessPartnerModel>(); businessPartnerRepository.Create(result); return(result.ConvertTo <BusinessPartnerResponse>()); } catch (Exception ex) { Log.Error(ex, "Something went wrong while posting BusinessPartner."); throw; } }
public BusinessPartnerResponse Get(GetBusinessPartner request) { try { BusinessPartnerModel businessPartner = businessPartnerRepository.Find(request.Id); if (businessPartner == default(BusinessPartnerModel)) { throw HttpError.NotFound($"There is no BusinessPartner with id : {request.Id}"); } return(businessPartner.ConvertTo <BusinessPartnerResponse>()); } catch (Exception ex) { Log.Error(ex, "Something went wrong while getting BusinessPartner."); throw; } }