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); }
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); }