Esempio n. 1
0
        public void Should_allow_subscriptions_to_sub_topics()
        {
            //Setup.
            const int    userId           = 10;
            const string rootTopicKey     = "News";
            const string oklahomaTopicKey = "News.Oklahoma";
            const string topicKey1        = "News.NewHampshire";
            const string topicKey2        = "News.Oklahoma.Tulsa";
            var          topicService     = new TopicService();

            //Execute.
            topicService.Subscribe(userId, topicKey1);
            topicService.Subscribe(userId, topicKey2);
            var topic1        = topicService.Get(topicKey1);
            var topic2        = topicService.Get(topicKey2);
            var rootTopic     = topicService.Get(rootTopicKey);
            var oklahomaTopic = topicService.Get(oklahomaTopicKey);

            //Verify.
            rootTopic.SubTopics.Should().HaveCount(2);
            oklahomaTopic.SubTopics.Should().HaveCount(1);
            topic1.Subscribers.Should().Contain(userId);
            topic2.Subscribers.Should().Contain(userId);

            //Teardown.
        }
Esempio n. 2
0
        public void Should_allow_subscriptions_to_all_sub_topics()
        {
            //Setup.
            const int    userId1      = 10;
            const int    userId2      = 20;
            const int    userId3      = 30;
            const string rootTopicKey = "News";
            const string topicKey1    = "News.NewHampshire";
            const string topicKey2    = "News.Oklahoma";
            const string topicKey3    = "News.*";
            var          topicService = new TopicService();

            //Execute.
            topicService.Subscribe(userId1, topicKey1);
            topicService.Subscribe(userId2, topicKey2);
            topicService.Subscribe(userId3, topicKey3);
            var topic1    = topicService.Get(topicKey1);
            var topic2    = topicService.Get(topicKey2);
            var rootTopic = topicService.Get(rootTopicKey);

            //Verify.
            topic1.Subscribers.Should().Contain(userId1);
            topic1.Subscribers.Should().NotContain(userId2);
            topic2.Subscribers.Should().Contain(userId2);
            topic2.Subscribers.Should().NotContain(userId1);
            rootTopic.SubTopics.All(x => x.Value.Subscribers.Contains(userId3)).Should().BeTrue();

            //Teardown.
        }
 /// <summary>
 /// 为专题添加分类时触发
 /// </summary>
 private void AddCategoriesToTopic_BatchAfter(IEnumerable <string> senders, TagEventArgs eventArgs)
 {
     if (eventArgs.TenantTypeId == TenantTypeIds.Instance().Topic())
     {
         long groupId = eventArgs.ItemId;
         if (groupSearcher == null)
         {
             groupSearcher = (TopicSearcher)SearcherFactory.GetSearcher(TopicSearcher.CODE);
         }
         groupSearcher.Update(topicService.Get(groupId));
     }
 }
Esempio n. 4
0
        public IActionResult Topic(Guid id)
        {
            Topic topic = _topicService.Get(id);
            IEnumerable <Message> messages = _msgService.GetAllOfTopic(id);

            return(View(new TopicViewModel()
            {
                Topic = topic,
                Messages = messages,
                NewMessage = null
            }));
        }
Esempio n. 5
0
        public ActionResult Edit(Guid Id)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                var cats = _categoryService.GetAllowedEditCategories(UsersRole, false);
                if (cats.Count > 0)
                {
                    var viewModel = new AdminCreateEditTopicViewModel();
                    viewModel.Categories = _categoryService.GetBaseSelectListCategories(cats);

                    var topic = _topicServic.Get(Id);

                    if (topic == null)
                    {
                        TempData[AppConstants.MessageViewBagName] = new GenericMessageViewModel
                        {
                            Message     = LocalizationService.GetResourceString("Errors.NoFindTopic"),
                            MessageType = GenericMessages.warning
                        };

                        return(RedirectToAction("Index"));
                    }

                    viewModel.Id       = topic.Id;
                    viewModel.Name     = topic.Name;
                    viewModel.Category = topic.Category_Id;
                    viewModel.IsLocked = topic.IsLocked;
                    viewModel.IsSticky = topic.IsSticky;
                    viewModel.Image    = topic.Image;

                    viewModel.Intro          = topic.Intro;
                    viewModel.SEOKeyword     = topic.SEOKeyword;
                    viewModel.SEODescription = topic.SEODescription;

                    if (topic.Post_Id != null)
                    {
                        var post = _postSevice.Get((Guid)topic.Post_Id);
                        if (post != null)
                        {
                            viewModel.Content = post.PostContent;
                        }
                    }
                    //viewModel.Po = topic.IsLocked;



                    return(View(viewModel));
                }
                return(ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission")));
            }
        }
Esempio n. 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var navigation = new List <Tuple <string, string> >();
                int topicId    = CustomConvert.ToInt32(RouteData.Values["topicId"]);
                var topic      = TopicService.Get(topicId);

                if (topic == null)
                {
                    Response.RedirectToRoute("NotFound", null);
                }
                else
                {
                    navigation.Add(Tuple.Create(GetRouteUrl("Default", null), "Acasa"));
                    navigation.Add(Tuple.Create(GetRouteUrl("SubjectTopics", new { subjectId = topic.Subject.Id }), topic.Subject.Name));
                    navigation.Add(Tuple.Create(GetRouteUrl("TopicPosts", new { topicId = topic.Id }), topic.Name));
                    Session["Navigation"] = navigation;

                    this.topicId.Value = topicId.ToString();
                    this.sortByDropDownList.DataSource = new List <object>
                    {
                        new { Value = "0", Text = "Data descrescator" },
                        new { Value = "1", Text = "Data crescator" },
                        new { Value = "2", Text = "Autor descrescator" },
                        new { Value = "3", Text = "Autor crescator" }
                    };
                    this.sortByDropDownList.DataValueField = "Value";
                    this.sortByDropDownList.DataTextField  = "Text";
                    this.sortByDropDownList.DataBind();
                    DataBind();
                }
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Topic(int id,
                                                [FromServices] ClientManager clientManager,
                                                [FromServices] CommentService commentService)
        {
            var topic = await TopicService.Get(id);

            return(await this.TopicView(topic, clientManager, commentService));
        }
Esempio n. 8
0
        public async Task <IActionResult> TopicByAlias(string alias,
                                                       [FromServices] ClientManager clientManager,
                                                       [FromServices] CommentService commentService)
        {
            var topic = await TopicService.Get(alias);

            return(await this.TopicView(topic, clientManager, commentService));
        }
Esempio n. 9
0
        public async Task <IActionResult> Get(int id)
        {
            var model = await TopicService.Get(id);

            if (model == null)
            {
                return(Error(L["Article does not exist"].Value));
            }
            return(Success(model));
        }
Esempio n. 10
0
        /// <summary>
        /// 是否为私有状态
        /// </summary>
        /// <param name="sectionId"></param>
        /// <returns></returns>
        public bool IsPrivate(long sectionId)
        {
            TopicEntity group = topicService.Get(sectionId);

            if (group == null)
            {
                return(false);
            }
            return(!group.IsPublic);
        }
Esempio n. 11
0
        // GET: api/Topic/5
        public IHttpActionResult Get(int id)
        {
            IService <Topic> service = new TopicService();
            var item = service.Get(id);

            if (item == null)
            {
                return(NotFound());
            }
            return(Ok(item));
        }
Esempio n. 12
0
        // GET: api/Topic
        public IHttpActionResult Get()
        {
            IService <Topic> service = new TopicService();
            var items = service.Get();

            if (items.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(items));
        }
        public PartialViewResult AjaxMorePosts(GetMorePostsViewModel getMorePostsViewModel)
        {
            // Get the topic
            var topic = TopicService.Get(getMorePostsViewModel.TopicId);

            // Get the permissions for the category that this topic is in
            var permissions = PermissionService.GetPermissions(topic.Category, _membersGroup, MemberService, CategoryPermissionService);

            // If this user doesn't have access to this topic then just return nothing
            if (permissions[AppConstants.PermissionDenyAccess].IsTicked)
            {
                return(null);
            }

            var orderBy = !string.IsNullOrEmpty(getMorePostsViewModel.Order) ?
                          AppHelpers.EnumUtils.ReturnEnumValueFromString <PostOrderBy>(getMorePostsViewModel.Order) : PostOrderBy.Standard;



            var viewModel = new ShowMorePostsViewModel
            {
                Topic       = topic,
                Permissions = permissions,
                User        = CurrentMember
            };

            // Map the posts to the posts viewmodel

            // Get all favourites for this user
            var favourites = new List <Favourite>();

            if (CurrentMember != null)
            {
                favourites.AddRange(FavouriteService.GetAllByMember(CurrentMember.Id));
            }

            // Get the posts
            var posts = PostService.GetPagedPostsByTopic(getMorePostsViewModel.PageIndex, Settings.PostsPerPage, int.MaxValue, topic.Id, orderBy);

            // Get all votes for all the posts
            var postIds      = posts.Select(x => x.Id).ToList();
            var allPostVotes = VoteService.GetAllVotesForPosts(postIds);

            viewModel.Posts = new List <ViewPostViewModel>();
            foreach (var post in posts)
            {
                var postViewModel = PostMapper.MapPostViewModel(permissions, post, CurrentMember, Settings, topic, allPostVotes, favourites);
                viewModel.Posts.Add(postViewModel);
            }

            return(PartialView(PathHelper.GetThemePartialViewPath("AjaxMorePosts"), viewModel));
        }
Esempio n. 14
0
        public void Can_subscribe_to_a_topic()
        {
            //Setup.
            const int    userId       = 10;
            const string topicKey     = "News";
            var          topicService = new TopicService();

            //Execute.
            topicService.Subscribe(userId, topicKey);
            var topic = topicService.Get(topicKey);

            //Verify.
            topic.Subscribers.Should().Contain(userId);

            //Teardown.
        }
Esempio n. 15
0
        public void Should_not_duplicate_subscribers()
        {
            //Setup.
            const int    userId       = 10;
            const string topicKey     = "News";
            var          topicService = new TopicService();

            //Execute.
            topicService.Subscribe(userId, topicKey);
            topicService.Subscribe(userId, topicKey);
            var topic = topicService.Get(topicKey);

            //Verify.
            topic.Subscribers.Count.Should().Be(1);

            //Teardown.
        }
Esempio n. 16
0
        /// <summary>
        /// 设置/取消管理员通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void SetManagerNoticeEventModule_After(TopicMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().SetTopicManager() && eventArgs.EventOperationType != EventOperationType.Instance().CancelTopicManager())
            {
                return;
            }

            TopicService groupService = new TopicService();
            TopicEntity  entity       = groupService.Get(sender.TopicId);

            if (entity == null)
            {
                return;
            }

            User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId);

            if (senderUser == null)
            {
                return;
            }

            NoticeService noticeService = DIContainer.Resolve <NoticeService>();

            Notice notice = Notice.New();

            notice.UserId             = sender.UserId;
            notice.ApplicationId      = TopicConfig.Instance().ApplicationId;
            notice.TypeId             = NoticeTypeIds.Instance().Hint();
            notice.LeadingActorUserId = 0;
            notice.LeadingActor       = string.Empty;
            notice.LeadingActorUrl    = string.Empty;
            notice.RelativeObjectId   = sender.TopicId;
            notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
            notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));

            if (eventArgs.EventOperationType == EventOperationType.Instance().SetTopicManager())
            {
                notice.TemplateName = NoticeTemplateNames.Instance().SetTopicManager();
            }
            else
            {
                notice.TemplateName = NoticeTemplateNames.Instance().CannelTopicManager();
            }
            noticeService.Create(notice);
        }
