Exemple #1
0
 public void SaveKidViewModel(int id, EditKidViewModel model)
 {
     Kid Kid = db.Kids.Find(id);
     Kid.FirstName = model.FirstName;
     Kid.LastName = model.LastName;
     model.SelectedRooms = new List<Room>();
     model.KidRooms = db.KidRooms.Where(k => k.KidId == id).ToList();
     foreach (var room in model.KidRooms)
     {
         model.SelectedRooms.Add(room.Room);
     }
     model.SelectedRooms.Add(db.Rooms.Find(model.RoomId));
     foreach (var room in model.SelectedRooms)
     {
         db.KidRooms.AddOrUpdate(k => new { k.KidId, k.RoomId },
             new KidRoom {KidId = id, RoomId = room.Id }
             );
     }
     db.SaveChanges();
 }
 public ActionResult EditKid(int id, EditKidViewModel model)
 {
     _homeAdapter.SaveKidViewModel(id, model);
     return RedirectToAction("Index");
 }
Exemple #3
0
 public EditKidViewModel GetEditKidViewModel(int id)
 {
     Kid Kid = db.Kids.Find(id);
     EditKidViewModel model = new EditKidViewModel();
     model.Kid = Kid;
     model.FirstName = Kid.FirstName;
     model.LastName = Kid.LastName;
     model.Rooms = db.Rooms.ToList();
     model.SelectedRooms = new List<Room>();
     model.KidRooms = db.KidRooms.Where(k => k.KidId == id).ToList();
     foreach (var room in model.KidRooms)
     {
         model.SelectedRooms.Add(room.Room);
     }
     return model;
 }
 public ActionResult EditKid(int id)
 {
     EditKidViewModel model = new EditKidViewModel();
     model = _homeAdapter.GetEditKidViewModel(id);
     return View(model);
 }