Exemplo n.º 1
0
        //Insert the race into the db, and generate a new Id for it.
        public int Insert()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Create a new Id
                    this.Id = Guid.NewGuid();

                    //Set the properties
                    tblRace race = new tblRace
                    {
                        Id          = this.Id,
                        Description = this.Description
                    };

                    //Add it to the table and save changes
                    dc.tblRaces.Add(race);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        //Retrieve the race from the database with this Id
        public void LoadById()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve from the db
                    tblRace race = dc.tblRaces.FirstOrDefault(r => r.Id == this.Id);

                    //Set this race's properties
                    this.Description = race.Description;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public int Update()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve the record from the DB
                    tblRace race = dc.tblRaces.FirstOrDefault(r => r.Id == this.Id);

                    //Update the properties
                    race.Description = this.Description;

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 4
0
        public int Delete()
        {
            try
            {
                using (MusicEntities dc = new MusicEntities())
                {
                    //Retrieve it from the DB
                    tblRace race = dc.tblRaces.FirstOrDefault(r => r.Id == this.Id);

                    //Remove the race
                    dc.tblRaces.Remove(race);

                    //Save the changes
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }