public BaseUser SignUp(string login, string email, string password, bool saveChanges)
        {
            if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentException();
            }

            Guid hash, salt;

            SecurityService.GeneratePasswordHash(password, out hash, out salt);

            var federation = DataService.PerThread.GroupSet.SingleOrDefault(x => x.Id == ConstHelper.RootGroupId);

            if (federation == null)
            {
                throw new BusinessLogicException("Не создана группа Федерация");
            }

            var encryptedEmail = CryptographyService.EncryptEmail(email);
            var emailUser      = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(x => x.EncryptedEmail == encryptedEmail);

            if (emailUser != null)
            {
                throw new BusinessLogicException("Указанная почта уже используется");
            }

            var user = new User // TODO: Регистрация админов должна идти отдельной функцией
            {
                Login                       = login,
                Email                       = email,
                Password                    = hash,
                Salt                        = salt,
                IsVerified                  = false,
                RegistrationDate            = DateTime.Now,
                LiveJournalSindication      = true,
                LiveJournalSindicateAsDraft = false,
                LastActivity                = DateTime.Now
            };

            user.SubscriptionSettings = new SubscriptionSettings {
                SubscriptionEmail = email
            };

            var gm = new GroupMember
            {
                EntryDate = DateTime.Now,
                GroupId   = federation.Id,
                State     = (byte)GroupMemberState.Approved,
                UserId    = user.Id
            };

            DataService.PerThread.GroupMemberSet.AddObject(gm);
            SubscriptionService.SubscribeToGroup(federation, user);
            VotingService.AnalizeGroupMemberBulletins(gm.Id);

            return(user);
        }
Exemple #2
0
        public void ChangeMemberStatus(Guid userId, Guid groupId, GroupMemberState state)
        {
            var gm = DataService.PerThread.GroupMemberSet.SingleOrDefault(x => x.GroupId == groupId & x.UserId == userId);

            if (gm == null)
            {
                throw new BusinessLogicException("Указанный участник группы не найден");
            }

            if (gm.State != (byte)GroupMemberState.Moderator && state == GroupMemberState.NotMember)
            {
                gm.State = (byte)GroupMemberState.NotMember;
            }

            if (gm.State != (byte)GroupMemberState.Approved && state == GroupMemberState.Approved)
            {
                gm.State = (byte)GroupMemberState.Approved;
                VotingService.AnalizeGroupMemberBulletins(gm.Id);
            }

            if (gm.State != (byte)GroupMemberState.Moderator && state == GroupMemberState.Moderator)
            {
                if (gm.Group.ModeratorsCount > gm.Group.GroupMembers.Count(x => x.State == (byte)GroupMemberState.Moderator))
                {
                    gm.State = (byte)GroupMemberState.Moderator;
                }
                else
                {
                    gm.State = (byte)GroupMemberState.Approved;
                    VotingService.AnalizeGroupMemberBulletins(gm.Id);
                }
            }

            DataService.PerThread.SaveChanges();

            UpdateGroupState(gm.GroupId);
        }
Exemple #3
0
        public void Publish(Content content, Guid userId)
        {
            if (content == null)
            {
                throw new BusinessLogicException("Не найден указанный контент");
            }

            if (content.State != (byte)ContentState.Draft && content.State != (byte)ContentState.Premoderated)
            {
                throw new BusinessLogicException("Данный контент нельзя публиковать");
            }

            if (content.GroupId.HasValue) // Контент привязан к группе
            {
                var member = GroupService.UserInGroup(userId, content.GroupId.Value, true);

                if (content.Group.PrivacyEnum.HasFlag(GroupPrivacy.ContentModeration))
                {
                    if (member.State == (byte)GroupMemberState.Moderator)
                    {
                        content.State = (byte)ContentState.Approved;
                    }
                    else
                    {
                        if (!IsAuthor(content, userId))
                        {
                            throw new BusinessLogicException("Нельзя публиковать чужой контент");
                        }

                        content.State = (byte)ContentState.Premoderated;
                    }
                }
                else
                {
                    if (content is Post && (content as Post).IsExternal)
                    {
                        content.State =
                            member.State == (byte)GroupMemberState.Moderator ? (byte)ContentState.Approved : (byte)ContentState.Premoderated;
                    }
                    else
                    {
                        content.State = (byte)ContentState.Approved;
                    }
                }
            }
            else
            {
                if (!IsAuthor(content, userId))
                {
                    throw new BusinessLogicException("Нельзя публиковать чужой контент");
                }

                content.State = (byte)ContentState.Approved;
            }

            content.PublishDate = DateTime.Now;

            if (content.State == (byte)ContentState.Approved)
            {
                if (content is Poll)
                {
                    VotingService.StartPoll(content.Id, userId);
                }
                else if (content is Survey)
                {
                    VotingService.StartSurvey(content.Id);
                }
            }

            UpdateContentCache(content);
        }
 public override void Execute()
 {
     VotingService.FinishSurvey(_surveyId);
 }
Exemple #5
0
 public override void Execute()
 {
     VotingService.FinishElection(_electionId);
 }
 public override void Execute()
 {
     VotingService.FinishPetition(_petitionId);
 }
Exemple #7
0
 public override void Execute()
 {
     VotingService.SummarizePoll(_pollId);
 }