public async Task AddShop(ShopDto shopData)
        {
            using (var db = new BuckwheatContext())
            {
                Shop shop = mapper.Map <ShopDto, Shop>(shopData);
                shop.Lots = null;
                await db.Shops.AddAsync(shop);

                await db.SaveChangesAsync();
            }
        }
Esempio n. 2
0
        public async Task AddPrice(PriceDto priceData, int lotId)
        {
            using (var db = new BuckwheatContext())
            {
                Lot lot = await db.Lots.FirstOrDefaultAsync(x => x.Id == lotId);

                if (lot == null)
                {
                    throw new ArgumentException($"Lot with id {lotId} was not found in the database.");
                }
                Price price = mapper.Map <PriceDto, Price>(priceData);
                price.Lot = lot;

                await db.Prices.AddAsync(price);

                await db.SaveChangesAsync();
            }
        }
Esempio n. 3
0
        public async Task <LotDto> AddLot(LotDto lotData, int shopId)
        {
            using (var db = new BuckwheatContext())
            {
                Shop shop = await db.Shops.FirstOrDefaultAsync(x => x.Id == shopId);

                if (shop == null)
                {
                    throw new ArgumentException($"Shop with id {shopId} was not found in the database.");
                }
                Lot lot = mapper.Map <LotDto, Lot>(lotData);
                lot.Shop = shop;

                await db.Lots.AddAsync(lot);

                await db.SaveChangesAsync();

                return(mapper.Map <Lot, LotDto>(lot));
            }
        }