public async Task <Brand> CreateBrandAsync(Brand brand)
        {
            if (brand.Id != default(long))
            {
                throw new InvalidOperationException("Id is generated by the database, should be empty.");
            }
            await _dbContext.Brands.AddAsync(brand);

            await _dbContext.SaveChangesAsync();

            return(brand);
        }
Пример #2
0
        public async Task <Watch> CreateWatchAsync(Watch watch)
        {
            if (watch.Id != default(long))
            {
                throw new InvalidOperationException("Id is generated by the database, should be empty.");
            }
            await _dbContext.Watches.AddAsync(watch);

            await _dbContext.SaveChangesAsync();

            await _dbContext.Entry(watch).Reference(x => x.Brand).LoadAsync();

            return(watch);
        }