Esempio n. 1
0
        private void _SendInvite(Invite invite)
        {
            if (!string.IsNullOrWhiteSpace(invite.Email))
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("*****@*****.**");
                message.To.Add(new MailAddress(invite.Email));
                message.Subject = "Приглашение на Демократия2";

                if (invite.Referal != null)
                {
                    message.Body = MessageComposer.ComposeInvitationMessage(invite.Referal.Id, invite.Name + " " + invite.Patronymic, invite.Key);
                }
                else
                {
                    message.Body = MessageComposer.ComposeInvitationMessage(invite.Name + " " + invite.Patronymic, invite.Key);
                }

                message.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Send(message);

                smtp.Dispose();
                message.Dispose();

                invite.CreationDate = DateTime.Now;
                invite.State        = (byte)InviteState.Sent;

                DataService.PerThread.SaveChanges();
            }
        }
Esempio n. 2
0
        public static Tag AddTagByUser(string title, string description, GroupMember groupMember)
        {
            var tag = GetTag(title, groupMember.Group, true);

            if (groupMember.State == (byte)GroupMemberState.Approved)
            {
                if (tag.TopicState == (byte)TopicState.NotTopic)
                {
                    tag.TopicState  = (byte)TopicState.ProposedTopic;
                    tag.Description = description;
                }
                else if (tag.TopicState == (byte)TopicState.GroupTopic)
                {
                    throw new ValidationException("Такая тема группы уже существует");
                }
                else if (tag.TopicState == (byte)TopicState.ProposedTopic)
                {
                    throw new ValidationException("Такая тема группы уже преждложена и ожидает решения модераторов.");
                }
            }
            else if (groupMember.State == (byte)GroupMemberState.Moderator)
            {
                if (tag.TopicState == (byte)TopicState.NotTopic || tag.TopicState == (byte)TopicState.ProposedTopic)
                {
                    tag.TopicState    = (byte)TopicState.GroupTopic;
                    tag.Description   = description;
                    tag.IsRecommended = true;
                }
                else if (tag.TopicState == (byte)TopicState.GroupTopic)
                {
                    throw new ValidationException("Такая тема группы уже существует");
                }
            }

            DataService.PerThread.SaveChanges();

            if (groupMember.Group.State == (byte)GroupMemberState.Approved)
            {
                var date = DateTime.Now;
                MessageService.SendToGroup(groupMember.Group,
                                           new MessageStruct
                {
                    Text = MessageComposer.ComposeGroupModeratorNotice(groupMember.Group.Id, "Поступило предложение на добавление новой темы группы: <a href='" + tag.GetTopicUrl(false) + "'>" + tag.Title + "</a>"),
                    Type = (byte)MessageType.GroupModeratorNotice,
                    Date = date
                }
                                           , GroupMessageRecipientType.Moderators);
            }

            return(tag);
        }
Esempio n. 3
0
        public static Comment AddComment(string text, Guid userId, Guid?contentId, Guid?parentCommentId)
        {
            var user = DataService.PerThread.BaseUserSet.OfType <User>().SingleOrDefault(u => u.Id == userId);

            if (user == null)
            {
                throw new BusinessLogicException("Перезайдите");
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                throw new BusinessLogicException("Не введен текст комментария");
            }

            if (!contentId.HasValue && !parentCommentId.HasValue)
            {
                throw new BusinessLogicException("Неверный идентификатор поста");
            }

            var comment = new Comment
            {
                Text   = text,
                UserId = userId
            };

            if (parentCommentId.HasValue)
            {
                var parentComment = DataService.PerThread.CommentSet.SingleOrDefault(c => c.Id == parentCommentId);
                if (parentComment == null)
                {
                    throw new MvcActionRedirectException("Указан неверный идентификатор комментария", "error", "index");//TODO
                }
                var group = parentComment.Content.Group;

                if (group.PrivacyEnum.HasFlag(GroupPrivacy.PrivateDiscussion) && !GroupService.IsUserApprovedInGroup(userId, group))
                {
                    throw new BusinessLogicException("Комментировать могут только члены группы");
                }

                if (parentComment.IsHidden)
                {
                    throw new BusinessLogicException("Данный комментарий скрыт, его нельзя комментировать");
                }

                if (parentComment.ParentComment != null)
                {
                    comment.ReplyTo         = parentComment;
                    comment.ParentCommentId = parentComment.ParentCommentId;
                    comment.ContentId       = parentComment.ParentComment.ContentId;
                }
                else
                {
                    comment.ParentCommentId = parentCommentId;
                    comment.ContentId       = parentComment.ContentId;
                }
            }
            else
            {
                var content = DataService.PerThread.ContentSet.SingleOrDefault(c => c.Id == contentId);
                if (content == null)
                {
                    throw new BusinessLogicException("Указан неверный идентификатор контента");
                }

                if (content.IsDiscussionClosed)
                {
                    throw new BusinessLogicException("Дискуссия по данному вопросу закрыта");
                }

                comment.ContentId = contentId.Value;
            }

            DataService.PerThread.CommentSet.AddObject(comment);
            DataService.PerThread.SaveChanges();

            //сообщение о появлении коммента
            DataService.PerThread.LoadProperty(comment, c => c.Content);
            var commentAuthorId = Guid.Empty;

            if (comment.ParentComment != null)
            {
                if (comment.ReplyTo == null) //Отвечаем на корень ветки
                {
                    if (comment.ParentComment.UserId != comment.UserId)
                    {
                        commentAuthorId = comment.ParentComment.UserId;
                    }
                }
                else //Отвечаем на комментарий внутри ветки
                {
                    if (comment.ReplyTo.UserId != comment.UserId)
                    {
                        commentAuthorId = comment.ReplyTo.UserId;
                    }
                }
            }
            else //Отвечаем на пост
            {
                if (comment.Content.AuthorId != null)
                {
                    if (comment.Content.AuthorId != comment.UserId)
                    {
                        commentAuthorId = comment.Content.AuthorId.Value;
                    }
                }
            }

            if (commentAuthorId != Guid.Empty && comment.User.BlackListsOwners.Count(x => x.Id == commentAuthorId) == 0)
            {
                MessageService.Send(new MessageStruct
                {
                    RecipientId = commentAuthorId,
                    Text        = MessageComposer.ComposeCommentNotice(comment.Id, comment.Text),
                    Type        = (byte)MessageType.CommentNotice,
                    Date        = DateTime.Now
                });
            }

            return(comment);
        }