Пример #1
0
        public void Delete(Restaurant restaurant)
        {
            var entry = db.Entry(restaurant);

            entry.State = System.Data.Entity.EntityState.Deleted;
            db.SaveChanges();
        }
Пример #2
0
        public void Update(Restaurant restaurant)
        {
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #3
0
        public void Update(Restaurant restaurant)
        {
            var entry = db.Entry(restaurant); // the object from DB is watching for update

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #4
0
        public void Update(Restaurant restaurant)
        {
            var entry = db.Entry(restaurant);  //entry exsits in table

            entry.State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }
Пример #5
0
        public void Edit(Restaurant restaurant)
        {
            var entry = dbContext.Entry(restaurant);

            entry.State = EntityState.Modified;
            dbContext.SaveChanges();
        }
Пример #6
0
        public void Update(Restaurant restaurant)
        {
            var entry = dbContext.Entry(restaurant); // means retaurant tbl and its data we want to modify is already in db

            entry.State = System.Data.Entity.EntityState.Modified;
            dbContext.SaveChanges();
        }
Пример #7
0
        public void Modify(Resturant resturant, int id)
        {
            var entry = db.Entry(resturant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #8
0
        public void Update(Restaurant restaurant)
        {
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            //var r = Get(restaurant.Id);
            //r.Name = "";
            db.SaveChanges();
        }
Пример #9
0
        public void Update(Restaurant restaurant)
        {
            //var r = Get(restaurant.Id);
            //r.Name = restaurant.Name;
            //r.Cuisine = restaurant.Cuisine;
            //db.SaveChanges();
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #10
0
        public void UpdateRestaurant(Restaurant restaurant)
        {
            //var r = GetRestaurant(restaurant.Id);
            //r.Name = "";
            //database.SaveChanges();

            var entry = database.Entry(restaurant);

            entry.State = EntityState.Modified;
            database.SaveChanges();
        }
Пример #11
0
        public void Update(Restaurant restaurant)
        {
            //var r = Get(restaurant.Id);
            //r.Name = "";
            //db.SaveChanges();

            //optimistic concurrency -> for production enviroments
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #12
0
        public void Update(Restaurant restaurant)
        {
            // Optimistic concurrency
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();

            // or
            //var r = Get(restaurant.Id);
            //r.Name = "";
            //db.SaveChanges();
        }
Пример #13
0
        public void Update(RestaurantModel restaurant)
        {
            //var x = GetById(restaurant.Id);
            //x.Name = restaurant.Name;
            //x.Menu = restaurant.Menu;
            //db.SaveChanges();

            //optimistic concurrency (multiple users can edit without interfering with each other)
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #14
0
        public void Update(Restaurant restaurant)
        {
            //get changes into the restaurant object, but be aware that mulitple users could be updating the same item
            //var r = Get(restaurant.Id);
            //r.Name = "";

            //This method checks that it matches whats in the database before saving
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;

            db.SaveChanges();
        }
Пример #15
0
        public void Update(Restaurant restaurant)
        {
            // Saves the last user update
            //var r = Get(restaurant.Id);
            //r.Name = restaurant.Name;
            //r.Cuisine = restaurant.Cuisine;
            //dbContext.SaveChanges();

            // Optimistic cuncurrency
            var entry = dbContext.Entry(restaurant);

            entry.State = EntityState.Modified;
            dbContext.SaveChanges();
        }
Пример #16
0
        public void Update(Restaurant restaurant)
        {
            //Right way
            var entry = db.Entry(restaurant);

            //we make sure that the users override one to each other using this by pulling the info at the time we're adding it

            entry.State = EntityState.Modified;

            //option 2
            //var r = Get(restaurant.Id);
            //r.Name = "";

            //save changes
            db.SaveChanges();
        }
Пример #17
0
        public void Update(Restaurant restaurant)
        {
            // retrieve restaurant from db first
            // not ideal for multiple users
            //var record = Get(restaurant.Id);
            //if (record != null)
            //{
            //    record.Name = restaurant.Name;
            //    record.Cuisine = restaurant.Cuisine;
            //}
            //db.SaveChanges();

            // with optimistic concurrency
            var entry = db.Entry(restaurant);//track changes to this object which should already be in the database

            entry.State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();
        }
Пример #18
0
        public void Update(Restaurant restaurant)
        {
            /**
             * This is not the best way to implement
             * since multiple user can be updating
             * the same object at the same time
             *
             * Better look for optimistic concurrency
             *
             * var r = Get(restaurant.Id);
             * r.Name = "";
             * db.SaveChanges();
             *
             */

            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #19
0
        public void Update(Restaurant restaurant)
        {
            /*
             *  //The below will not work for concurrent users and the last one that does the update wins.
             *  //This can cause user to over wrote another user's changes:
             *  //The Solution is to implement optimistic concurrncy using the db.Entry and EntityState.
             *
             *   var r = Get(restaurant.Id);
             *   r.Name = "";
             *   db.SaveChanges();
             */


            //Entity Framework implements change tracking:
            //Optimistic concurrency when many users are using the system:
            var entry = db.Entry(restaurant);

            entry.State = System.Data.Entity.EntityState.Modified;

            //Entity Framework will look at all the changes and make the update in one unit or work in a transaction.
            db.SaveChanges();
        }
Пример #20
0
        public void Update(Restaurant restaurant)
        {
            ////mycode
            //var existing = db.Restaurants.FirstOrDefault(r => r.Id == id);
            //if(existing != null)
            //{
            //    existing.Name = restaurant.Name;
            //    existing.Cuisine = restaurant.Cuisine;
            //    db.SaveChanges();
            //}

            ////Scott's Code without Concurency Consideration: Last user in, with the updates will win!
            //var r = Get(restaurant.Id);
            //r.Name = restaurant.Name;
            //r.Cuisine = restaurant.Cuisine;
            //db.SaveChanges();

            //Scott's code with Optimistic Concurency
            var entry = db.Entry(restaurant);

            entry.State = EntityState.Modified;
            db.SaveChanges();
        }
Пример #21
0
 public Restaurant Update(Restaurant restaurant)
 {
     _context.Entry(restaurant).State = EntityState.Modified;
     _context.SaveChanges();
     return(restaurant);
 }