예제 #1
0
        public ActionResult Edit(int id, LunchCreateEditViewModel lunchCredteEditViewModel)
        {
            // todo: validate lunch-creator can edit a lunch
            var selectedRestaurants = lunchCredteEditViewModel.Restaurants.Where(r => r.IsChecked).Select(r => r.ID).ToList();

            var lunch = _context
                        .Lunches
                        .Include(l => l.Restaurants)
                        .First(l => l.Id == id);

            if (ModelState.IsValid)
            {
                lunch.Host        = lunchCredteEditViewModel.Host;
                lunch.MeetingTime = lunchCredteEditViewModel.MeetingTime;

                foreach (var restaurantId in selectedRestaurants)
                {
                    var restaurant = _context.Restaurants.Find(restaurantId);
                    lunch.Restaurants.Add(restaurant);
                }

                _context.Entry(lunch).State = EntityState.Modified;
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }


            return(View("Edit", lunchCredteEditViewModel));
        }
예제 #2
0
 public ActionResult Edit(int id, [Bind(Include = "Id, Name, Longitude, Latitude")] Restaurant restaurant)
 {
     if (ModelState.IsValid)
     {
         _context.Entry(restaurant).State = EntityState.Modified;
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("Details", restaurant));
 }