Esempio n. 17
0
        protected object GetPosts(int topicId)
        {
            try
            {
                var result = TopicService.Get(topicId, x => x.Posts.Select(y => y.CreatedBy))?.Posts
                             .Select(x => new
                {
                    Id                    = x.Id,
                    CreatedAt             = x.CreatedAt,
                    CreatedById           = x.CreatedBy?.Id,
                    CreatedByName         = x.CreatedBy?.FullName,
                    CreatedByProfileImage = x.CreatedBy?.ProfileImage64Url,
                    Text                  = x.Text,
                    CanEdit               = SecurityContext.IsAuthenticated && x.CreatedBy == SecurityContext.User,
                    CanDelete             = SecurityContext.IsManager || SecurityContext.IsAdmin
                }).ToList();

                var order = CustomConvert.ToInt32(this.sortByDropDownList.SelectedValue);

                switch (order)
                {
                case 1:
                    result = result.OrderBy(x => x.CreatedAt).ToList();
                    break;

                case 2:
                    result = result.OrderByDescending(x => x.CreatedByName).ToList();
                    break;

                case 3:
                    result = result.OrderBy(x => x.CreatedByName).ToList();
                    break;

                default:
                    result = result.OrderByDescending(x => x.CreatedAt).ToList();
                    break;
                }

                return(result.ToList <object>());
            }
            catch (Exception exception)
            {
                //handle exception
                return(null);
            }
        }
        Task <bool> IRequestHandler <UpdateChecklistTopicRequest, bool> .Handle(UpdateChecklistTopicRequest request, CancellationToken cancellationToken)
        {
            var existingTopic = TopicService.Get(request.Topic.Id);

            if (existingTopic == null)
            {
                throw new ApplicationException($"UpdateChecklistTopicHandler: Topic with Id {request.Topic.Id} does not exist.");
            }

            //AutoMapper to Map the fields
            Mapper.Map(request.Topic, existingTopic);

            using (var ts = new TransactionScope())
            {
                var updatedTopic = TopicService.Update(existingTopic);

                ts.Complete();
            }
            return(Task.FromResult(true));
        }
 public void ApproveTopic(ApproveTopicViewModel model)
 {
     if (Request.IsAjaxRequest() && User.IsInRole(AppConstants.AdminRoleName))
     {
         using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
         {
             var topic = TopicService.Get(model.Id);
             topic.Pending = false;
             try
             {
                 unitOfWork.Commit();
             }
             catch (Exception ex)
             {
                 unitOfWork.Rollback();
                 LogError(ex);
                 throw ex;
             }
         }
     }
 }
