コード例 #1
0
        public async Task DeleteShopAsync(int id)
        {
            var shop = await this.modelContext.Shops.FindAsync(id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            this.modelContext.Shops.Remove(shop);
            await this.modelContext.SaveChangesAsync();
        }
コード例 #2
0
        public async Task <byte[]> GetCoverPictureAsync(int id)
        {
            var shop = await this.modelContext.Shops
                       .AsNoTracking()
                       .Include(s => s.CoverPicture)
                       .FirstOrDefaultAsync(s => s.Id == id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            return(shop.CoverPicture);
        }
コード例 #3
0
        public async Task <ShopInfoDto> GetShopAsync(int id)
        {
            var shop = await this.modelContext.Shops
                       .Include(s => s.CoverPicture)
                       .AsNoTracking()
                       .FirstOrDefaultAsync(s => s.Id == id);

            if (shop == null)
            {
                throw ShopException.ShopIdNotFoundException(id);
            }

            return(new ShopInfoDto()
            {
                Id = shop.Id,
                Description = shop.Description,
                Discount = shop.Discount,
                LinkToSite = shop.LinkToSite,
                Location = shop.Location,
                Name = shop.Name,
                PhoneNumber = shop.PhoneNumber
            });
        }
コード例 #4
0
        public async Task <Shop> ChangeShopDataAsync(int shopId, Shop shop)
        {
            if (shop == null)
            {
                throw new ArgumentNullException("shop cannot be null");
            }

            var updateShop = await this.modelContext.Shops.FindAsync(shopId);

            if (updateShop == null)
            {
                throw ShopException.ShopIdNotFoundException(shopId);
            }

            updateShop.SetName(shop.Name);
            updateShop.SetLinkToSite(shop.LinkToSite);
            updateShop.SetDescription(shop.Description);
            updateShop.SetDiscount(shop.Discount);
            updateShop.SetLocation(shop.Location);
            updateShop.SetPhoneNumber(shop.PhoneNumber);
            updateShop.SetCoverPicture(shop.CoverPicture);

            await using var transaction = await this.modelContext.Database.BeginTransactionAsync();

            await this.modelContext.SaveChangesAsync();

            if (shop.CoverPicture != null)
            {
                var fileId = BuildFileIdFromShopId(shop.Id);
                await this.fileStorageService.StoreFileAsync(fileId, updateShop.CoverPicture);
            }

            await transaction.CommitAsync();

            return(updateShop);
        }