public async Task <Domain.Items.Item> InsertItem(long categoryId, Domain.Items.Item item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var dbItem = item.ToDalOrNull(Items.DbEntities.ItemConverter.ToDalNew);

            var category = await _categories
                           .Include(c => c.Items)
                           .Where(c => c.Id == categoryId)
                           .SingleOrDefaultAsync();

            if (category == null)
            {
                return(null);
            }

            category.Items.Add(dbItem);

            await context.SaveChangesAsync();

            return(dbItem.ToDomainOrNull(Items.DbEntities.ItemConverter.ToDomain));
        }
Exemple #2
0
        public async Task <bool> Update(Domain.Items.Item item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            var dbItem = await _items
                         .Where(i => i.Id == item.Id)
                         .SingleOrDefaultAsync();

            if (dbItem == null)
            {
                return(false);
            }

            dbItem.SellPrice  = item.SellPrice;
            dbItem.StockPrice = item.StockPrice;
            dbItem.Stock      = item.Stock;

            await context.SaveChangesAsync();

            return(true);
        }