public GroupEditCandidatePetitionViewModel(Candidate candidate)
 {
     if (candidate != null)
     {
         CandidateId = candidate.Id;
         IsConfirmed = (CandidateStatus)candidate.Status == CandidateStatus.Confirmed;
         if (candidate.Petition != null)
             Text = candidate.Petition.Text;
         GroupId = candidate.GroupMember.GroupId;
         GroupName = candidate.GroupMember.Group.Name;
         GroupUrl = candidate.GroupMember.Group.Url;
     }
 }
예제 #2
0
 public static Petition CreateCandidatePetition(Candidate candidate, string text = null)
 {
     return _votingService.CreateCandidatePetition(candidate, text);
 }
예제 #3
0
        public Petition CreateCandidatePetition(Candidate candidate, string text = null)
        {
            var election = candidate.Election;
            var user = candidate.GroupMember.User;

            Petition petition = VotingService.CreatePetition(new PetitionContainer
            {
                GroupId = election.GroupId.Value,
                Title = "Выдвижение " + user.FullName + " в качестве кандидата на " + election.Title,
                Tags = "Выборы, Петиция кандидата",
                IsPrivate = true
            }, user.Id, false);

            if (string.IsNullOrEmpty(text))
                petition.Text = "Подпишите петицию, если вы хотите, чтобы я участвовал в выборах";
            else
                petition.Text = text;
            petition.State = (byte)ContentState.Approved;
            petition.PublishDate = DateTime.Now;
            petition.Candidate = candidate;

            DataService.PerThread.SaveChanges();

            return petition;
        }
        public Group_ElectionVoting_CandidateViewModel(Candidate candidate, int totalMembersCount, bool voted)
        {
            if (candidate != null)
            {
                Id = candidate.Id;
                UserId = candidate.GroupMember.UserId;
                Avatar = ImageService.GetImageUrl<User>(candidate.GroupMember.User.Avatar);
                FullName = candidate.GroupMember.User.FullName;
                IsChecked = voted;

                PetitionId = candidate.Petition == null ? (Guid?)null : candidate.Petition.Id;
                if (candidate.Petition != null)
                {
                    var signs = candidate.Petition.Signers.Count;
                    PetitonSigns = DeclinationService.OfNumber(signs, "подпись", "подписи", "подписей");
                    PetitonRelativeSigns = ((float)signs) / totalMembersCount;
                    PetitonSummary = TextHelper.CleanTags(candidate.Petition.Text);
                    if (PetitonSummary.Length > 140)
                        PetitonSummary = PetitonSummary.Substring(0, 140)+"...";
                }
            }
        }
예제 #5
0
        public Group_Election_CandidateViewModel(Candidate candidate, GroupMember gm)
        {
            if (candidate != null)
            {
                Id = candidate.Id;
                UserId = candidate.GroupMember.UserId;
                Avatar = ImageService.GetImageUrl<User>(candidate.GroupMember.User.Avatar);
                FullName = candidate.GroupMember.User.FullName;
                Votes = DeclinationService.OfNumber(candidate.Electorate.Count, "голос", "голоса", "голосов");
                PetitionId = candidate.Petition == null ? (Guid?)null : candidate.Petition.Id;

                if (gm != null)
                    IsChecked = candidate.Electorate.Count(x => x.OwnerId == gm.Id) > 0;
            }
        }
예제 #6
0
        private void FixupCandidate(Candidate previousValue)
        {
            if (previousValue != null && ReferenceEquals(previousValue.Petition, this))
            {
                previousValue.Petition = null;
            }

            if (Candidate != null)
            {
                Candidate.Petition = this;
            }
        }
예제 #7
0
        private void FixupCandidate(Candidate previousValue)
        {
            if (previousValue != null && ReferenceEquals(previousValue.GroupMember, this))
            {
                previousValue.GroupMember = null;
            }

            if (Candidate != null)
            {
                Candidate.GroupMember = this;
            }
        }
예제 #8
0
 public static Petition CreateCandidatePetition(Candidate candidate, string text = null)
 {
     return(_votingService.CreateCandidatePetition(candidate, text));
 }