Esempio n. 20
0
        protected void insertPostButton_Click(object sender, EventArgs e)
        {
            var topic = TopicService.Get(CustomConvert.ToInt32(this.topicId.Value));

            if (!SecurityContext.IsAuthenticated)
            {
                throw new NotAuthorizedException();
            }

            try
            {
                var post = new Post(this.newPostText.Text, topic, SecurityContext.User);

                PostService.Create(post);
                PostService.CommitChanges();
                Response.RedirectToRoute("TopicPosts", new { topicId = topic.Id });
            }
            catch
            {
                //handle exception
                this.message.InnerText = GenericErrorMessage;
                this.message.Visible   = true;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void TopicMemberNoticeModule_After(TopicMember sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType != EventOperationType.Instance().Delete() && eventArgs.EventOperationType != EventOperationType.Instance().Create() && sender != null)
            {
                return;
            }
            TopicService groupService = new TopicService();
            TopicEntity  entity       = groupService.Get(sender.TopicId);

            if (entity == null)
            {
                return;
            }

            User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId);

            if (senderUser == null)
            {
                return;
            }

            NoticeService noticeService = DIContainer.Resolve <NoticeService>();
            Notice        notice;

            List <long> toUserIds = new List <long>();

            toUserIds.Add(entity.UserId);
            toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId));
            //删除专题成员通知群管理员
            if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                    {
                        continue;
                    }
                    notice                    = Notice.New();
                    notice.UserId             = toUserId;
                    notice.ApplicationId      = TopicConfig.Instance().ApplicationId;
                    notice.TypeId             = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor       = senderUser.DisplayName;
                    notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId   = sender.TopicId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                    notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                    notice.TemplateName       = NoticeTemplateNames.Instance().MemberQuit();
                    noticeService.Create(notice);
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Create()) //添加群成员时向群管理员发送通知
            {
                foreach (var toUserId in toUserIds)
                {
                    if (toUserId == sender.UserId)
                    {
                        continue;
                    }
                    notice                    = Notice.New();
                    notice.UserId             = toUserId;
                    notice.ApplicationId      = TopicConfig.Instance().ApplicationId;
                    notice.TypeId             = NoticeTypeIds.Instance().Hint();
                    notice.LeadingActorUserId = sender.UserId;
                    notice.LeadingActor       = senderUser.DisplayName;
                    notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                    notice.RelativeObjectId   = sender.TopicId;
                    notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                    notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                    notice.TemplateName       = NoticeTemplateNames.Instance().MemberJoin();
                    noticeService.Create(notice);
                }
                //向加入者发送通知

                //notice = Notice.New();
                //notice.UserId = sender.UserId;
                //notice.ApplicationId = TopicConfig.Instance().ApplicationId;
                //notice.TypeId = NoticeTypeIds.Instance().Hint();
                //notice.LeadingActorUserId = sender.UserId;
                //notice.LeadingActor = senderUser.DisplayName;
                //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(sender.UserId));
                //notice.RelativeObjectId = sender.TopicId;
                //notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
                //notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                //notice.TemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                //noticeService.Create(notice);
            }
        }
        public void UnSubscribe(UnSubscribeEmailViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        // Add logic to add subscr
                        var isCategory = subscription.SubscriptionType.Contains("category");
                        var id         = subscription.Id;

                        if (isCategory)
                        {
                            // get the category
                            var cat = CategoryService.Get(Convert.ToInt32(id));

                            if (cat != null)
                            {
                                // get the notifications by user
                                var notifications = CategoryNotificationService.GetByUserAndCategory(CurrentMember, cat);

                                if (notifications.Any())
                                {
                                    foreach (var categoryNotification in notifications)
                                    {
                                        // Delete
                                        CategoryNotificationService.Delete(categoryNotification);
                                    }
                                }
                            }
                        }
                        else
                        {
                            // get the topic
                            var topic = TopicService.Get(new Guid(id));

                            if (topic != null)
                            {
                                // get the notifications by user
                                var notifications = TopicNotificationService.GetByUserAndTopic(CurrentMember, topic);

                                if (notifications.Any())
                                {
                                    foreach (var topicNotification in notifications)
                                    {
                                        // Delete
                                        TopicNotificationService.Delete(topicNotification);
                                    }
                                }
                            }
                        }

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        throw new Exception(Lang("Errors.GenericMessage"));
                    }
                }
            }
            else
            {
                throw new Exception(Lang("Errors.GenericMessage"));
            }
        }
        public void Subscribe(SubscribeEmailViewModel subscription)
        {
            if (Request.IsAjaxRequest())
            {
                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    try
                    {
                        // Add logic to add subscr
                        var isCategory = subscription.SubscriptionType.Contains("category");
                        var id         = subscription.Id;

                        if (isCategory)
                        {
                            // get the category
                            var cat = CategoryService.Get(Convert.ToInt32(id));

                            if (cat != null)
                            {
                                // Create the notification
                                var categoryNotification = new CategoryNotification
                                {
                                    Category   = cat,
                                    CategoryId = cat.Id,
                                    Member     = CurrentMember,
                                    MemberId   = CurrentMember.Id
                                };
                                //save

                                CategoryNotificationService.Add(categoryNotification);
                            }
                        }
                        else
                        {
                            // get the category
                            var topic = TopicService.Get(new Guid(id));

                            // check its not null
                            if (topic != null)
                            {
                                // Create the notification
                                var topicNotification = new TopicNotification
                                {
                                    Topic    = topic,
                                    Member   = CurrentMember,
                                    MemberId = CurrentMember.Id
                                };
                                TopicNotificationService.Add(topicNotification);
                            }
                        }

                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        throw new Exception(Lang("Errors.GenericMessage"));
                    }
                }
            }
            else
            {
                throw new Exception(Lang("Errors.GenericMessage"));
            }
        }
