Esempio n. 1
0
        private static void CreateHotel()
        {
            Console.WriteLine("Please enter hotel name:");
            var name = Console.ReadLine();

            Console.WriteLine("Please enter hotel address:");
            var address = Console.ReadLine();

            var hotel = new Hotel {
                Name = name, Address = address
            };

            using (var context = new HotelAdvisorContext())
            {
                context.Hotels.Add(hotel);
                context.SaveChanges();

                Console.WriteLine("Hotels in our database:");

                var query = from h in context.Hotels
                            orderby h.Name
                            select h;

                foreach (var h in query)
                {
                    Console.WriteLine(string.Format("Hotel id: {0}, name: {1}, address:{2}", h.Id, h.Name, h.Address));
                }

                Console.WriteLine("Press any key to exit application.");
                Console.ReadKey();
            }
        }
 public void CreateHotel(Hotel hotel)
 {
     using (var context = new HotelAdvisorContext())
     {
         context.Hotels.Add(hotel);
         context.SaveChanges();
     }
 }
 public void CreateComment(Comment comment)
 {
     using (var context = new HotelAdvisorContext())
     {
         context.Comments.Add(comment);
         context.SaveChanges();
     }
 }
Esempio n. 4
0
 public void CreateUser(User user)
 {
     using (var context = new HotelAdvisorContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Esempio n. 5
0
 public void Edit(Hotel newHotel)
 {
     using (var dbContext = new HotelAdvisorContext())
     {
         this.hotel = dbContext.Hotels.Find(newHotel.Id);
         this.Populate(newHotel);
         dbContext.Entry(hotel).State = System.Data.Entity.EntityState.Modified;
         dbContext.SaveChanges();
     }
 }