コード例 #1
0
        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)));
        }
コード例 #2
0
ファイル: VotingsController.cs プロジェクト: Ndabe/SMS
        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));
        }
コード例 #3
0
        public ActionResult AddGroup(int id)
        {
            ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description");

            var view = new VotingGroup
            {
                VotingId = id,
            };

            return(View(view));
        }
コード例 #4
0
        public ActionResult <VotingGroup> Get(string id)
        {
            VotingGroup VotingGroup = VotingGroupService.Get(id);

            if (VotingGroup == null)
            {
                return(NotFound());
            }

            return(VotingGroup);
        }
コード例 #5
0
        public IActionResult Delete(string id)
        {
            VotingGroup VotingGroup = VotingGroupService.Get(id);

            if (VotingGroup == null)
            {
                return(NotFound());
            }

            VotingGroupService.Remove(VotingGroup.Id);

            return(NoContent());
        }
コード例 #6
0
        public IActionResult Update(string id, VotingGroup votingGroupIn)
        {
            VotingGroup VotingGroup = VotingGroupService.Get(id);

            if (VotingGroup == null)
            {
                return(NotFound());
            }

            VotingGroupService.Update(id, votingGroupIn);

            return(NoContent());
        }
コード例 #7
0
        public ActionResult AddGroup(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

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

            var votingGroup = new VotingGroup
            {
                VotingId = id
            };

            return(View(votingGroup));
        }
コード例 #8
0
        public async Task <IActionResult> Post([FromBody] NewVoteViewModel model)
        {
            var poll = this.unitOfWork.PollsRepository.GetById(model.PollId);

            if (poll == null)
            {
                return(BadRequest());
            }
            string ipAddress = HttpContext.Connection.RemoteIpAddress.ToString();
            var    flag      = this.unitOfWork.VotesRepository.AlreadyVoted(ipAddress, model.PollId);

            if (flag)
            {
                return(Conflict());
            }
            else
            {
                if (!poll.MultipleAnswers && model.VotedFor.Count > 1)
                {
                    return(BadRequest("You've chosen more than 1 option"));
                }
                VotingGroup votingGroup = new VotingGroup
                {
                    IpAddress = ipAddress,
                    DateTime  = DateTime.Now,
                    PollId    = model.PollId
                };
                this.unitOfWork.VotesRepository.AddVoteGroup(votingGroup);
                foreach (var id in model.VotedFor)
                {
                    Vote newVote = new Vote
                    {
                        PollAnswerId  = id,
                        VotingGroupId = votingGroup.VotingGroupId,
                    };
                    this.unitOfWork.VotesRepository.AddVote(newVote);
                }
                await this.unitOfWork.Save();

                return(StatusCode(201));
            }
        }
コード例 #9
0
        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));
        }
コード例 #10
0
        public ActionResult AddGroup(VotingGroup addGroupView)
        {
            if (ModelState.IsValid)
            {
                //busco si grupo existe o si ya esta seleccionado:
                var votingGroup = db.VotingGroups.Where(vg => vg.VotingId == addGroupView.VotingId &&
                                                        vg.GroupId == addGroupView.GroupId).FirstOrDefault();//ejecuto la funcion link:

                //Aquí a ver si si lo encontro:
                if (votingGroup != null)
                {
                    ModelState.AddModelError("", "The group already belong to Voting.");

                    //ViewBag.Error = "The group already belong to Voting.";

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

                    return(View(addGroupView));
                }

                //Si no existe debo crear el objeto de bd: y despues de crear el objeto lo envio a la base de datos:
                votingGroup = new VotingGroup
                {
                    GroupId  = addGroupView.GroupId,
                    VotingId = addGroupView.VotingId,
                };

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

                return(RedirectToAction($"Details/{addGroupView.VotingId}"));
            }

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

            return(View(addGroupView));
        }
コード例 #11
0
 public void Remove(VotingGroup votingGroupIn) =>
 VotingGroups.DeleteOne(VotingGroup => VotingGroup.Id == votingGroupIn.Id);
コード例 #12
0
 public void Update(string id, VotingGroup votingGroupIn) =>
 VotingGroups.ReplaceOne(VotingGroup => VotingGroup.Id == id, votingGroupIn);
コード例 #13
0
 public VotingGroup Create(VotingGroup votingGroup)
 {
     VotingGroups.InsertOne(votingGroup);
     return(votingGroup);
 }
コード例 #14
0
 public void AddVoteGroup(VotingGroup votingGroup)
 {
     this.dbContext.VotingGroups.Add(votingGroup);
 }
コード例 #15
0
        public ActionResult <VotingGroup> Create(VotingGroup votingGroup)
        {
            VotingGroupService.Create(votingGroup);

            return(CreatedAtRoute("GetVotingGroup", new { id = votingGroup.Id.ToString() }, votingGroup));
        }