コード例 #1
0
ファイル: FormatManager.cs プロジェクト: jlipke/DVDCentral
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat deleterow = dc.tblFormats.FirstOrDefault(dt => dt.Id == id);

                    if (deleterow != null)
                    {
                        // Remove the row
                        dc.tblFormats.Remove(deleterow);

                        // Commit/Save the changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row was not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public static Format LoadById(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat row = (from dt in dc.tblFormats
                                     where dt.Id == id
                                     select dt).FirstOrDefault();

                    if (row != null)
                    {
                        return new Format {
                                   Id = row.Id, Description = row.Description
                        }
                    }
                    ;
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
ファイル: FormatManager.cs プロジェクト: jlipke/DVDCentral
        public static bool Insert(Format format)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    // Make a new row
                    tblFormat newrow = new tblFormat();

                    // Set the properties
                    // Ternary Operator condition ? true : false
                    newrow.Id          = dc.tblFormats.Any() ? dc.tblFormats.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1
                    newrow.Description = format.Description;


                    // Do the Insert
                    dc.tblFormats.Add(newrow);

                    // Commit the insert
                    dc.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
ファイル: FormatManager.cs プロジェクト: jlipke/DVDCentral
        public static int Update(Format format)
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                try
                {
                    tblFormat updatedrow = dc.tblFormats.Where(dt => dt.Id == format.Id).FirstOrDefault();

                    // Check to see if object exists
                    if (format != null)
                    {
                        // Update the proper fields
                        updatedrow.Description = format.Description;


                        // Save and commit changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        // throw an exception stating the row was not found
                        throw new Exception("Row was not found.");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
コード例 #5
0
ファイル: FormatManager.cs プロジェクト: VanVelZ/DVD-Central
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to delete
                    tblFormat deleteRow = (from dt in dc.tblFormats
                                           where dt.Id == id
                                           select dt).FirstOrDefault();

                    if (deleteRow != null)
                    {
                        dc.tblFormats.Remove(deleteRow);
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
ファイル: Format.cs プロジェクト: B-Lemke/FVTC_DVDCentral
        public void LoadById()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == this.Id);

                        //Make sure that a format was retrieved
                        if (format != null)
                        {
                            //Set the properties on this format
                            this.Description = format.Description;
                        }
                        else
                        {
                            throw new Exception("No format to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Format Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #7
0
ファイル: FormatManager.cs プロジェクト: VanVelZ/DVD-Central
        public static int Update(Format format)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to update
                    tblFormat updateRow = (from dt in dc.tblFormats
                                           where dt.Id == format.Id
                                           select dt).FirstOrDefault();

                    if (updateRow != null)
                    {
                        updateRow.Description = format.Description;
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
ファイル: FormatManager.cs プロジェクト: VanVelZ/DVD-Central
        public static int Insert(Format format)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat tblFormat = new tblFormat();

                    tblFormat.Description = format.Description;

                    //example of ternary operator
                    tblFormat.Id = dc.tblFormats.Any() ? dc.tblFormats.Max(dt => dt.Id) + 1 : 1;

                    //Change the ID of the inserted Student
                    format.Id = tblFormat.Id;

                    dc.tblFormats.Add(tblFormat);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == -99);
                dc.tblFormats.Remove(format);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
コード例 #10
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == -99);
                format.Description = "TestingUpdate";

                //Save changed property
                dc.SaveChanges();

                tblFormat updatedFormat = dc.tblFormats.FirstOrDefault(f => f.Description == "TestingUpdate");
                Assert.AreEqual(format.Id, updatedFormat.Id);
            }
        }
コード例 #11
0
ファイル: utFormat.cs プロジェクト: VanVelZ/DVD-Central
        public void DeleteTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblFormat row = (from dt in dc.tblFormats
                                 where dt.Id == -99
                                 select dt).FirstOrDefault();

                dc.tblFormats.Remove(row);

                int results = dc.SaveChanges();

                Assert.AreNotEqual(0, results);
            }
        }
コード例 #12
0
ファイル: utFormat.cs プロジェクト: VanVelZ/DVD-Central
        public void InsertTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblFormat newrow = new tblFormat();

                newrow.Id          = -99;
                newrow.Description = "ZZZ";


                dc.tblFormats.Add(newrow);

                int results = dc.SaveChanges();

                Assert.IsTrue(results == 1);
            }
        }
コード例 #13
0
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat deleterow = (from dt in dc.tblFormats
                                           where dt.Id == id
                                           select dt).FirstOrDefault();
                    dc.tblFormats.Remove(deleterow);

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #14
0
        public static int Update(int id, string description)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat updaterow = (from dt in dc.tblFormats
                                           where dt.Id == id
                                           select dt).FirstOrDefault();

                    updaterow.Description = description;

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #15
0
ファイル: utFormat.cs プロジェクト: VanVelZ/DVD-Central
        public void UpdateTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblFormat row = (from dt in dc.tblFormats
                                 where dt.Id == -99
                                 select dt).FirstOrDefault();


                if (row != null)
                {
                    row.Description = "VV";
                }


                int results = dc.SaveChanges();

                Assert.AreNotEqual(0, results);
            }
        }
コード例 #16
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a format
                tblFormat format = new tblFormat
                {
                    Id          = -99,
                    Description = "TestFormat"
                };

                //Insert the row
                dc.tblFormats.Add(format);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
コード例 #17
0
ファイル: Format.cs プロジェクト: B-Lemke/FVTC_DVDCentral
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblFormat format = new tblFormat
                    {
                        Description = this.Description,
                        Id          = dc.tblFormats.Any() ? dc.tblFormats.Max(f => f.Id) + 1 : 1
                    };
                    this.Id = format.Id;
                    dc.tblFormats.Add(format);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #18
0
ファイル: Format.cs プロジェクト: B-Lemke/FVTC_DVDCentral
        public int Update()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == this.Id);

                        //Make sure that a format was retrieved
                        if (format != null)
                        {
                            //Update the proterties on the format
                            format.Description = this.Description;

                            //return the number of rows effected
                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("No format to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Format Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #19
0
ファイル: FormatManager.cs プロジェクト: jlipke/DVDCentral
        public static Format LoadById(int id)
        {
            try
            {
                if (id != 0)
                {
                    using (DVDCentralEntities dc = new DVDCentralEntities())
                    {
                        tblFormat tblformat = dc.tblFormats.FirstOrDefault(p => p.Id == id);

                        if (tblformat != null)
                        {
                            Format format = new Format
                            {
                                Id          = tblformat.Id,
                                Description = tblformat.Description
                            };

                            return(format);
                        }
                        else
                        {
                            throw new Exception("Row was not found.");
                        }
                    }
                }
                else
                {
                    throw new Exception("Please provide an id");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #20
0
        public static int Insert(out int id, string description)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblFormat newrow = new tblFormat();

                    newrow.Description = description;

                    newrow.Id = dc.tblFormats.Any() ? dc.tblFormats.Max(dt => dt.Id) + 1 : 1;

                    id = newrow.Id;

                    dc.tblFormats.Add(newrow);

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }