public async Task<bool> Update(VehicleType item) { if (item.HeadId == null) throw new ArgumentNullException("HeadId"); var type = await IdExist(item.Id); type.Name = item.Name; type.HeadId = await HeadExist(item.HeadId.Value); _db.Entry(type).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } return true; }
public async Task<VehicleType> Add(VehicleType item) { if (item.HeadId == null) throw new ArgumentNullException("HeadId"); var type = new VehicleType { Name = item.Name, HeadId = await HeadExist(item.HeadId.Value) }; type = _db.VehicleTypes.Add(type); try { await _db.SaveChangesAsync(); return type; } catch (DbUpdateConcurrencyException exception) { throw new DbUpdateConcurrencyException(exception.Message); } }