Exemple #1
0
        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;
            }
        }
Exemple #2
0
        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;
            }
        }
Exemple #3
0
        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;
            }
        }