Пример #1
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;
            }
        }
Пример #2
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;
            }
        }
Пример #3
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;
     }
 }
Пример #4
0
        public void DeleteTest()
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                tblProgDec row = (from dt in dc.tblProgDecs
                                  where dt.Id == -99
                                  select dt).FirstOrDefault();

                if (row != null)
                {
                    dc.tblProgDecs.Remove(row);
                    int actual = dc.SaveChanges();
                    Assert.AreNotEqual(0, actual);
                }
            }
        }
Пример #5
0
        public static int Delete(int id)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblProgDec deleterow = (from dt in dc.tblProgDecs
                                            where dt.Id == id
                                            select dt).FirstOrDefault();



                    dc.tblProgDecs.Remove(deleterow);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #6
0
        public void UpdateTest()
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                // Get the record that I want to update
                // SELECT * FROM tblProgDec WHERE  Id = -99
                tblProgDec row = (from dt in dc.tblProgDecs
                                  where dt.Id == -99
                                  select dt).FirstOrDefault();

                if (row != null)
                {
                    // Change values
                    row.ProgramId  = 2;
                    row.StudentId  = 4;
                    row.ChangeDate = DateTime.Now;

                    int actual = dc.SaveChanges();
                    Assert.AreNotEqual(0, actual);
                }
            }
        }
Пример #7
0
        public void InsertTest()
        {
            using (ProgDecEntities dc = new ProgDecEntities())
            {
                // Make a new progdec
                tblProgDec newrow = new tblProgDec();

                // Set the column values
                newrow.Id         = -99;
                newrow.ProgramId  = 4;
                newrow.StudentId  = 3;
                newrow.ChangeDate = DateTime.Now;

                // Add the row
                dc.tblProgDecs.Add(newrow);

                // Save the Changes
                int results = dc.SaveChanges();

                Assert.IsTrue(results > 0);
            }
        }
Пример #8
0
        public static int Update(int id,
                                 int progDecId,
                                 int studentId)
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblProgDec updaterow = (from dt in dc.tblProgDecs
                                            where dt.Id == id
                                            select dt).FirstOrDefault();

                    updaterow.ProgramId  = progDecId;
                    updaterow.StudentId  = studentId;
                    updaterow.ChangeDate = DateTime.Now;
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #9
0
        public bool Insert()
        {
            try
            {
                using (ProgDecEntities dc = new ProgDecEntities())
                {
                    tblProgDec progDec = new tblProgDec();

                    progDec.Id         = dc.tblProgDecs.Any() ? dc.tblProgDecs.Max(p => p.Id) + 1 : 1; // (condition) ? if{} : else{}
                    progDec.StudentId  = this.StudentId;
                    progDec.ProgramId  = this.ProgramId;
                    progDec.ChangeDate = DateTime.Now;
                    this.Id            = progDec.Id;

                    dc.tblProgDecs.Add(progDec);
                    dc.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }