Ejemplo n.º 1
0
        public ActionResult AddGroup(AddGroupView view)
          {           

            if (ModelState.IsValid)
            {
                var votingGroup = db.VotingGroups.Where(vg => vg.VotingId == view.VotingId && vg.GroupId == view.GroupId).FirstOrDefault();

                if (votingGroup != null)
                {

                    ModelState.AddModelError(string.Empty, "The group already belongs to voting...");
                    
                    ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description").ToList();
                    
                    return View(view);
                }

                votingGroup = new VotingGroup
                {
                  GroupId = view.GroupId,
                  VotingId = view.VotingId,
                };

                db.VotingGroups.Add(votingGroup);
                db.SaveChanges();

                return RedirectToAction(string.Format("Details/{0}", view.VotingId));
                             
            }

            ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description").ToList();

            return View(view);
        }
Ejemplo n.º 2
0
        public ActionResult AddGroup(int id)
        {
            ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description").ToList();
            
            // ViewBag.GroupId = new SelectList(db.Groups.OrderBy(vg => vg.Description), "GroupId", "Description").FirstOrDefault();
            var view = new AddGroupView
            {
                VotingId = id,
                
            };

            return View(view);
        }