Пример #1
0
        public static void Delete(Guitar guitar)
        {
            using (GuitarContext context = new GuitarContext())
            {
                context.Database.Log = Console.WriteLine;

                context.Entry(guitar).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Пример #2
0
        public static List <Guitar> GetGuitars()
        {
            using (GuitarContext context = new GuitarContext())
            {
                List <Guitar> guitars =
                    context.Guitars.ToList();

                return(guitars);
            }
        }
Пример #3
0
        public static Guitar Update(Guitar guitar)
        {
            using (var context = new GuitarContext())
            {
                context.Database.Log = Console.WriteLine;

                context.Entry(guitar).State = EntityState.Modified;
                context.SaveChanges();

                return(guitar);
            }
        }
Пример #4
0
        /// <summary>
        /// Adds a guitar to the database.
        /// Returns guitar with <see cref="GetGuitars.GuitarId"/>
        /// property(identity column) populated.
        /// </summary>
        /// <param name="guitar">The guitar to be added</param>
        public static Guitar Add(Guitar guitar)
        {
            using (var guitarContext = new GuitarContext())
            {
                guitarContext.Database.Log = Console.WriteLine;

                guitarContext.Guitars.Add(guitar);
                guitarContext.SaveChanges();

                return(guitar);
            }
        }
Пример #5
0
        public static void Delete(int id)
        {
            using (GuitarContext context = new GuitarContext())
            {
                Guitar guitarToDelete = (from guitar in context.Guitars
                                         where guitar.GuitarId == id
                                         select guitar).Single();


                context.Entry(guitarToDelete).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }