public async Task <ActionResult <TaxInfoModel> > Post(int customerId, TaxInfoModel model) { try { //Make sure TaxInfoId is not already taken var existing = await _repository.GetTaxInfoAsync(customerId, model.Id); if (existing != null) { return(BadRequest("TaxInfo Id in Use")); } //map var TaxInfo = _mapper.Map <TaxInfo>(model); //save and return if (!await _repository.StoreNewTaxInfoAsync(customerId, TaxInfo)) { return(BadRequest("Bad request, could not create record!")); } else { var location = _linkGenerator.GetPathByAction("Get", "TaxInfo", new { TaxInfo.Id }); return(Created(location, _mapper.Map <TaxInfoModel>(TaxInfo))); } } catch (Exception e) { _logger.LogError(e, e.Message); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
public async Task <ActionResult <TaxInfoModel> > Put(int customerId, int Id, TaxInfoModel updatedModel) { try { var currentTaxInfo = await _repository.GetTaxInfoAsync(customerId, Id); if (currentTaxInfo == null) { return(NotFound($"Could not find TaxInfo with Id of {Id}")); } _mapper.Map(updatedModel, currentTaxInfo); if (await _repository.UpdateTaxInfoAsync(customerId, currentTaxInfo)) { return(_mapper.Map <TaxInfoModel>(currentTaxInfo)); } } catch (Exception e) { _logger.LogError(e, e.Message); return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }