コード例 #1
0
        public async Task<bool> Update(VehicleBrand item)
        {
            var brand = await IdExist(item.Id);

            brand.Name = item.Name;

            _db.Entry(brand).State = EntityState.Modified;
            try
            {
                await _db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }

            return true;
        }
コード例 #2
0
        public async Task<VehicleBrand> Add(VehicleBrand item)
        {
            var brand = new VehicleBrand
            {
                Name = item.Name,
            };

            brand = _db.VehicleBrands.Add(brand);
            try
            {
                await _db.SaveChangesAsync();
                return brand;
            }
            catch (DbUpdateConcurrencyException exception)
            {
                throw new DbUpdateConcurrencyException(exception.Message);
            }
        }