public bool CreateStudent(int id, string name, string rollNumber, string email, string phone, string address, string cid, int status) { try { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Student student = new Student { StudentId = id, StudentName = name, StudentRollNumber = rollNumber, StudentEmail = email, StudentPhone = phone, StudentAddress = address, ClassId = cid, StudentStatus = status, CreatedAt = DateTime.Now.Ticks, UpdatedAt = 0 }; context.Students.InsertOnSubmit(student); context.SubmitChanges(); return(true); } catch (Exception e) { } return(false); }
public bool UpdateAStudent(Student student) { try { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Student stu = context.Students.FirstOrDefault(s => s.StudentId == student.StudentId); if (stu != null) { stu.StudentId = student.StudentId; stu.ClassId = student.ClassId; stu.StudentName = student.StudentName; stu.StudentAddress = student.StudentAddress; stu.StudentEmail = stu.StudentEmail; stu.StudentPhone = student.StudentPhone; stu.StudentRollNumber = student.StudentRollNumber; stu.CreatedAt = student.CreatedAt; stu.UpdatedAt = student.UpdatedAt; stu.StudentStatus = student.StudentStatus; context.SubmitChanges(); return(true); } } catch (Exception e) { } return(false); }
public bool UpdateStudent(int id, string name, string rollNumber, string email, string phone, string address, string cid, int status) { try { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Student student = context.Students.FirstOrDefault(stu => stu.StudentId == id); if (student != null) { student.StudentName = name; student.StudentRollNumber = rollNumber; student.StudentEmail = email; student.StudentPhone = phone; student.StudentAddress = address; student.ClassId = cid; student.StudentStatus = status; student.UpdatedAt = DateTime.Now.Ticks; context.SubmitChanges(); return(true); } } catch (Exception e) { Console.WriteLine(e); throw; } return(false); }
public List <Class> GetClassFromTo(string ids, string ide) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); List <Class> list = context.Classes.Where(c => c.ClassId == ids && c.ClassId == ide).ToList(); foreach (var c in list) { c.Students.Clear(); } return(list); }
public Class GetClassById(string id) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Class cClass = context.Classes.FirstOrDefault(c => c.ClassId == id); if (cClass != null) { cClass.Students.Clear(); } return(cClass); }
public List <Class> GetAllCalsses() { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); List <Class> list = context.Classes.ToList(); foreach (var c in list) { c.Students.Clear(); } return(list); }
public List <Student> GetStudentsByClassId(string cId) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); List <Student> list = context.Students.Where(stu => stu.ClassId == cId).ToList(); foreach (var student in list) { student.ClassId = null; } return(list); }
public List <Student> GetStudentsFromTo(int id1, int id2) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); List <Student> list = context.Students.Where(stu => stu.StudentId >= id1 && stu.StudentId <= id2).ToList(); foreach (var student in list) { student.ClassId = null; } return(list); }
public Student GetStudentById(int id) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Student student = context.Students.FirstOrDefault(stu => stu.StudentId == id); if (student != null) { student.ClassId = null; } return(student); }
public bool DeleteClass(string id) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Class cClass = context.Classes.FirstOrDefault(c => c.ClassId == id); if (cClass != null) { context.Classes.DeleteOnSubmit(cClass); context.SubmitChanges(); return(true); } return(false); }
public List <Student> GetAllStudents() { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); List <Student> list = context.Students.ToList(); // Khử đệ quy : xóa classId khỏi từng thằng student. foreach (var student in list) { student.ClassId = null; } return(list); }
public bool DeleteAStudent(int id) { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Student student = context.Students.FirstOrDefault(stu => stu.StudentId == id); if (student != null) { context.Students.DeleteOnSubmit(student); context.SubmitChanges(); return(true); } return(false); }
public bool CreateAStudent(string json) { try { var student = JsonConvert.DeserializeObject <Student>(json); CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); context.Students.InsertOnSubmit(student); context.SubmitChanges(); return(true); } catch (Exception e) { } return(false); }
public bool CreateClass(string id, string name, string rollNumber, int status) { try { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Class cClass = new Class { ClassId = id, ClassName = name, ClassRollNumber = rollNumber, ClassStatus = status, CreatedAt = DateTime.Now.Ticks }; context.Classes.InsertOnSubmit(cClass); context.SubmitChanges(); return(true); } catch (Exception e) { } return(false); }
public bool UpdateClass(string id, string name, string rollNumber, int status) { try { CSDLAptechStudentsDataContext context = new CSDLAptechStudentsDataContext(); Class cClass = context.Classes.FirstOrDefault(c => c.ClassId == id); if (cClass != null) { cClass.ClassName = name; cClass.ClassRollNumber = rollNumber; cClass.ClassStatus = status; cClass.UpdatedAt = DateTime.Now.Ticks; context.SubmitChanges(); return(true); } } catch (Exception e) { } return(false); }