public int Update(Model.Class c) { string sql = "update [Class] set ClassName=@ClassName, Grade=@Grade, ClassTypeId=@ClassTypeId, HeadTeacherId=@HeadTeacherId"; int ret = db.Execute(sql, c); return(ret); }
public int Add(Model.Class c) { string sql = "insert into [Class](ClassName, Grade, ClassTypeId, HeadTeacherId)"; sql += " values(@ClassName, @Grade, @ClassTypeId, @HeadTeacherId)"; int ret = db.Execute(sql, c); return(ret); }
public Model.Class GetClass(int studentId) { string sql = "select c.ID,c.ClassName,c.Grade,c.ClassTypeId,c.HeadTeacherId,sc.ClassId,sc.StudentId from [Class] as c,[StudentClass] as sc"; sql += " where c.ID=sc.ClassId"; sql += " and sc.StudentId=" + studentId.ToString(); Model.Class cls = db.QuerySingleOrDefault <Model.Class>(sql); return(cls); }
/// <summary> /// /// </summary> /// <param name="cls"></param> public void Delete(Model.Class cls) { try { this.dbContext.Set <Model.Class>().Remove(cls); this.dbContext.SaveChanges(); } catch { throw; } }
/// <summary> /// /// </summary> /// <param name="cls"></param> public void Update(Model.Class cls) { try { //this.dbContext.Set<Model.Class>().Update(cls); this.dbContext.SaveChanges(); } catch { throw; } }
/// <summary> /// /// </summary> /// <param name="cls"></param> public void Add(Model.Class cls) { try { this.dbContext.Set <Model.Class>().Add(cls); this.dbContext.SaveChanges(); } catch { throw; } }
public void ChangeStudentClass(Model.NewStudent s, Model.Class newClass, Model.Class oldClass) { try { Model.ClassAssignment assignment = this.dbContext.Set <Model.ClassAssignment>().Single(x => x.ClassId == oldClass.ClassId && x.NewStudentId == s.NewStudentId); assignment.ClassId = newClass.ClassId; this.dbContext.SaveChanges(); } catch (Exception ex) { throw (ex); } }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="c"></param> public void RemoveStudentFromClass(Model.NewStudent s, Model.Class c) { try { Model.ClassAssignment assignment = this.dbContext.Set <Model.ClassAssignment>().Single(x => x.ClassId == c.ClassId && x.NewStudentId == s.NewStudentId); this.dbContext.Set <Model.ClassAssignment>().Remove(assignment); this.dbContext.SaveChanges(); } catch (Exception ex) { throw (ex); } }
/// <summary> /// /// </summary> /// <param name="s"></param> /// <param name="c"></param> public void AddStudentToClass(Model.NewStudent s, Model.Class c) { Model.ClassAssignment assignment = new Model.ClassAssignment(); assignment.ClassId = c.ClassId; assignment.NewStudentId = s.NewStudentId; try { this.dbContext.Set <Model.ClassAssignment>().Add(assignment); this.dbContext.SaveChanges(); } catch (Exception ex) { throw(ex); } }