Пример #1
0
        public ActionResult FavEdit(MemberWithFavGames mgvm)
        {
            if (ModelState.IsValid)
            {
                Member m = db.Members.Find(mgvm.ID);
                m.Games.Clear();

                foreach (var fg in mgvm.FavGames)
                {
                    if (fg.isFav == true)
                    {
                        Game g = db.Games.Find(fg.Game.Id);
                        m.Games.Add(g);

                    }

                }
                db.Entry(m).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");

            }
               return View(mgvm);
        }
Пример #2
0
        // GET: Members/Edit/5
        public ActionResult FavEdit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Member member = db.Members.Find(id);
            if (member == null)
            {
                return HttpNotFound();
            }

            //todo
            MemberWithFavGames mgvm = new MemberWithFavGames();

            mgvm.Member = member;
            mgvm.ID = member.Id;

            var q = from g in db.Games
                    select g;
            foreach(Game g in q)
            {
                mgvm.FavGames.Add(new FavGame() { isFav = member.Games.Contains(g), Game = g });
            }
            return View(mgvm);
        }