public async Task <ActionResult <DtoWhistle> > Put(int whistleID, DtoWhistle WhistleInput) { try { var oldWhistle = await _repository.GetWhistle(whistleID); if (oldWhistle == null) { return(NotFound("")); } WhistleInput.Modified = DateTime.Now; WhistleInput.Created = oldWhistle.Created; _mapper.Map(WhistleInput, oldWhistle); if (await _repository.SaveChangesAsync()) { return(_mapper.Map <DtoWhistle>(oldWhistle)); } } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "")); } return(BadRequest()); }
public async Task <ActionResult <DtoWhistle> > Post(DtoWhistle WhistleInput) { try { Whistle W = _mapper.Map <Whistle>(WhistleInput); _repository.Add(W); if (await _repository.SaveChangesAsync()) { return(Created($"/api/whistle/", _mapper.Map <DtoWhistle>(W))); } } catch { return(this.StatusCode(StatusCodes.Status500InternalServerError, "")); } return(BadRequest()); }