public bool Add(MaterialTypeDto model) { try { if (string.IsNullOrEmpty(model.Name)) { throw new KnownException("信息不完善"); } using (var db = new BCEnterpriseContext()) { if (db.MaterialTypes.Any(n => n.Name.Equals(model.Name))) { throw new KnownException("已存在该名字"); } var profession = new ML.BC.EnterpriseData.Model.MaterialType() { Name = model.Name, Available = model.Avaliable }; db.MaterialTypes.Add(profession); if (db.SaveChanges() > 0) { return(true); } else { return(false); } } } catch (Exception e) { throw e; } }
public bool Update(MaterialTypeDto model) { try { if (string.IsNullOrEmpty(model.Name)) { throw new KnownException("信息不完善"); } using (var db = new BCEnterpriseContext()) { var temp = db.MaterialTypes.First( x => x.MaterialTypeID == model.MaterialTypeID); if (null == temp) { throw new KnownException("没有该记录!"); } temp.Available = model.Avaliable; temp.Name = model.Name; if (db.SaveChanges() > 0) { return(true); } else { return(false); } } } catch (Exception e) { throw e; } }