Example #1
0
        public async Task <ActionResult <PaymentBillingModel> > Post(int customerId, PaymentBillingModel model)
        {
            try
            {
                //Make sure PaymentBillingId is not already taken
                var existing = await _repository.GetPaymentBillingAsync(customerId, model.Id);

                if (existing != null)
                {
                    return(BadRequest("PaymentBilling Id in Use"));
                }

                //map
                var PaymentBilling = _mapper.Map <PaymentBilling>(model);

                //save and return
                if (!await _repository.StoreNewPaymentBillingAsync(customerId, PaymentBilling))
                {
                    return(BadRequest("Bad request, could not create record!"));
                }
                else
                {
                    var location = _linkGenerator.GetPathByAction("Get",
                                                                  "PaymentBilling",
                                                                  new { Id = PaymentBilling.Id });

                    return(Created(location, _mapper.Map <PaymentBillingModel>(PaymentBilling)));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
Example #2
0
        public async Task <ActionResult <PaymentBillingModel> > Put(int customerId, int Id, PaymentBillingModel updatedModel)
        {
            try
            {
                var currentPaymentBilling = await _repository.GetPaymentBillingAsync(customerId, Id);

                if (currentPaymentBilling == null)
                {
                    return(NotFound($"Could not find PaymentBilling with Id of {Id}"));
                }

                _mapper.Map(updatedModel, currentPaymentBilling);

                if (await _repository.UpdatePaymentBillingAsync(customerId, currentPaymentBilling))
                {
                    return(_mapper.Map <PaymentBillingModel>(currentPaymentBilling));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }