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)); }
public ActionResult AddGroup(AddGroupView view) { ViewBag.groupId = new SelectList(db.Groups.OrderBy(g => g.description), "groupId", "description"); if (!ModelState.IsValid) { return(View(view)); } var votingGroup = db.VotingGroups.Where(vg => vg.votingId == view.votingId && vg.groupId == view.groupId).FirstOrDefault(); if (votingGroup != null) { ViewBag.Error = "The group already belongs to this voting"; return(View(view)); } var group = new VotingGroup { votingId = view.votingId, groupId = view.groupId, }; db.VotingGroups.Add(group); db.SaveChanges(); return(RedirectToAction(string.Format("Details/{0}", group.votingId))); }
public ActionResult AddGroup(int id) { ViewBag.groupId = new SelectList(db.Groups.OrderBy(g => g.description), "groupId", "description"); var view = new AddGroupView { votingId = id, }; return(View(view)); }
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)); }
public ActionResult AddGroup(int id) { ViewBag.GroupId = new SelectList( db.Groups.OrderBy(g => g.Description), "GroupId", "Description"); var view = new AddGroupView { VotingId = id }; return View(view); }
public ActionResult AddGroup(AddGroupView view) { if (ModelState.IsValid) { var votingGroup = db.VotingGroups .Where(vg => vg.VotingId == view.VotingId && vg.GroupId == view.GroupId) .FirstOrDefault(); //Si en caso ya esta asignado ese grupo al voting if (votingGroup != null) { ModelState.AddModelError(string.Empty, "The group already belong to group"); //ViewBag.Error = ""; ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description"); return(View(view)); } votingGroup = new VotingGroup() { VotingId = view.VotingId, GroupId = view.GroupId }; db.VotingGroups.Add(votingGroup); db.SaveChanges(); return(RedirectToAction("Details", new { id = view.VotingId })); //return RedirectToAction(string.Format("Details/{0}",view.VotingId)); } ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description"); return(View(view)); }