public async Task <HiveSectionProduct> CreateHiveSectionProductAsync(UpdateHiveSectionProductRequest createRequest) { var dbStoreItems = await _context.Items.Where(p => p.ProductId == createRequest.ProductId && p.HiveSectionId == createRequest.HiveSectionId).ToArrayAsync(); if (dbStoreItems.Length > 0) { throw new RequestedResourceHasConflictException("ProductId"); } var dbStoreItem = Mapper.Map <UpdateHiveSectionProductRequest, DbItem>(createRequest); _context.Items.Add(dbStoreItem); await _context.SaveChangesAsync(); return(Mapper.Map <HiveSectionProduct>(dbStoreItem)); }
public async Task <HiveSectionProduct> UpdateHiveSectionProductAsync(int productId, UpdateHiveSectionProductRequest updateRequest) { var dbStoreItems = await _context.Items.Where(p => p.ProductId == updateRequest.ProductId && p.Id != productId).ToArrayAsync(); if (dbStoreItems.Length > 0) { throw new RequestedResourceHasConflictException("productId"); } dbStoreItems = await _context.Items.Where(p => p.Id == productId).ToArrayAsync(); if (dbStoreItems.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbStoreItem = dbStoreItems[0]; Mapper.Map(updateRequest, dbStoreItem); await _context.SaveChangesAsync(); return(Mapper.Map <HiveSectionProduct>(dbStoreItem)); }