/// <inheritdoc/> public async Task <Shop> CreateShopAsync(UpdateShopRequest createRequest) { var dbShops = await _context.Shops.Where(c => c.Code == createRequest.Code).ToArrayAsync(); if (dbShops.Length > 0) { throw new RequestedResourceHasConflictException("code"); } var dbShop = Mapper.Map <UpdateShopRequest, DbShop>(createRequest); _context.Shops.Add(dbShop); await _context.SaveChangesAsync(); return(Mapper.Map <Shop>(dbShop)); }
/// <inheritdoc/> public async Task <Shop> UpdateShopAsync(int shopId, UpdateShopRequest updateRequest) { var dbShops = await _context.Shops.Where(c => c.Code == updateRequest.Code && c.Id != shopId).ToArrayAsync(); if (dbShops.Length > 0) { throw new RequestedResourceHasConflictException("code"); } dbShops = await _context.Shops.Where(c => c.Id == shopId).ToArrayAsync(); if (dbShops.Length == 0) { throw new RequestedResourceNotFoundException(); } var dbShop = dbShops[0]; Mapper.Map(updateRequest, dbShop); await _context.SaveChangesAsync(); return(Mapper.Map <Shop>(dbShop)); }