Example #1
0
        public void Submit_voting(string sprintId, VotingDto voting, Action onOk, Action <InconsistentVotingDto> onInconsistency)
        {
            try
            {
                var json       = new JavaScriptSerializer();
                var jsonVoting = json.Serialize(voting);

                var wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/json");
                wc.UploadString(EndpointAddress + $"/api/sprints/{sprintId}/votings", "Post", jsonVoting);
                onOk();
            }
            catch (WebException e)
            {
                var response = (HttpWebResponse)e.Response;
                if ((int)response.StatusCode == 422)
                {
                    var sr     = new StreamReader(response.GetResponseStream());
                    var jsonIv = sr.ReadToEnd();

                    var json = new JavaScriptSerializer();
                    var iv   = json.Deserialize <InconsistentVotingDto>(jsonIv);
                    onInconsistency(iv);
                }
                else
                {
                    throw e;
                }
            }
        }
        public void Submit_valid_voting()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                var voting = new VotingDto {
                    VoterId    = "Frodo",
                    Weightings = new[] {
                        new WeightedComparisonPairDto {
                            Id = "1", Selection = Selection.A
                        },
                        new WeightedComparisonPairDto {
                            Id = "2", Selection = Selection.B
                        }
                    }
                };
                var json       = new JavaScriptSerializer();
                var jsonVoting = json.Serialize(voting);

                var wc = new WebClient();
                wc.Headers.Add("Content-Type", "application/json");
                var result = wc.UploadString("http://localhost:8080/api/sprints/42/votings", "Post", jsonVoting);

                Assert.AreEqual("42", rh.sprintId);
                Assert.AreEqual("Frodo", rh.voting.VoterId);
                Assert.AreEqual("2", rh.voting.Weightings.Last().Id);
            }
        }
        public void Submit_inconsistent_voting()
        {
            var rh = new MockRequestHandler();

            using (new RESTServer("http://localhost:8080", rh))
            {
                try {
                    var voting = new VotingDto {
                        VoterId    = "Sauron",
                        Weightings = null
                    };
                    var json       = new JavaScriptSerializer();
                    var jsonVoting = json.Serialize(voting);

                    var wc = new WebClient();
                    wc.Headers.Add("Content-Type", "application/json");
                    var result = wc.UploadString("http://localhost:8080/api/sprints/42/votings", "Post", jsonVoting);
                }
                catch (WebException e) {
                    var response = (System.Net.HttpWebResponse)e.Response;
                    Assert.AreEqual(422, (int)response.StatusCode);

                    var sr     = new StreamReader(response.GetResponseStream());
                    var jsonIv = sr.ReadToEnd();
                    Console.WriteLine("Inconsistent voting: {0}", jsonIv);

                    var json = new JavaScriptSerializer();
                    var iv   = json.Deserialize <InconsistentVotingDto>(jsonIv);
                    Assert.AreEqual("42", iv.SprintId);
                    Assert.AreEqual("1", iv.ComparisonPairId);
                }
            }
        }
Example #4
0
        public IActionResult SubmitVote(VotingDto model)
        {
            if (_eventService.SubmitVote(model, _context, _context.PlayerModel.First(a => a.User == ControllerContext.HttpContext.User.Identity.Name).Name))
            {
                return(View("Index", _context.EventModel.ToList()));
            }

            return(View("PollClosed"));
        }
Example #5
0
        public bool SubmitVote(VotingDto model, ApplicationDbContext context, string username)
        {
            var voting = context.VotingModel.Find(model.Id);

            voting.Event = context.EventModel.Find(model.EventId);
            var b = context.LeagueModel.First(a => a.Id == voting.Event.LeagueId).Players.Contains(username);

            if (!voting.IsOpened || !context.LeagueModel.First(a => a.Id == voting.Event.LeagueId).Players.Contains(username))
            {
                return(false);
            }
            if (model.Stand)
            {
                voting.Stand++;
            }
            if (model.Mod)
            {
                voting.Mod++;
            }
            if (model.Pau)
            {
                voting.Pau++;
            }
            if (model.Rain)
            {
                voting.Rain++;
            }
            if (model.Draft)
            {
                voting.Draft++;
            }
            if (model.Sing)
            {
                voting.Sing++;
            }
            if (model.Tri)
            {
                voting.Tri++;
            }
            if (model.Pea)
            {
                voting.Pea++;
            }
            if (model.War)
            {
                voting.War++;
            }
            if (model.Back)
            {
                voting.Back++;
            }
            context.PlayerModel.First(a => a.Name == username).HasVoted =
                true;
            context.VotingModel.Update(voting);
            context.SaveChanges();
            return(true);
        }
Example #6
0
        public IActionResult Voting(int?id)
        {
            if (_context.PlayerModel.First(a => a.User == ControllerContext.HttpContext.User.Identity.Name).HasVoted ==
                false)
            {
                var model = _context.VotingModel.First(a => a.Id == id);
                var dto   = new VotingDto();
                dto.Id      = model.Id;
                dto.EventId = Convert.ToInt32(id);
                return(View("Voting", dto));
            }

            return(View("AlreadyVoted", _context.VotingModel.First(a => a.Id == id)));
        }
        public HttpResponseMessage Post(string sprintId, [FromBody] VotingDto voting)
        {
            var res = new HttpResponseMessage();

            RequestHandler.Submit_voting(sprintId, voting,
                                         new Action(() => res = new HttpResponseMessage()),

                                         new Action <InconsistentVotingDto>(iv => {
                var json       = new JavaScriptSerializer();
                var jsonIv     = json.Serialize(iv);
                res            = new HttpResponseMessage();
                res.Content    = new StringContent(jsonIv, Encoding.UTF8, "application/json");
                res.StatusCode = (HttpStatusCode)422;
            }));

            return(res);
        }
        public void Submit_voting(string sprintId, VotingDto voting, Action onOk, Action <InconsistentVotingDto> onInconsistency)
        {
            Console.WriteLine("MockRequestHandler.Submit voting for {0}", sprintId);

            this.sprintId = sprintId;
            this.voting   = voting;

            if (voting.VoterId == "Sauron")
            {
                onInconsistency(new InconsistentVotingDto {
                    SprintId = sprintId, ComparisonPairId = "1"
                });
            }
            else
            {
                onOk();
            }
        }
