public async Task<bool> Update(VehicleModel item) { var model = await IdExist(item.Id); model.Name = item.Name; model.BrandId = await BrandExist(item.BrandId); model.TypeId = await TypeExist(item.TypeId); if (item.Year != null) model.Year = item.Year; _db.Entry(model).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } return true; }
public async Task<VehicleModel> Add(VehicleModel item) { var model = new VehicleModel { Name = item.Name, BrandId = await BrandExist(item.BrandId), TypeId = await TypeExist(item.TypeId), }; if (item.Year != null) model.Year = item.Year; model = _db.VehicleModels.Add(model); try { await _db.SaveChangesAsync(); return model; } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } }