public async Task <IActionResult> Update(int id, [FromBody] SaveCounterResource counterResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var counter = await counterRepository.GetOne(id); if (counter == null) { return(NotFound()); } counter = mapper.Map(counterResource, counter); counterRepository.Update(counter); if (await unitOfWork.CompleteAsync() == false) { throw new Exception(message: $"Updating counter {id} failed on save"); } counter = await counterRepository.GetOne(counter.Id); var result = mapper.Map <Counter, ViewCounterResource>(counter); return(Ok(result)); }
public async Task <IActionResult> Create([FromBody] SaveCounterResource counterResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var counter = mapper.Map <SaveCounterResource, Counter>(counterResource); counterRepository.Add(counter); if (await unitOfWork.CompleteAsync() == false) { throw new Exception(message: $"Create New Counter failed on Save"); } counter = await counterRepository.GetOne(counter.Id); var result = mapper.Map <Counter, ViewCounterResource>(counter); return(Ok(result)); }