Example #9
0
        //TODO: Inkonsistenzquellen bestimmen
        public void Submit_voting(string sprintId, VotingDto voting, Action onOk, Action <InconsistentVotingDto> onInconsistency)
        {
            var sprint          = this.repo.Load(sprintId);
            var vergleichspaare = Vergleichspaare_berechnen(sprint.UserStories.Length);

            this.weighting.Compute_Estimator_Weighting(voting.Weightings, vergleichspaare,
                                                       gewichtung => {
                sprint.Register(new Voting(voting.VoterId, gewichtung.StoryIndizes.ToArray()));

                this.repo.Store(sprint);
                onOk();
            },
                                                       () => {
                onInconsistency(new InconsistentVotingDto {
                    SprintId = sprintId, ComparisonPairId = ""
                });
            });
        }
Example #10
0
        public ActionResult AddVote(VotingDto votingDto)
        {
            try
            {
                articleService.UpdateArticleVotes(votingDto.ArticleId, votingDto.Flag);

                var author = authorService.GetAuthorByArticleId(votingDto.ArticleId);

                //authorService.UpdateAuthorPostVotes(author, votingDto.Flag);

                authorService.UpdateAuthorVotes(author.Id);

                return(Ok(new { articleid = votingDto.ArticleId }));
            }
            catch
            {
                return(BadRequest());
            }
        }
Example #11
0
        public async Task <VotingDto> GetVoteDetail(Guid id)
        {
            try
            {
                var voting = await _votingRepository.GetVoteById(id);

                VotingDto votingDto = new VotingDto
                {
                    ID          = voting.ID,
                    Description = voting.Description,
                    Name        = voting.Name,
                    DueDate     = voting.DueDate,
                    VotersCount = voting.VotersCount,
                    CreatedDate = voting.CreatedDate,
                    Category    = voting.Category.Name
                };

                return(votingDto);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #12
0
        public void UseCase()
        {
            const string EVENTSTORE_FOLDER = "UseCaseEventStore";

            if (Directory.Exists(EVENTSTORE_FOLDER))
            {
                Directory.Delete(EVENTSTORE_FOLDER, true);
            }

            var we  = new Weighting();
            var es  = new FilesystemEventStore(EVENTSTORE_FOLDER);
            var sut = new RequestHandler(we, es);

            // create first sprint
            var sprintId = sut.Create_Sprint(new[] { "a", "b", "c" });

            // ab, ac, bc
            var cp = sut.ComparisonPairs(sprintId);

            Assert.AreEqual(sprintId, cp.SprintId);
            Assert.AreEqual("a", cp.Pairs[0].A);
            Assert.AreEqual("b", cp.Pairs[0].B);
            Assert.AreEqual("a", cp.Pairs[1].A);
            Assert.AreEqual("c", cp.Pairs[1].B);

            var voting = new VotingDto {
                VoterId = "v1", Weightings = new[] {
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[0].Id, Selection = Selection.B
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[1].Id, Selection = Selection.B
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[2].Id, Selection = Selection.B
                    }
                }
            };

            sut.Submit_voting(sprintId, voting,
                              () => { Console.WriteLine("voting sprint 1 submitted"); },
                              null);

            var total = sut.Get_total_weighting_for_sprint(sprintId);

            Assert.AreEqual(sprintId, total.SprintId);
            Assert.AreEqual(new[] { "c", "b", "a" }, total.Stories);
            Assert.AreEqual(1, total.NumberOfVotings);


            // create second sprint
            var sprintId2 = sut.Create_Sprint(new[] { "x", "y", "z" });

            cp = sut.ComparisonPairs(sprintId2);
            Assert.AreEqual(sprintId2, cp.SprintId);
            Assert.AreEqual("x", cp.Pairs[0].A);
            Assert.AreEqual("y", cp.Pairs[0].B);
            voting = new VotingDto {
                VoterId    = "vI",
                Weightings = new[] {
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[0].Id, Selection = Selection.A
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[1].Id, Selection = Selection.A
                    },
                    new WeightedComparisonPairDto {
                        Id = cp.Pairs[2].Id, Selection = Selection.A
                    }
                }
            };
            sut.Submit_voting(sprintId2, voting,
                              () => { Console.WriteLine("voting sprint 2 submitted"); },
                              null);
            total = sut.Get_total_weighting_for_sprint(sprintId2);
            Assert.AreEqual(sprintId2, total.SprintId);
            Assert.AreEqual(new[] { "x", "y", "z" }, total.Stories);
            Assert.AreEqual(1, total.NumberOfVotings);


            // both sprints coexist
            cp = sut.ComparisonPairs(sprintId);
            Assert.AreEqual(sprintId, cp.SprintId);
            cp = sut.ComparisonPairs(sprintId2);
            Assert.AreEqual(sprintId2, cp.SprintId);


            // delete only second sprint
            sut.Delete_Sprint(sprintId2);
            Assert.Throws <InvalidOperationException>(() => sut.Get_total_weighting_for_sprint(sprintId2));

            cp = sut.ComparisonPairs(sprintId);
            Assert.AreEqual(sprintId, cp.SprintId);
        }