Esempio n. 24
0
        public async Task <IActionResult> Topic(int id)
        {
            var topic = await TopicService.Get(id);

            return(await this.TopicView(topic));
        }
        /// <summary>
        /// 通知处理程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void TopicMemberApplyNoticeModule_After(TopicMemberApply sender, CommonEventArgs eventArgs)
        {
            TopicService groupService = new TopicService();
            TopicEntity  entity       = groupService.Get(sender.TopicId);

            if (entity == null)
            {
                return;
            }

            User senderUser = DIContainer.Resolve <IUserService>().GetFullUser(sender.UserId);

            if (senderUser == null)
            {
                return;
            }
            InvitationService invitationService = new InvitationService();
            Invitation        invitation;
            NoticeService     noticeService = DIContainer.Resolve <NoticeService>();
            Notice            notice;

            if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Pending)
                {
                    List <long> toUserIds = new List <long>();
                    toUserIds.Add(entity.UserId);
                    toUserIds.AddRange(entity.TopicManagers.Select(n => n.UserId));
                    foreach (var toUserId in toUserIds)
                    {
                        //申请加入专题的请求
                        if (!groupService.IsMember(sender.TopicId, sender.UserId))
                        {
                            invitation = Invitation.New();
                            invitation.ApplicationId      = TopicConfig.Instance().ApplicationId;
                            invitation.InvitationTypeKey  = InvitationTypeKeys.Instance().ApplyJoinTopic();
                            invitation.UserId             = toUserId;
                            invitation.SenderUserId       = sender.UserId;
                            invitation.Sender             = senderUser.DisplayName;
                            invitation.SenderUrl          = SiteUrls.Instance().SpaceHome(sender.UserId);
                            invitation.RelativeObjectId   = sender.TopicId;
                            invitation.RelativeObjectName = entity.TopicName;
                            invitation.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
                            invitation.Remark             = sender.ApplyReason;
                            invitationService.Create(invitation);
                        }
                    }
                }
            }

            string noticeTemplateName = string.Empty;

            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Approved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyApproved();
                }
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                if (sender.ApplyStatus == TopicMemberApplyStatus.Disapproved)
                {
                    noticeTemplateName = NoticeTemplateNames.Instance().MemberApplyDisapproved();
                }
            }

            if (string.IsNullOrEmpty(noticeTemplateName))
            {
                return;
            }

            notice = Notice.New();

            notice.UserId        = sender.UserId;
            notice.ApplicationId = TopicConfig.Instance().ApplicationId;
            notice.TypeId        = NoticeTypeIds.Instance().Hint();
            //notice.LeadingActorUserId = UserContext.CurrentUser.UserId;
            //notice.LeadingActor = UserContext.CurrentUser.DisplayName;
            //notice.LeadingActorUrl = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(UserContext.CurrentUser.UserId));
            notice.RelativeObjectId   = sender.TopicId;
            notice.RelativeObjectName = StringUtility.Trim(entity.TopicName, 64);
            notice.RelativeObjectUrl  = SiteUrls.FullUrl(SiteUrls.Instance().TopicHome(entity.TopicKey));
            notice.TemplateName       = noticeTemplateName;
            noticeService.Create(notice);
        }
