Ejemplo n.º 1
0
        public bool UpdateStudent(Student s)
        {
            var sDB = GetStudent(s.Id);

            if (sDB == null)
            {
                throw new Exception("Student not found");
            }
            var db = new AppEfDbContext();

            sDB.Firstname  = s.Firstname;
            sDB.Lastname   = s.Lastname;
            sDB.Gpa        = s.Gpa;
            sDB.Sat        = s.Sat;
            sDB.IsFulltime = s.IsFulltime;
            sDB.MajorId    = s.MajorId;
            var mid = db.Majors.Find(s.Major.Id);

            if (mid == null)
            {
                return(false);
            }
            else
            {
                db.Students.Update(sDB);
                db.SaveChanges();
                return(true);
            }
        }
Ejemplo n.º 2
0
        public bool UpdateStudent(Student s)
        {
            var db  = new AppEfDbContext();
            var sDb = GetStudent(s.Id);

            if (sDb == null)
            {
                throw new Exception("Student cannot be found");
            }
            sDb.Firstname  = s.Firstname;
            sDb.Lastname   = s.Lastname;
            sDb.Gpa        = s.Gpa;
            sDb.Sat        = s.Sat;
            sDb.IsFulltime = s.IsFulltime;
            sDb.MajorId    = s.MajorId;
            if (s.MajorId != null)
            {
                var major = db.Majors.Find(s.MajorId);
                if (major == null)
                {
                    return(false);
                }
            }
            //db.Update<Student>(sDb);
            db.Students.Update(sDb);
            db.SaveChanges();
            return(true);
        }
Ejemplo n.º 3
0
        public bool RemoveStudent(Student s)
        {
            var db  = new AppEfDbContext();
            var rDB = GetStudent(s.Id);

            if (rDB == null)
            {
                throw new Exception("Student does not exist!");
            }
            rDB.Firstname  = s.Firstname;
            rDB.Lastname   = s.Lastname;
            rDB.Gpa        = s.Gpa;
            rDB.Sat        = s.Sat;
            rDB.IsFulltime = s.IsFulltime;
            rDB.MajorId    = s.MajorId;
            var major = db.Majors.Find(s.MajorId);

            if (major == null)
            {
                return(false);
            }
            db.Remove <Student>(rDB);
            db.SaveChanges();
            return(true);
        }
Ejemplo n.º 4
0
        public bool DeleteStudent(Student student)
        {
            var del = GetStudent(student.Id);
            var db  = new AppEfDbContext();

            if (del == null)
            {
                return(false);
            }
            db.Students.Remove(del);
            db.SaveChanges();
            return(true);
        }
Ejemplo n.º 5
0
        public bool DeleteStudent(Student dS)
        {
            var db  = new AppEfDbContext();
            var sDb = GetStudent(dS.Id);

            if (sDb == null)
            {
                return(false);
            }
            db.Students.Remove(sDb);
            db.SaveChanges();
            return(true);
        }
Ejemplo n.º 6
0
        public bool DeleteStudentById(int id)
        {
            var del = GetStudent(id);

            if (del == null)
            {
                return(false);
            }
            var db = new AppEfDbContext();

            db.Students.Remove(del);
            db.SaveChanges();
            return(true);
        }
Ejemplo n.º 7
0
        public bool InsertStudent(Student student)
        {
            var db = new AppEfDbContext();

            student.Id = 0;
            if (student.MajorId != null)
            {
                var major = db.Majors.Find(student.MajorId);
                if (major == null)
                {
                    return(false);
                }
            }
            db.Students.Add(student);
            db.SaveChanges();
            return(true);
        }