public bool SaveStudent(StudentDTO dto) { using (var ctx = new SMSContext()) { if (dto.StudentID > 0) { //Update var query = from p in ctx.Students where p.StudentID == dto.StudentID select p; //Now query will be executed on DB and will return result var result = query.FirstOrDefault(); if (result != null) { result.StudentName = dto.StudentName; result.FatherName = dto.FatherName; } } else { ctx.Students.Add(dto); } ctx.SaveChanges(); } return true; }
public StudentDTO GetById(int id) { using (var ctx = new SMSContext()) { return ctx.Students.Where(p => p.StudentID == id).FirstOrDefault(); } }
public bool SaveTeacher(TeacherDTO dto) { using (var ctx = new SMSContext()) { if (dto.TID > 0) { //Update var query = from p in ctx.Teachers where p.TID == dto.TID select p; //Now query will be executed on DB and will return result var result = query.FirstOrDefault(); if (result != null) { result.Name = dto.Name; result.Subject = dto.Subject; } } else { ctx.Teachers.Add(dto); } ctx.SaveChanges(); } return true; }
public TeacherDTO GetById(int id) { using (var ctx = new SMSContext()) { return ctx.Teachers.Where(p => p.TID == id).FirstOrDefault(); } }
public void RemoveById(int id) { using (var ctx = new SMSContext()) { var result = ctx.Students.Where(p => p.StudentID == id).FirstOrDefault(); if (result != null) { ctx.Students.Remove(result); ctx.SaveChanges(); } } }
public void RemoveById(int id) { using (var ctx = new SMSContext()) { var result = ctx.Teachers.Where(p => p.TID == id).FirstOrDefault(); if (result != null) { ctx.Teachers.Remove(result); ctx.SaveChanges(); } } }
public List <TeacherDTO> GetAll() { using (var ctx = new SMSContext()) { //ToList() //First() //FirstOrDefault(); //Single() //SignleOrDefualt(); return(ctx.Teachers.ToList()); } }
public List<StudentDTO> GetAll() { using (var ctx = new SMSContext()) { //ToList() //First() //FirstOrDefault(); //Single() //SignleOrDefualt(); return ctx.Students.ToList(); } }
public List <Users> GetAllUsers() { //Using handles the disposal by itself using (var ctx = new SMSContext()) { //LINQ builder approach var list = ctx.Users.ToList(); /* * var query = from p in ctx.Users * select p; * * var list = query.ToList(); */ return(list); } }
public bool VerifyLogin(String Login, String Password) { using (var ctx = new SMSContext()) { var query = from p in ctx.Users where p.Login == Login && p.Password == Password select p; var cnt = query.Count(); if (cnt > 0) { return(true); } else { return(false); } } }
public Users GetUserById(int userid) { using (var ctx = new SMSContext()) { //LINQ to Entities approach //This is just query object in memory var query = from p in ctx.Users where p.UserID == userid select p; //Now query will be executed on DB and will return result var result = query.FirstOrDefault(); //ctx.Users.Where(p => p.UserID == userid).FirstOrDefault(); return(result); } }
public bool DeleteUserById(int userid) { using (var ctx = new SMSContext()) { //LINQ to Entities approach //This is just query object in memory var query = from p in ctx.Users where p.UserID == userid select p; //Now query will be executed on DB and will return result var result = query.FirstOrDefault(); if (result != null) { ctx.Users.Remove(result); ctx.SaveChanges(); } return(true); } }