Esempio n. 26
0
 public ActionResult <List <Topic> > Get()
 {
     return(_topicService.Get());
 }
 public IEnumerable <Topic> Get() => _topicService.Get();
        public PartialViewResult CreatePost(CreateAjaxPostViewModel post)
        {
            // Make sure correct culture on Ajax Call

            PermissionSet permissions;
            Post          newPost;
            Topic         topic;
            string        postContent;

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Quick check to see if user is locked out, when logged in
                if (CurrentMember.IsLockedOut | !CurrentMember.IsApproved)
                {
                    MemberService.LogOff();
                    throw new Exception(Lang("Errors.NoAccess"));
                }

                // Check for banned links
                if (BannedLinkService.ContainsBannedLink(post.PostContent))
                {
                    throw new Exception(Lang("Errors.BannedLink"));
                }

                topic = TopicService.Get(post.Topic);

                postContent = BannedWordService.SanitiseBannedWords(post.PostContent);

                var akismetHelper = new AkismetHelper();

                // Create the new post
                newPost = PostService.AddNewPost(postContent, topic, CurrentMember, PermissionService, MemberService, CategoryPermissionService, MemberPointsService, out permissions);

                if (!akismetHelper.IsSpam(newPost))
                {
                    try
                    {
                        unitOfWork.Commit();
                    }
                    catch (Exception ex)
                    {
                        unitOfWork.Rollback();
                        LogError(ex);
                        throw new Exception(Lang("Errors.GenericMessage"));
                    }
                }
                else
                {
                    unitOfWork.Rollback();
                    throw new Exception(Lang("Errors.PossibleSpam"));
                }
            }

            //Check for moderation
            if (newPost.Pending)
            {
                return(PartialView(PathHelper.GetThemePartialViewPath("PostModeration")));
            }

            // All good send the notifications and send the post back
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                // Create the view model
                var viewModel = PostMapper.MapPostViewModel(permissions, newPost, CurrentMember, Settings, topic, new List <Vote>(), new List <Favourite>());

                // Success send any notifications
                NotifyNewTopics(topic, postContent);

                return(PartialView(PathHelper.GetThemePartialViewPath("Post"), viewModel));
            }
        }
Esempio n. 29
0
        public async Task <IActionResult> TopicByAlias(string alias)
        {
            var topic = await TopicService.Get(alias);

            return(await this.TopicView(topic));
        }
Esempio n. 30
0
        private AdminMenuEditViewModel CreateEditMenuViewModel(Menu menu)
        {
            var viewModel = new AdminMenuEditViewModel
            {
                Id          = menu.Id,
                ParentMenu  = menu.Menu_Id,
                Name        = menu.Name,
                Description = menu.Description,
                Colour      = menu.Colour,
                iType       = menu.iType,
                Image       = menu.Image,
                SortOrder   = menu.SortOrder,
                AllMenus    = _menuService.GetBaseSelectListMenus(_menuService.GetMenusParenMenu(menu)),
                AllType     = GetTypeLink(),
                AllPage     = GetPageLink(),
                //AllCat = _categoryService.GetBaseSelectListCategories(_categoryService.GetAll()),
                AllCatNews    = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(false)),
                AllCatProduct = _categoryService.GetBaseSelectListCategories(_categoryService.GetList(true)),
            };

            switch (menu.iType)
            {
            case 0:
                viewModel.Link = menu.Link;
                break;

            case 1:
                viewModel.LinkPage = menu.Link;
                break;

            //case 2:
            //    viewModel.LinkCat = menu.Link;
            //    break;
            case 6:
                viewModel.LinkCatNews = menu.Link;
                break;

            case 7:
                viewModel.LinkCatProduct = menu.Link;
                break;

            case 3:
                if (!menu.Link.IsNullEmpty())
                {
                    var a = _topicService.Get(new Guid(menu.Link));
                    if (a != null)
                    {
                        viewModel.LinkNews  = menu.Link;
                        viewModel.TitleNews = a.Name;
                    }
                }
                break;

            case 4:
                if (!menu.Link.IsNullEmpty())
                {
                    var b = _productSevice.Get(new Guid(menu.Link));
                    if (b != null)
                    {
                        viewModel.LinkProduct  = menu.Link;
                        viewModel.TitleProduct = b.Name;
                    }
                }

                break;

            case 5:
                if (!menu.Link.IsNullEmpty())
                {
                    var b = _productSevice.GetProductClass(new Guid(menu.Link));
                    if (b != null)
                    {
                        viewModel.LinkGroupProduct  = menu.Link;
                        viewModel.TitleGroupProduct = b.Name;
                    }
                }
                break;
            }

            return(viewModel);
        }