public int Update()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    if (Id >= 0)
                    {
                        tblProgram program = dc.tblPrograms.Where(s => s.Id == Id).FirstOrDefault();
                        if (program != null)
                        {
                            program.Description  = this.Description;
                            program.DegreeTypeId = this.DegreeTypeId;
                            program.ImagePath    = this.ImagePath;


                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Row was not found");
                        }
                    }
                    else
                    {
                        throw new Exception("ID is not set");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public static List <Advisor> Load(int progDecId)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    List <Advisor> advisors = new List <Advisor>();

                    var results = (from a in dc.tblAdvisors
                                   join pda in dc.tblProgDecAdvisors on a.Id equals pda.AdvisorId
                                   where pda.ProgDecId == progDecId
                                   select new
                    {
                        a.Id,
                        a.Name
                    }).ToList();

                    results.ForEach(r => advisors.Add(new Advisor {
                        Id = r.Id, Name = r.Name
                    }));
                    return(advisors);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        public void InsertTest()
        {
            ProgDecEntities dc = new ProgDecEntities();

            // Dimension and instatiate new row
            tblStudent newrow = new tblStudent();

            // set properties for the new record
            newrow.Id        = -99;
            newrow.FirstName = "Bart";
            newrow.LastName  = "Simpson";
            newrow.StudentId = "123999999";

            // Insert the row into the database
            dc.tblStudents.Add(newrow);

            // Commit the changes
            dc.SaveChanges();

            tblStudent student = (from p in dc.tblStudents
                                  where p.Id == -99
                                  select p).FirstOrDefault();

            Assert.AreSame(newrow, student);    // one way to test if a new row was successfully added
        }
        public int Update()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    if (Id >= 0)
                    {
                        tblStudent student = dc.tblStudents.Where(s => s.Id == Id).FirstOrDefault();
                        if (student != null)
                        {
                            student.FirstName = this.FirstName;
                            student.LastName  = this.LastName;
                            student.StudentId = this.StudentId;

                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Row was not found");
                        }
                    }
                    else
                    {
                        throw new Exception("ID is not set");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public int Update()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    if (Id >= 0)
                    {
                        tblProgDec progDec = dc.tblProgDecs.Where(p => p.Id == Id).FirstOrDefault();
                        if (progDec != null)
                        {
                            progDec.StudentId  = this.StudentId;
                            progDec.ProgramId  = this.ProgramId;
                            progDec.ChangeDate = DateTime.Now;

                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("Row was not found");
                        }
                    }
                    else
                    {
                        throw new Exception("ID is not set");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 6
0
        public static int Insert(out int id,
                                 string firstName,
                                 string lastName,
                                 string studentId)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblStudent newrow = new tblStudent();

                    newrow.FirstName = firstName;
                    newrow.LastName  = lastName;
                    newrow.StudentId = studentId;
                    newrow.Id        = dc.tblStudents.Any() ? dc.tblStudents.Max(s => s.Id) + 1 : 1;
                    id = newrow.Id;

                    dc.tblStudents.Add(newrow);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int Insert(out int id, string description)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblDegreeType newrow = new tblDegreeType();

                    newrow.Description = description;
                    newrow.Id          = dc.tblDegreeTypes.Any() ? dc.tblDegreeTypes.Max(dt => dt.Id) + 1 : 1;
                    id = newrow.Id;

                    //if(dc.tblDegreeTypes.Any())
                    //{
                    //    newrow.Id = dc.tblDegreeTypes.Max(dt => dt.Id) + 1;
                    //}
                    //else
                    //{
                    //    newrow.Id = 1;
                    //}

                    dc.tblDegreeTypes.Add(newrow);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 8
0
 public int Delete()
 {
     try
     {
         using (ProgDecEntities dc = new ProgDecEntities())
         {
             if (Id >= 0)
             {
                 tblProgDec progDec = dc.tblProgDecs.Where(p => p.Id == Id).FirstOrDefault();
                 if (progDec != null)
                 {
                     dc.tblProgDecs.Remove(progDec);
                     return(dc.SaveChanges());
                 }
                 else
                 {
                     throw new Exception("Row was not found");
                 }
             }
             else
             {
                 throw new Exception("ID is not set");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 9
0
        public void LoadByProgDecId(int progDecId)
        {
            try
            {
                ProgDecEntities dc = new ProgDecEntities();

                var advisors = from pda in dc.tblProgDecAdvisors
                               join a in dc.tblAdvisors on pda.AdvisorId equals a.Id
                               where pda.ProgDecId == progDecId
                               select new
                {
                    a.Id,
                    a.Name
                };

                foreach (var advisor in advisors)
                {
                    Advisor a = new Advisor(advisor.Id, advisor.Name);
                    this.Add(a);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public static DegreeType LoadById(int id)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblDegreeType row = (from dt in dc.tblDegreeTypes
                                         where dt.Id == id
                                         select dt).FirstOrDefault();

                    if (row != null)
                    {
                        return new DegreeType {
                                   Id = row.Id, Description = row.Description
                        }
                    }
                    ;
                    else
                    {
                        throw new Exception("Row was not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void LoadById()
 {
     try
     {
         using (ProgDecEntities dc = new ProgDecEntities())
         {
             if (Id >= 0)
             {
                 tblStudent student = dc.tblStudents.Where(s => s.Id == Id).FirstOrDefault();
                 if (student != null)
                 {
                     this.Id        = student.Id;
                     this.FirstName = student.FirstName;
                     this.LastName  = student.LastName;
                     this.StudentId = student.StudentId;
                 }
                 else
                 {
                     throw new Exception("Row was not found");
                 }
             }
             else
             {
                 throw new Exception("Id was not set");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 12
0
        public static int Insert(out int id,
                                 int progDecId,
                                 int studentId)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblProgDec newrow = new tblProgDec();

                    newrow.ProgramId  = progDecId;
                    newrow.StudentId  = studentId;
                    newrow.ChangeDate = DateTime.Now;
                    newrow.Id         = dc.tblProgDecs.Any() ? dc.tblProgDecs.Max(dt => dt.Id) + 1 : 1;
                    id = newrow.Id;


                    dc.tblProgDecs.Add(newrow);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 13
0
        public static Student LoadById(int id)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblStudent row = (from s in dc.tblStudents
                                      where s.Id == id
                                      select s).FirstOrDefault();

                    if (row != null)
                    {
                        return new Student
                               {
                                   Id        = row.Id,
                                   FirstName = row.FirstName,
                                   LastName  = row.LastName,
                                   StudentId = row.StudentId
                               }
                    }
                    ;
                    else
                    {
                        throw new Exception("Row was not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public int Update()
 {
     try
     {
         using (ProgDecEntities dc = new ProgDecEntities())
         {
             if (Id >= 0)
             {
                 tblDegreeType degreeType = dc.tblDegreeTypes.Where(p => p.Id == Id).FirstOrDefault();
                 if (degreeType != null)
                 {
                     degreeType.Description = this.Description;
                     return(dc.SaveChanges());
                 }
                 else
                 {
                     throw new Exception("Row was not found");
                 }
             }
             else
             {
                 throw new Exception("ID is not set");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
 public void LoadById()
 {
     try
     {
         using (ProgDecEntities dc = new ProgDecEntities())
         {
             if (Id >= 0)
             {
                 tblDegreeType degreeType = dc.tblDegreeTypes.Where(p => p.Id == Id).FirstOrDefault();
                 if (degreeType != null)
                 {
                     this.Id          = degreeType.Id;
                     this.Description = degreeType.Description;
                 }
                 else
                 {
                     throw new Exception("Row was not found");
                 }
             }
             else
             {
                 throw new Exception("Id was not set");
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 16
0
 public static List <Student> Load()
 {
     try
     {
         using (ProgDecEntities dc = new ProgDecEntities())
         {
             List <Student> students = new List <Student>();
             foreach (tblStudent s in dc.tblStudents)
             {
                 students.Add(new Student
                 {
                     Id        = s.Id,
                     FirstName = s.FirstName,
                     LastName  = s.LastName,
                     StudentId = s.StudentId
                 });
             }
             return(students);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 17
0
        public void Load()
        {
            ProgDecEntities dc = new ProgDecEntities();

            foreach (tblAdvisor advisor in dc.tblAdvisors)
            {
                Advisor a = new Advisor(advisor.Id, advisor.Name);
                Add(a);
            }
        }
Esempio n. 18
0
 public static List <Advisor> Load()
 {
     using (ProgDecEntities dc = new ProgDecEntities())
     {
         List <Advisor> advisors = new List <Advisor>();
         dc.tblAdvisors.ToList().ForEach(r => advisors.Add(new Advisor {
             Id = r.Id, Name = r.Name
         }));
         return(advisors);
     }
 }
Esempio n. 19
0
        public void LoadTest()
        {
            ProgDecEntities dc = new ProgDecEntities();

            // SELECT * FROM tblProgram - LINQ SQL
            var results = from Program in dc.tblPrograms
                          select Program;

            int expected = 17;
            int actual   = results.Count();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 20
0
        public void LoadTest()
        {
            ProgDecEntities dc = new ProgDecEntities();

            // SELECT * FROM tblProgDec - LINQ SQL
            var results = from progdec in dc.tblProgDecs
                          select progdec;

            int expected = 5;
            int actual   = results.Count();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 21
0
        public void LoadTest()
        {
            ProgDecEntities dc = new ProgDecEntities();

            // SELECT * FROM tblStudent - LINQ SQL
            var results = from student in dc.tblStudents
                          select student;

            int expected = 4;
            int actual   = results.Count();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 22
0
        public void LoadTest()
        {
            ProgDecEntities dc = new ProgDecEntities();

            // SELECT * FROM tblDegreeType - LINQ SQL
            var results = from degreetype in dc.tblDegreeTypes
                          select degreetype;

            int expected = 3;
            int actual   = results.Count();

            Assert.AreEqual(expected, actual);
        }
        public static void Add(int progdecId, int advisorId)
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                tblProgDecAdvisor pda = new tblProgDecAdvisor();
                pda.Id        = dc.tblProgDecAdvisors.Any() ? dc.tblProgDecAdvisors.Max(p => p.Id) + 1 : 1;
                pda.ProgDecId = progdecId;
                pda.AdvisorId = advisorId;

                dc.tblProgDecAdvisors.Add(pda);
                dc.SaveChanges();
            }
        }
        public static void Delete(int progdecId, int advisorId)
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                tblProgDecAdvisor pda = dc.tblProgDecAdvisors.FirstOrDefault(p => p.ProgDecId == progdecId && p.AdvisorId == advisorId);

                if (pda != null)
                {
                    dc.tblProgDecAdvisors.Remove(pda);
                    dc.SaveChanges();
                }
            }
        }
        public void LoadTest()
        {
            // data context
            // make var of data type of data context
            // [data type]  [data context]  = new [data type object]
            ProgDecEntities dc = new ProgDecEntities();

            var programs = from p in dc.tblPrograms
                           select p;

            dc = null; // clean up, because the same var name is being used elsewhere
            Assert.IsTrue(programs.Count() > 0);
        }
Esempio n. 26
0
        public static Models.ProgDec LoadById(int id)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    var progdec = (from pd in dc.tblProgDecs
                                   join s in dc.tblStudents on pd.StudentId equals s.Id
                                   join p in dc.tblPrograms on pd.ProgramId equals p.Id
                                   join dt in dc.tblDegreeTypes on p.DegreeTypeId equals dt.Id
                                   where pd.Id == id
                                   select new
                    {
                        ProgDecId = pd.Id,
                        ProgramId = p.Id,
                        StudentId = s.Id,
                        pd.ChangeDate,
                        ProgramName = p.Description,
                        s.FirstName,
                        s.LastName,
                        DegreeTypeName = dt.Description
                    }).FirstOrDefault();

                    if (progdec != null)
                    {
                        Models.ProgDec progDec = new Models.ProgDec
                        {
                            Id             = progdec.ProgDecId,
                            ProgramId      = progdec.ProgramId,
                            StudentId      = progdec.StudentId,
                            ProgramName    = progdec.ProgramName,
                            DegreeTypeName = progdec.DegreeTypeName,
                            StudentName    = progdec.LastName + ", " + progdec.FirstName,
                            ChangeDate     = progdec.ChangeDate
                        };

                        return(progDec);
                    }
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 27
0
        public static bool Login(User user)
        {
            try
            {
                if (!string.IsNullOrEmpty(user.UserId))
                {
                    if (!string.IsNullOrEmpty(user.PassCode))
                    {
                        using (ProgDecEntities dc = new ProgDecEntities())
                        {
                            tblUser tblUser = dc.tblUsers.FirstOrDefault(u => u.UserId == user.UserId);
                            if (tblUser != null)
                            {
                                // Check the password
                                if (tblUser.UserPass == GetHash(user.PassCode))
                                {
                                    user.FirstName = tblUser.FirstName;
                                    user.LastName  = tblUser.LastName;
                                    user.Id        = tblUser.Id;

                                    return(true);
                                }
                                else
                                {
                                    throw new Exception("Cannot login with these credentials. Your IP has been saved");
                                }
                            }
                            else
                            {
                                throw new Exception("User id could not be found.");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Password not set");
                    }
                }
                else
                {
                    throw new Exception("UserName not set");
                }
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 28
0
        public void LoadById()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    if (Id >= 0)
                    {
                        var results = (from pd in dc.tblProgDecs
                                       join p in dc.tblPrograms on pd.ProgramId equals p.Id
                                       join s in dc.tblStudents on pd.StudentId equals s.Id
                                       where pd.Id == this.Id
                                       select new
                        {
                            pd.Id,
                            pd.ProgramId,
                            pd.StudentId,
                            pd.ChangeDate,
                            p.Description,
                            s.FirstName,
                            s.LastName
                        }).FirstOrDefault();

                        if (results != null)
                        {
                            this.Id          = results.Id;
                            this.StudentId   = results.StudentId;
                            this.ProgramId   = results.ProgramId;
                            this.ChangeDate  = results.ChangeDate;
                            this.ProgramName = results.Description;
                            this.StudentName = results.FirstName + " " + results.LastName;
                            LoadAdvisors();
                        }
                        else
                        {
                            throw new Exception("Row was not found");
                        }
                    }
                    else
                    {
                        throw new Exception("Id was not set");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 29
0
        public void DeleteTest()
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                tblStudent row = (from dt in dc.tblStudents
                                  where dt.Id == -99
                                  select dt).FirstOrDefault();

                if (row != null)
                {
                    dc.tblStudents.Remove(row);
                    int actual = dc.SaveChanges();
                    Assert.AreNotEqual(0, actual);
                }
            }
        }
        public void LoadById()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    if (Id >= 0)
                    {
                        // missing an if() here?? error on line 135, '}' expected
                        var results = (from p in dc.tblPrograms
                                       join dt in dc.tblDegreeTypes on p.DegreeTypeId equals dt.Id
                                       where p.Id == this.Id
                                       select new
                        {
                            p.Id,
                            p.DegreeTypeId,
                            p.Description,
                            DegreeTypeName = dt.Description,
                            p.ImagePath
                        }).FirstOrDefault();


                        if (results != null)
                        {
                            this.Id             = results.Id;
                            this.Description    = results.Description;
                            this.DegreeTypeId   = results.DegreeTypeId;
                            this.DegreeTypeName = results.DegreeTypeName;
                            this.ImagePath      = results.ImagePath;
                        }

                        else
                        {
                            throw new Exception("Row was not found");
                        }
                    }
                    else
                    {
                        throw new Exception("Id was not set");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }