public async Task <IActionResult> Put(int id, [FromBody] ServiceItemsSetDto updatedServiceItemsSetDto) { if (!ModelState.IsValid || updatedServiceItemsSetDto.Id != id) { return(BadRequest()); } try { var updatedServiceItemsSet = await _context.ServiceItemsSets.SingleAsync(g => g.Id == id); Mapper.Map(updatedServiceItemsSetDto, updatedServiceItemsSet); _context.Entry(updatedServiceItemsSet).OriginalValues["RowVersion"] = updatedServiceItemsSetDto.RowVersion; _context.ServiceItemsSets.Update(updatedServiceItemsSet); await _context.SaveChangesAsync(); _cache.Remove(IMemoryCacheKeys.customersCacheKey); } catch (DbUpdateConcurrencyException exception) { return(Conflict(exception)); } catch (Exception exception) { return(BadRequest(exception)); } return(new NoContentResult()); }
public async Task <IActionResult> Post([FromBody] ServiceItemsSetDto newServiceItemsSetDto) { if (!ModelState.IsValid) { return(BadRequest()); } var newServiceItemsSet = Mapper.Map <ServiceItemsSet>(newServiceItemsSetDto); try { _context.ServiceItemsSets.Add(newServiceItemsSet); await _context.SaveChangesAsync(); _cache.Remove(IMemoryCacheKeys.customersCacheKey); } catch (Exception exception) { return(BadRequest(exception)); } return(CreatedAtRoute("", new { id = newServiceItemsSet.Id }, Mapper.Map <ServiceItemsSetDto>(newServiceItemsSet))); }