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); }
public ActionResult Vote(int id) { if (!User.IsInRole("owner")) { return new HttpUnauthorizedResult(); } var administrationJobsVoting = adminJobsVotingsRepository.GetById(id); if(administrationJobsVoting == null) { return HttpNotFound(); } var currentPerson = personsRepository.GetPersonByUsername(User.Identity.Name); var isCurrentPersonOwner = administrationJobsVoting.Building.GetOwners().Contains(currentPerson); if(!isCurrentPersonOwner) { return new HttpUnauthorizedResult(); } var votingVoteModel = Mapper.Map<AdministrationJobsVoting, VotingVoteModel>(administrationJobsVoting); LinksModel links = new LinksModel(); if (Session["lastPageId"] != null) { links.Id = (int)Session["lastPageId"]; links.Links = NavLinksGenerator.GetOwnerLinks(administrationJobsVoting.Building, "Rad uprave"); } var model = new VoteModel() { Vote = votingVoteModel, Roles = Roles.GetRolesForUser(), CurrentRole = "owner", Links = links }; return View(model); }