コード例 #1
0
        public async Task <ActionResult <CreditNoteLineModel> > Post(int CreditNoteId, CreditNoteLineModel model)
        {
            try
            {
                //Make sure CreditNoteLineId is not already taken
                var existing = await _repository.GetCreditNoteLineAsync(CreditNoteId, model.Id);

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

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

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

                    return(Created(location, _mapper.Map <CreditNoteLineModel>(CreditNoteLine)));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }
        }
コード例 #2
0
        public async Task <ActionResult <CreditNoteLineModel> > Put(int CreditNoteId, int Id, CreditNoteLineModel updatedModel)
        {
            try
            {
                var currentCreditNoteLine = await _repository.GetCreditNoteLineAsync(CreditNoteId, Id);

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

                _mapper.Map(updatedModel, currentCreditNoteLine);

                if (await _repository.UpdateCreditNoteLineAsync(CreditNoteId, currentCreditNoteLine))
                {
                    return(_mapper.Map <CreditNoteLineModel>(currentCreditNoteLine));
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"));
            }

            return(BadRequest());
        }