public async Task <IActionResult> Put(int id, [FromBody] SubscriptionServiceItemDto updatedSubscriptionServiceItemDto) { if (!ModelState.IsValid || updatedSubscriptionServiceItemDto.Id != id) { return(BadRequest()); } try { var updatedSubscriptionServiceItem = await _context.ServiceItems.OfType <SubscriptionServiceItem>().SingleAsync(g => g.Id == id); Mapper.Map(updatedSubscriptionServiceItemDto, updatedSubscriptionServiceItem); _context.Entry(updatedSubscriptionServiceItem).OriginalValues["RowVersion"] = updatedSubscriptionServiceItemDto.RowVersion; _context.ServiceItems.Update(updatedSubscriptionServiceItem); 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] SubscriptionServiceItemDto newSubscriptionServiceItemDto) { if (!ModelState.IsValid) { return(BadRequest()); } var newSubscriptionServiceItem = Mapper.Map <SubscriptionServiceItem>(newSubscriptionServiceItemDto); newSubscriptionServiceItem.IsArchived = false; try { _context.ServiceItems.Add(newSubscriptionServiceItem); await _context.SaveChangesAsync(); _cache.Remove(IMemoryCacheKeys.customersCacheKey); } catch (Exception exception) { return(BadRequest(exception)); } return(CreatedAtRoute("", new { id = newSubscriptionServiceItem.Id }, Mapper.Map <SubscriptionServiceItemDto>(newSubscriptionServiceItem))); }