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(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(int id) { ViewBag.GroupId = new SelectList(db.Groups.OrderBy(g => g.Description), "GroupId", "Description"); var view = new VotingGroup { VotingId = id, }; return(View(view)); }
public ActionResult <VotingGroup> Get(string id) { VotingGroup VotingGroup = VotingGroupService.Get(id); if (VotingGroup == null) { return(NotFound()); } return(VotingGroup); }
public IActionResult Delete(string id) { VotingGroup VotingGroup = VotingGroupService.Get(id); if (VotingGroup == null) { return(NotFound()); } VotingGroupService.Remove(VotingGroup.Id); return(NoContent()); }
public IActionResult Update(string id, VotingGroup votingGroupIn) { VotingGroup VotingGroup = VotingGroupService.Get(id); if (VotingGroup == null) { return(NotFound()); } VotingGroupService.Update(id, votingGroupIn); return(NoContent()); }
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)); }
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)); } }
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)); }
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)); }
public void Remove(VotingGroup votingGroupIn) => VotingGroups.DeleteOne(VotingGroup => VotingGroup.Id == votingGroupIn.Id);
public void Update(string id, VotingGroup votingGroupIn) => VotingGroups.ReplaceOne(VotingGroup => VotingGroup.Id == id, votingGroupIn);
public VotingGroup Create(VotingGroup votingGroup) { VotingGroups.InsertOne(votingGroup); return(votingGroup); }
public void AddVoteGroup(VotingGroup votingGroup) { this.dbContext.VotingGroups.Add(votingGroup); }
public ActionResult <VotingGroup> Create(VotingGroup votingGroup) { VotingGroupService.Create(votingGroup); return(CreatedAtRoute("GetVotingGroup", new { id = votingGroup.Id.ToString() }, votingGroup)); }