Beispiel #1
0
 private bool Validate(Components componets)
 {
     using (var db = GetDataContext())
     {
         var entity = db.Components.FirstOrDefault(e => e.Type == componets.Type && e.Brand.ToUpper() == componets.Brand.ToUpper() && e.Specification.ToUpper() == componets.Specification.ToUpper());
         return entity == null ? true : false;
     }
 }
Beispiel #2
0
 public int Add(Components components)
 {
     if (!Validate(components))
     {
         throw new ArgumentException("存在相同类型、品牌、规格的部件");
     }
     using (var db = GetDataContext())
     {
         db.Components.Add(components);
         db.SaveChanges();
         return components.ID;
     }
 }