/// <summary> /// 保存数据 /// </summary> public virtual void SaveImportData(IEnumerable <Spl_TestStudentsModel> list) { try { using (DBContainer db = new DBContainer()) { foreach (var model in list) { Spl_TestStudents entity = new Spl_TestStudents(); entity.Id = 0; entity.ClassId = model.ClassId; entity.Name = model.Name; entity.Avg = model.Avg; entity.Photo = model.Photo; entity.Enable = model.Enable; entity.CreateTime = ResultHelper.NowTime; db.Spl_TestStudents.Add(entity); } db.SaveChanges(); } } catch (Exception ex) { throw; } }
public virtual Spl_TestStudentsModel GetById(object id) { if (IsExists(id)) { Spl_TestStudents entity = m_Rep.GetById(id); Spl_TestStudentsModel model = new Spl_TestStudentsModel(); model.Id = entity.Id; model.ClassId = entity.ClassId; model.Name = entity.Name; model.Avg = entity.Avg; model.Photo = entity.Photo; model.Enable = entity.Enable; model.CreateTime = entity.CreateTime; return(model); } else { return(null); } }
public virtual bool Create(ref ValidationErrors errors, Spl_TestStudentsModel model) { try { Spl_TestStudents entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new Spl_TestStudents(); entity.Id = model.Id; entity.ClassId = model.ClassId; entity.Name = model.Name; entity.Avg = model.Avg; entity.Photo = model.Photo; entity.Enable = model.Enable; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_TestStudentsModel model) { try { Spl_TestStudents entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.ClassId = model.ClassId; entity.Name = model.Name; entity.Avg = model.Avg; entity.Photo = model.Photo; entity.Enable = model.Enable; entity.CreateTime = model.CreateTime; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }