Пример #1
0
        public async Task AddAsync(Data.Order order)
        {
            foreach (var item in order.OrderItems)
            {
                var comic = await _context.ComicBooks.FindAsync(item.ComicBookId);

                if (comic == null)
                {
                    throw new NullReferenceException("Invalid comic book Id");
                }

                if (comic.Quantity < item.Quantity)
                {
                    throw new InvalidOperationException(
                              $"Comic book with id: {comic.Id} does not have enough items to create your order (in stock {comic.Quantity}, your order {item.Quantity})");
                }

                comic.Quantity = comic.Quantity - item.Quantity;
                _context.Update(comic);
            }
            _context.Orders.Add(order);
            await _context.SaveChangesAsync();
        }
Пример #2
0
 public Task AddAsync(Data.Series series)
 {
     _context.Set <Data.Series>().Add(series);
     return(_context.SaveChangesAsync());
 }
Пример #3
0
 public Task AddAsync(Data.Publisher publisher)
 {
     _context.Publishers.Add(publisher);
     return(_context.SaveChangesAsync());
 }
Пример #4
0
 public Task AddAsync(Data.Artist artist)
 {
     _context.Set <Data.Artist>().Add(artist);
     return(_context.SaveChangesAsync());
 }
Пример #5
0
 public Task AddAsync(Data.ComicBook comic)
 {
     _context.Set <Data.ComicBook>().Add(comic);
     return(_context.SaveChangesAsync());
 }