예제 #1
0
        public void Can_Create_OwnerVote()
        {
            // Arrange
            IPartitionSpace partitionSpace = landRegistry.CreatePartitionSpace("123", 23, "Stan 1", new PhysicalPerson("12345678901", "Mile", "Milic"));

            // Act
            OwnerVote ownerVote = new OwnerVote(true, partitionSpace);

            // Assert
            Assert.IsNotNull(ownerVote);
        }
        /// <summary>
        /// Glasanje
        /// </summary>
        /// <param name="ownerVote">glas vlasnika</param>
        public virtual void AddVote(OwnerVote ownerVote)
        {
            var isOwnerVoted = ownerVotes.Contains(ownerVote);
            if (isOwnerVoted) { return; }

            var isOwnerInThisBuilding = building.LandRegistry.OwnedPartitionSpaces.Any(
                ownedPartitionSpace => ownedPartitionSpace.Owner.Oib == ownerVote.Owner.Oib);

            if(isOwnerInThisBuilding) {
                ownerVotes.Add(ownerVote);
                Evaluate();
            }
        }
        public ActionResult Vote(int id, VoteModel voteModel)
        {
            if (!User.IsInRole("owner")) { return new HttpUnauthorizedResult(); }

            var administrationJobsVoting = adminJobsVotingsRepository.GetById(id);
            if (administrationJobsVoting == null) {
                return HttpNotFound();
            }

            if (ModelState.IsValid) {
                var person = personsRepository.GetPersonByUsername(User.Identity.Name);
                var partitionSpace = partitionSpacesRepository.GetPartitionSpace(person, administrationJobsVoting.Building.LandRegistry);
                if(partitionSpace != null && partitionSpace.IsOwnedPartitionSpace) {
                    try {
                        var votingVoteModel = voteModel.Vote;
                        var ownerVote = new OwnerVote(votingVoteModel.Vote, partitionSpace);
                        administrationJobsVoting.AddVote(ownerVote);

                        return RedirectToAction("voting", new { Id = administrationJobsVoting.Id });

                    } catch (BusinessRulesException ex) {
                        ex.CopyTo(ModelState);
                    }
                } else {
                    ModelState.AddModelError("", "Etaža ne postoji ili niste vlasnik etaže za nevedenu zgradu, stoga ne možete glasati.");
                }

            }

            voteModel.Roles = Roles.GetRolesForUser();
            voteModel.CurrentRole = "owner";

            LinksModel links = new LinksModel();
            if (Session["lastPageId"] != null) {
                links.Id = (int)Session["lastPageId"];
                links.Links = NavLinksGenerator.GetOwnerLinks(administrationJobsVoting.Building, "Rad uprave");
            }

            voteModel.Links = links;

            return View(voteModel);
        }