public SubscribeController(SubscribeService subscribeService, UsersService usersService, CourseService courseService, SessionsService sessionsService)
 {
     _subscribeService = subscribeService;
     _usersService     = usersService;
     _courseService    = courseService;
     _sessionsService  = sessionsService;
 }
Exemple #2
0
        protected internal Task OnReceiveAsync(string msg, string key)
        {
            var ed = SubscribeService.GetEventDeclare(key);

            if (ed == null)
            {
                return(Task.FromResult <string>(null));
            }
            if (ed.IsArray && !ed.IsCopy)
            {
                var obj = msg.ToObject(ed.EventDataType.GenericTypeArguments[0]);
                var ed2 = SubscribeService.GetEventDeclare(ed.GetArrayName());
                ed2.setCache(obj);
                //转成集合
                if (ed2.CacheData.Count >= ed2.ListTake)
                {
                    ed2.rePublish();
                }
                return(Task.FromResult <string>(null));
            }
            else
            {
                var obj = msg.ToObject(ed.EventDataType);
                return((Task)ed.MethodInvoke.Invoke(ed.CreateServiceInstance(), new object[] { obj }));
            }
        }
Exemple #3
0
 public ResourceController(ResourseService resourseService, SubscribeService subscribeService, UsersService usersService, SessionsService sessionsService)
 {
     _resourseService  = resourseService;
     _subscribeService = subscribeService;
     _usersService     = usersService;
     _sessionsService  = sessionsService;
 }
Exemple #4
0
        static void Main(string[] args)
        {
            DirectRabbitMQTest.test();
            return;

            var config = new QueueConfig();

            //config.UseRabbitMQ("127.0.0.1", "guest", "guest");
            //config.UseRedis("[email protected]:6389");
            config.UseMongoDb("mongodb://*****:*****@127.0.0.1:27017/test");
            var client = new Publisher(config);

            client.Publish("timeTest", DateTime.Now);

            var subService = new SubscribeService(config);

            //注册方式订阅
            //subService.Register(System.Reflection.Assembly.GetAssembly(typeof(SubscribeTest)));
            //subService.StartSubscribe();

            //手动指定订阅
            subService.StartSubscribe <List <DateTime> >(new SubscribeAttribute("timeTest"), b =>
            {
                Console.WriteLine(b);
            });
label1:
            client.Publish("timeTest", DateTime.Now);
            client.Publish("intTest", DateTime.Now.Second);
            var n = client.GetQueueLength("timeTest");

            Console.WriteLine("send ok " + n);
            Console.ReadLine();
            goto label1;
        }
        /// <summary>
        /// 处理取消关注事件
        /// </summary>
        /// <param name="requestMessage">请求消息</param>
        /// <returns></returns>
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            SubscribeService ss = new SubscribeService();

            ss.UnSubscribe(requestMessage);
            return(null);
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        SetMeta(new MetaInfo(string.Format("{0} - {1}", SettingsMain.ShopName, Resources.Resource.Client_SubscribeDeactivate_DeleteSubscribe)), null);

        if (!IsPostBack)
        {
            if (Page.Request["ID"] != null)
            {
                try
                {
                    var temp = SubscribeService.SubscribeGetEmailCountByDeactivateCode(Page.Request["ID"]);
                    if (temp != 1)
                    {
                        ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_SubscribeDeactivate_DamageLink);
                        return;
                    }

                    var email = SubscribeService.SubscribeDeleteEmail(Page.Request["ID"]);
                    if (SettingsMailChimp.MailChimpActive)
                    {
                        MailChimp.UnsubscribeListMember(SettingsMailChimp.MailChimpId,
                                                        SettingsMailChimp.MailChimpRegUsersList, email);
                    }
                    MultiView1.SetActiveView(viewMessage);
                    lblInfo.Text    = Resources.Resource.Client_SubscribeDeactivate_Deactivated;
                    lblInfo.Visible = true;
                }
                catch (Exception ex)
                {
                    AdvantShop.Diagnostics.Debug.LogError(ex);
                    ShowMessage(Notify.NotifyType.Error, ex.Message + " at Subscribe <br/>");
                }
            }
        }
    }
        public async Task <ActionResult> Unsubscribe()
        {
            var user = await _adminRepository.GetUserAsync(CurrentUser);

            user.SubsciptionStatus = SubscribeService.Unsubscribe(user.SubscriptionId);
            await _adminRepository.UpdateUserAsync(user);

            return(RedirectToAction("Index", "AdminSubscription", new { message = "You unsubscribed successfully" }));
        }
        public void GetAllElements_RequestOfCollection_CollectionIsNotNull()
        {
            var mock = new Mock <IUnitOfWork>();

            mock.Setup(a => a.Subscribs.GetAllElements()).Returns(new List <Subscribe>());
            var service = new SubscribeService(mock.Object);

            var result = service.GetAllElements() as IEnumerable <SubscribeDTO>;

            Assert.IsNotNull(result);
        }
Exemple #9
0
        //todo:mazq,by zhengw:需走查以下变更:向帖吧用户推送动态

        /// <summary>
        /// 获取接收人UserId集合
        /// </summary>
        /// <param name="activityService">动态业务逻辑类</param>
        /// <param name="ownerId">动态拥有者Id</param>
        /// <param name="userId">动态发布者Id</param>
        /// <param name="activityItemKey">动态项目标识</param>
        /// <returns></returns>
        IEnumerable <long> IActivityReceiverGetter.GetReceiverUserIds(ActivityService activityService, Activity activity)
        {
            SubscribeService   subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
            IEnumerable <long> followerUserIds  = subscribeService.GetUserIdsOfObject(activity.OwnerId);

            if (followerUserIds == null)
            {
                return(new List <long>());
            }
            return(followerUserIds.Where(n => IsReceiveActivity(activityService, n, activity)));
        }
        public async Task <ActionResult> Success(string session_id)
        {
            var user = await _adminRepository.GetUserAsync(CurrentUser);

            SubscriptionModel subscriptionModel = SubscribeService.Success(session_id, CurrentCompany);

            user.SubscriptionId    = subscriptionModel.SubscriptionId;
            user.SubsciptionStatus = subscriptionModel.SubsciptionStatus;
            await _adminRepository.UpdateUserAsync(user);

            return(RedirectToAction("Index", "AdminSubscription", new { message = "You subscribed successfully" }));
        }
Exemple #11
0
        /// <summary>
        /// 更新帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="sectionedFile">帖吧标识图</param>
        public void Update(BarSection section, long userId, IEnumerable <long> managerIds, Stream sectionedFile)
        {
            EventBus <BarSection> .Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Update()));



            //上传Logo
            if (sectionedFile != null)
            {
                LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                section.LogoImage = logoService.UploadLogo(section.SectionId, sectionedFile);
            }

            auditService.ChangeAuditStatusForUpdate(userId, section);
            barSectionRepository.Update(section);

            if (managerIds != null && managerIds.Count() > 0)
            {
                List <long> mangagerIds_list = managerIds.ToList();
                mangagerIds_list.Remove(section.UserId);
                managerIds = mangagerIds_list;
            }
            barSectionRepository.UpdateManagerIds(section.SectionId, managerIds);

            if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());

                //帖吧主、吧管理员自动关注本帖吧
                int  followedCount = 0;
                bool result        = subscribeService.Subscribe(section.SectionId, section.UserId);
                if (result)
                {
                    followedCount++;
                }
                if (managerIds != null && managerIds.Count() > 0)
                {
                    foreach (var managerId in managerIds)
                    {
                        result = subscribeService.Subscribe(section.SectionId, managerId);
                        if (result)
                        {
                            followedCount++;
                        }
                    }
                }

                //增加帖吧的被关注数
                CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
            }
            EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Update()));
        }
        public void GetElement_InputExistingId_SubscribeReturned()
        {
            int?SubscribeId = 2;
            var mock        = new Mock <IUnitOfWork>();

            mock.Setup(a => a.Subscribs.GetElement(SubscribeId.Value)).Returns(new Subscribe());
            var service = new SubscribeService(mock.Object);

            var result = service.GetElement(SubscribeId.Value) as SubscribeDTO;

            Assert.IsNotNull(result);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            UnitWork.Instance.Register((services) =>
            {
                services.AddScoped <Forward.Core.Forward>();

                services.AddSingleton <MaillService>();
                services.AddSingleton <OrderService>();

                services.AddSingleton(typeof(IConfig), (serviceProvider) =>
                {
                    var instance = new Config();
                    instance.TryAdd <MaillService>("maill");
                    return(instance);
                });
            });
            UnitWork.Instance.Builder();

            var subscribe = new SubscribeService();

            subscribe.AddService <MaillService, OrderService>((response) =>
            {
                if (response is bool checkResponse)
                {
                    if (checkResponse)
                    {
                        return(new OrderModel
                        {
                            Title = "Subscribe and Create Order",
                            PayMoney = 1,
                            CreateTime = DateTime.Now
                        });
                    }
                }

                return(null);
            });

            DiagnosticListener.AllListeners.Subscribe(subscribe);

            var mApiServer = new HttpApiServer();

            mApiServer.ActionFactory.ControllerInstance += (o, e) =>
            {
                e.Controller = UnitWork.Instance.ServiceProvider.GetRequiredService(e.Type);
            };
            mApiServer.Register(Assembly.Load("Forward.Core"));
            mApiServer.Open();

            Console.ReadLine();
        }
Exemple #14
0
        public void DeleteSubscribe(int projectId)
        {
            var user    = UserService.Include(t => t.Subscriber).Find(s => s.login == User.Identity.Name);
            var project = ProjectService
                          .Include(t => t.ProjectSubscribers)
                          .Find(t => t.Id == projectId);

            var link = project.Subscribers.FirstOrDefault(t => t.Id == user.Subscriber.Id);

            SubscribeService.RemoveLink(new ProjectSubscriber()
            {
                ProjectsId = projectId, SubscribersId = link.Id
            });
        }
Exemple #15
0
    protected void btnSubscribe_Click(object sender, EventArgs e)
    {
        try
        {
            if (SubscribeService.IsExistInSubscribeEmails(txtEmail.Text))
            {
                //MultiView1.SetActiveView(ViewEmailSend);
                //lblError.Visible = true;
                ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_Subscribe_EmailAlreadyReg);
                return;
            }

            if (SubscribeService.IsExistInCustomerEmails(txtEmail.Text))
            {
                //MultiView1.SetActiveView(ViewEmailSend);
                //lblError.Visible = true;
                ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_Subscribe_EmailAlreadyReg);
                return;
            }

            string strActivateCode   = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + DateTime.Now.Second.ToString();
            string strDeactivateCode = DateTime.Now.Millisecond.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Second.ToString();

            SubscribeService.SubscribeInsertEmail(txtEmail.Text, strActivateCode, strDeactivateCode);
            string strLink  = "<a href=\'" + AdvantShop.Configuration.SettingsMain.SiteUrl + "/subscribe.aspx?ID=" + strActivateCode + "\'>" + AdvantShop.Configuration.SettingsMain.SiteUrl + "/subscribe.aspx?ID=" + strActivateCode + "</a>";
            var    clsParam = new ClsMailParamOnSubscribeActivate {
                Link = strLink
            };
            string message = SendMail.BuildMail(clsParam);


            SendMail.SendMailNow(txtEmail.Text, Resources.Resource.Client_Subscribe_NewSubscribe, message, true);

            MultiView1.SetActiveView(ViewEmailSend);
            //--------------------------

            txtEmail.Text   = string.Empty;
            lblInfo.Visible = true;
            lblInfo.Text    = Resources.Resource.Client_Subscribe_RegSuccess + @" <br /><br />" +
                              Resources.Resource.Client_Subscribe_Instruction;
            //ShowMessage(Notify.NotifyType.Notice, Resources.Resource.Client_Subscribe_RegSuccess + @" <br /><br />" + Resources.Resource.Client_Subscribe_Instruction);
            //lblInfo.ForeColor = System.Drawing.Color.Black;
        }
        catch (Exception ex)
        {
            AdvantShop.Diagnostics.Debug.LogError(ex);
            //lblError.Visible = true;
            ShowMessage(Notify.NotifyType.Error, ex.Message + @" at Subscribe");
        }
    }
        public Service1()
        {
            basketRepository       = new Repository <Basket>();
            basketItemRepository   = new Repository <BasketItem>();
            coffeeRepository       = new Repository <Coffee>();
            courseRepository       = new Repository <Course>();
            productRepository      = new Repository <Product>();
            subscriptionRepository = new Repository <Subscription>();
            userRepository         = new Repository <User>();

            basketService    = new BasketService();
            productService   = new ProductService();
            subscribeService = new SubscribeService();
            userService      = new UserService();
        }
Exemple #17
0
    protected void Page_Load(object sender, EventArgs e)
    {
        SetMeta(new MetaInfo(string.Format("{0} - {1}", AdvantShop.Configuration.SettingsMain.ShopName, Resources.Resource.Client_Subscribe_NewSubscribe)), null);

        if (!IsPostBack)
        {
            if (Request["emailtosubscribe"] != null)
            {
                txtEmail.Text = Request["emailtosubscribe"];
                if (ValidationHelper.IsValidEmail(txtEmail.Text))
                {
                    btnSubscribe_Click(sender, e);
                }
            }

            if (Page.Request["ID"] != null)
            {
                //lblActivated.Visible = true;
                //MultiView1.SetActiveView(ViewEmailSend);
                try
                {
                    var temp = SubscribeService.SubscribeGetEmailCountByActivateCode(Page.Request["ID"]);
                    if (temp != 1)
                    {
                        ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_Subscribe_DamageLink);
                        //lblActivated.Text = Resources.Resource.Client_Subscribe_DamageLink;
                        //lblActivated.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                    SubscribeService.SubscribeUpdateEnableByActivateCode(Page.Request["ID"]);
                    MultiView1.SetActiveView(ViewEmailSend);
                    lblInfo.Text    = Resource.Client_Subscribe_Activated;
                    lblInfo.Visible = true;
                    //lblActivated.Text = Resources.Resource.Client_Subscribe_Activated;
                    //lblActivated.ForeColor = System.Drawing.Color.Black;
                }
                catch (Exception ex)
                {
                    AdvantShop.Diagnostics.Debug.LogError(ex);
                    //lblError.Visible = true;
                    ShowMessage(Notify.NotifyType.Error, ex.Message + @" at Subscribe");
                }
            }
        }
    }
Exemple #18
0
        /// <summary>
        /// 帖吧申请处理结果通知
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        void BarSectionNoticeEventModule_After(BarSection sender, CommonEventArgs eventArgs)
        {
            if (eventArgs.EventOperationType == EventOperationType.Instance().Approved() || eventArgs.EventOperationType == EventOperationType.Instance().Disapproved())
            {
                IUserService  userService   = DIContainer.Resolve <IUserService>();
                NoticeService noticeService = DIContainer.Resolve <NoticeService>();
                User          toUser        = userService.GetFullUser(sender.UserId);
                if (toUser == null)
                {
                    return;
                }
                Notice notice = Notice.New();
                notice.UserId             = sender.UserId;
                notice.ApplicationId      = BarConfig.Instance().ApplicationId;
                notice.TypeId             = NoticeTypeIds.Instance().Reply();
                notice.LeadingActorUserId = sender.UserId;
                notice.LeadingActor       = toUser.DisplayName;
                notice.LeadingActorUrl    = SiteUrls.FullUrl(SiteUrls.Instance().SpaceHome(toUser.UserName));
                notice.RelativeObjectId   = sender.SectionId;
                notice.RelativeObjectName = HtmlUtility.TrimHtml(sender.Name, 64);
                if (eventArgs.EventOperationType == EventOperationType.Instance().Approved())
                {
                    //通知吧主,其申请的帖吧通过了审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerApproved();
                }
                else
                {
                    //通知吧主,其申请的帖吧未通过审核
                    notice.TemplateName = NoticeTemplateNames.Instance().ManagerDisapproved();
                }

                notice.RelativeObjectUrl = SiteUrls.FullUrl(SiteUrls.Instance().SectionDetail(sender.SectionId));
                noticeService.Create(notice);
            }
            else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
            {
                SubscribeService   subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                IEnumerable <long> userIds          = subscribeService.GetTopUserIdsOfObject(sender.SectionId, int.MaxValue);

                foreach (long userId in userIds)
                {
                    subscribeService.CancelSubscribe(sender.SectionId, userId);
                }
            }
        }
Exemple #19
0
        public IActionResult Profile()
        {
            var user = UserService
                       .Include(t => t.Email)
                       .Include(t => t.Creator)
                       .Include(t => t.Projects)
                       .Include(t => t.RolesUsers)
                       .Find(t => t.login == User.Identity.Name);

            user.Subscriber = SubscribeService
                              .Include(t => t.ProjectSubscribers)
                              .Find(t => t.UserId == user.Id);
            user.Worker = WorkerService
                          .Include(t => t.SkillWorkers)
                          .Include(t => t.SkillWorkers)
                          .Include(t => t.Projects)
                          .Find(s => s.UserId == user.Id);
            return(View("Edit", user));
        }
    protected void btnDeactivate_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtEmailAdress.Text))
        {
            ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_SubscribeDeactivate_NoEmail);
            return;
        }

        try
        {
            if (!SubscribeService.IsExistInSubscribeEmails(txtEmailAdress.Text))
            {
                ShowMessage(Notify.NotifyType.Error, Resources.Resource.Client_SubscribeDeactivate_EmailNotFound);
                return;
            }

            if (!string.IsNullOrEmpty(txtDeactivateReason.Text))
            {
                SubscribeService.SubscribeInsertDeactivateReason(txtDeactivateReason.Text);
            }

            var strDeactivateCode = SubscribeService.SubscribeGetDectivateCodeByEmail(txtEmailAdress.Text);

            string strLink = "<a href=\'" + SettingsMain.SiteUrl + "/subscribedeactivate.aspx?id=" + strDeactivateCode + "\'>" + SettingsMain.SiteUrl + "/subscribedeactivate.aspx?id=" + strDeactivateCode + "</a>";

            var clsParam = new ClsMailParamOnSubscribeDeactivate {
                Link = strLink
            };

            string message = SendMail.BuildMail(clsParam);

            SendMail.SendMailNow(txtEmailAdress.Text, Resources.Resource.Client_SubscribeDeactivate_DeactivateNews, message, true);

            MultiView1.SetActiveView(viewMessage);
            lblInfo.Text    = Resources.Resource.Client_SubscribeDeactivate_EmailSent;
            lblInfo.Visible = true;
        }
        catch (Exception ex)
        {
            AdvantShop.Diagnostics.Debug.LogError(ex);
            ShowMessage(Notify.NotifyType.Error, ex.Message + @" at Subscribe Diactivate");
        }
    }
Exemple #21
0
        static void Main(string[] args)
        {
            var config = new QueueConfig();

            //config.UseRabbitMQ("127.0.0.1", "test", "test");
            //config.UseRedis("[email protected]:6389");
            config.UseMongoDb("mongodb://*****:*****@127.0.0.1:27017/test");
            var client     = new Publisher(config);
            var subService = new SubscribeService(config);

            subService.Register(System.Reflection.Assembly.GetAssembly(typeof(SubscribeTest)));
            subService.StartSubscribe();
label1:
            client.Publish("timeTest", DateTime.Now);
            client.Publish("intTest", DateTime.Now.Second);
            Console.WriteLine("send ok");
            Console.ReadLine();
            goto label1;
        }
Exemple #22
0
        public IActionResult SaveUser(User user)
        {
            if (user.ImageDataLocal != null)
            {
                byte[] imageData = null;
                using (var binaryReader = new BinaryReader(user.ImageDataLocal.OpenReadStream()))
                {
                    imageData = binaryReader.ReadBytes((int)user.ImageDataLocal.Length);
                }
                if (user.Image == null)
                {
                    user.Image = new Image();
                }

                user.Image.Data = imageData;
            }
            else
            {
                user.Image = null;
            }
            user.Worker.User = user;
            user.RolesUsers  = null;
            user.Worker      = null;
            NgProjectService.Save <User, int>(user);
            user.Projects = ProjectService.FindAll(t => t.UserId == user.Id).ToList();
            user.Image    = NgProjectService.FindByFunc <Image, int>(t => t.UserId == user.Id);
            var newuser = UserService
                          .Include(t => t.Email)
                          .Include(t => t.Creator)
                          .Include(t => t.Projects)
                          .Include(t => t.RolesUsers)
                          .Find(t => t.login == User.Identity.Name);

            newuser.Subscriber = SubscribeService.Include(t => t.ProjectSubscribers).Find(t => t.UserId == user.Id);
            newuser.Worker     = WorkerService
                                 .Include(t => t.Projects)
                                 .Include(t => t.SkillWorkers)
                                 .Find(s => s.UserId == user.Id);
            return(View("Edit", newuser));
        }
Exemple #23
0
        /// <summary>
        /// 获取感兴趣的问题
        /// </summary>
        /// <param name="tenantTypeId">租户类型id</param>
        /// <param name="userId">用户id</param>
        /// <param name="topNumber">查询条数</param>
        /// <returns>问题列表</returns>
        public IEnumerable <AskQuestion> GetTopInterestedQuestions(string tenantTypeId, long userId, int topNumber)
        {
            StringBuilder cacheKey = new StringBuilder();

            cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
            cacheKey.AppendFormat("GetTopInterestedQuestions::tenantTypeId-{0}", tenantTypeId);

            //从缓存里取列表,如果缓存里没有就去数据库取
            List <AskQuestion> questions = cacheService.Get <List <AskQuestion> >(cacheKey.ToString());

            if (questions != null && questions.Count() > 0)
            {
                return(questions.Take(topNumber));
            }

            IEnumerable <object> questionIds = null;

            //先查询关注标签下的问题
            //查询用户关注的标签
            SubscribeService   subscribeService = new SubscribeService(TenantTypeIds.Instance().AskTag());
            IEnumerable <long> tagIds           = subscribeService.GetAllObjectIds(userId);

            if (tagIds != null && tagIds.Count() > 0)
            {
                Sql sql;
                Sql whereSql;
                Sql orderSql;
                BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sql, out whereSql, out orderSql);
                sql.InnerJoin("tn_ItemsInTags").On("spb_AskQuestions.QuestionId = tn_ItemsInTags.ItemId")
                .Append(whereSql)
                .Where("tn_ItemsInTags.TenantTypeId = @0", TenantTypeIds.Instance().AskQuestion())
                .Where("tn_ItemsInTags.Id in (@tagIds)", new { tagIds = tagIds })
                .Append(orderSql);
                questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sql);
                questions   = this.PopulateEntitiesByEntityIds(questionIds).ToList();
                if (questions != null && questions.Count() >= topNumber)
                {
                    //加入缓存
                    cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                    return(questions.Take(topNumber));
                }
            }



            //如果查询结果不够topNumber,从关注用户的问题中查找
            //查询用户关注的用户
            FollowService      followService   = new FollowService();
            IEnumerable <long> followedUserIds = followService.GetTopFollowedUserIds(userId, 100, null, Follow_SortBy.FollowerCount_Desc);

            if (followedUserIds != null && followedUserIds.Count() > 0)
            {
                Sql sql;
                Sql whereSql;
                Sql orderSql;
                BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sql, out whereSql, out orderSql);
                sql.Append(whereSql)
                .Where("spb_AskQuestions.UserId in (@followedUserIds)", new { followedUserIds = followedUserIds })
                .Append(orderSql);
                questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sql);
                IEnumerable <AskQuestion> questionsFollow = this.PopulateEntitiesByEntityIds(questionIds);
                if (questionsFollow != null && questionsFollow.Count() > 0)
                {
                    if (questions == null)
                    {
                        questions = new List <AskQuestion>();
                    }
                    questions.AddRange(questionsFollow);
                    questions = questions.Distinct <AskQuestion>().ToList();
                }
                if (questions != null && questions.Count() >= topNumber)
                {
                    //加入缓存
                    cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                    return(questions.Take(topNumber));
                }
            }

            //如果查询结果还不够topNumber,从最新问题中查找
            Sql sqlNew;
            Sql whereSqlNew;
            Sql orderSqlNew;

            BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sqlNew, out whereSqlNew, out orderSqlNew);
            sqlNew.Append(whereSqlNew).Append(orderSqlNew);
            questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sqlNew);
            IEnumerable <AskQuestion> questionsNew = this.PopulateEntitiesByEntityIds(questionIds);

            if (questionsNew != null && questionsNew.Count() > 0)
            {
                if (questions == null)
                {
                    questions = new List <AskQuestion>();
                }
                questions.AddRange(questionsNew);
                questions = questions.Distinct().ToList();
            }
            if (questions != null)
            {
                //加入缓存
                cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                return(questions.Take(topNumber));
            }

            return(questions);
        }
Exemple #24
0
        /// <summary>
        /// 创建帖吧
        /// </summary>
        /// <param name="section">帖吧</param>
        /// <param name="userId">当前操作人</param>
        /// <param name="managerIds">管理员用户Id</param>
        /// <param name="logoFile">帖吧标识图</param>
        /// <returns>是否创建成功</returns>
        public bool Create(BarSection section, long userId, IEnumerable <long> managerIds, Stream logoFile)
        {
            EventBus <BarSection> .Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create()));

            //设置审核状态
            auditService.ChangeAuditStatusForCreate(userId, section);

            if (!(section.SectionId > 0))
            {
                section.SectionId = IdGenerator.Next();
            }

            long id = 0;

            long.TryParse(barSectionRepository.Insert(section).ToString(), out id);

            if (id > 0)
            {
                if (managerIds != null && managerIds.Count() > 0)
                {
                    List <long> mangagerIds_list = managerIds.ToList();
                    mangagerIds_list.Remove(section.UserId);
                    managerIds = mangagerIds_list;
                    barSectionRepository.UpdateManagerIds(id, managerIds);
                }
                if (section.TenantTypeId == TenantTypeIds.Instance().Bar())
                {
                    //帖吧主、吧管理员自动关注本帖吧
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    int  followedCount = 0;
                    bool result        = subscribeService.Subscribe(section.SectionId, section.UserId);
                    if (result)
                    {
                        followedCount++;
                    }
                    if (managerIds != null && managerIds.Count() > 0)
                    {
                        foreach (var managerId in managerIds)
                        {
                            result = subscribeService.Subscribe(section.SectionId, managerId);
                            if (result)
                            {
                                followedCount++;
                            }
                        }
                    }
                    //增加帖吧的被关注数
                    CountService countService = new CountService(TenantTypeIds.Instance().BarSection());
                    countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true);
                }



                //上传Logo
                if (logoFile != null)
                {
                    LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection());
                    section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile);
                    barSectionRepository.Update(section);
                }
                EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create()));

                EventBus <BarSection, AuditEventArgs> .Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null));
            }
            return(id > 0);
        }
Exemple #25
0
        /// <summary>
        /// 是否具有创建BarThread的权限
        /// </summary>
        /// <param name="authorizer"></param>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <param name="errorMessage">无权信息提示</param>
        /// <returns></returns>
        public static bool BarThread_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            errorMessage = string.Empty;
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                errorMessage = "您需要先登录,才能发帖";
                return(false);
            }
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

            if (barSection == null)
            {
                errorMessage = "贴吧不存在";
                return(false);
            }

            if (authorizer.BarSection_Manage(barSection))
            {
                return(true);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreateThread()))
            {
                if (currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarThreadDenied;
                }
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreateThread)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    if (subscribeService.IsSubscribed(sectionId, currentUser.UserId))
                    {
                        return(true);
                    }
                    else
                    {
                        errorMessage = "您需要先关注此帖吧,才能发帖";
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
                else
                {
                    TenantType tenantType = new TenantTypeService().Get(barSection.TenantTypeId);
                    errorMessage = string.Format("只有加入{0}才能发帖", tenantType.Name);
                    return(false);
                }
            }
        }
 public SubscriberModule(SubscribeService service)
 {
     _subscribeService = service;
 }
Exemple #27
0
        /// <summary>
        /// 是否具有创建BarPost的权限
        /// </summary>
        /// <param name="sectionId">所属帖吧Id</param>
        /// <returns></returns>
        public static bool BarPost_Create(this Authorizer authorizer, long sectionId, out string errorMessage)
        {
            IUser currentUser = UserContext.CurrentUser;

            errorMessage = "没有权限回帖";
            BarSectionService barSectionService = new BarSectionService();
            var barSection = barSectionService.Get(sectionId);

            if (barSection == null)
            {
                return(false);
            }

            if (barSection.AuditStatus != AuditStatus.Success)
            {
                errorMessage = "由于贴吧未经过审核,所以不允许发帖";
                return(false);
            }

            if (!authorizer.AuthorizationService.Check(currentUser, PermissionItemKeys.Instance().Bar_CreatePost()))
            {
                if (currentUser != null && currentUser.IsModerated)
                {
                    errorMessage = Resources.Resource.Description_ModeratedUser_CreateBarPostDenied;
                }
                return(false);
            }

            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                //检查是否需要是关注用户才能发帖
                IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
                BarSettings         barSetting         = barSettingsManager.Get();
                if (barSetting.OnlyFollowerCreatePost)
                {
                    if (currentUser == null)
                    {
                        errorMessage = "您需要先登录并关注此帖吧,才能回帖";
                        return(false);
                    }
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    bool             isSubscribed     = subscribeService.IsSubscribed(sectionId, currentUser.UserId);
                    if (!isSubscribed)
                    {
                        errorMessage = "您需要先关注此帖吧,才能回帖";
                    }
                    return(isSubscribed);
                }
            }
            else
            {
                if (authorizer.BarSection_Manage(barSection))
                {
                    return(true);
                }
                bool isTenantMember = authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId);
                if (!isTenantMember)
                {
                    errorMessage = "您需要先加入,才能回帖";
                }
                return(isTenantMember);
            }

            //站点设置是否启用了匿名发帖
            ISiteSettingsManager siteSettingsManager = DIContainer.Resolve <ISiteSettingsManager>();
            SiteSettings         siteSettings        = siteSettingsManager.Get();

            if (siteSettings.EnableAnonymousPosting)
            {
                return(true);
            }

            if (currentUser == null)
            {
                errorMessage = "您必须先登录,才能回帖";
                return(false);
            }
            return(true);
        }
Exemple #28
0
    public bool SaveData()
    {
        if (!ValidateData())
        {
            return(false);
        }

        SettingsMailChimp.MailChimpActive = ckbActive.Checked;
        if (SettingsMailChimp.MailChimpId != txtMailChimpId.Text)
        {
            SettingsMailChimp.MailChimpRegUsersList   = string.Empty;
            SettingsMailChimp.MailChimpUnRegUsersList = string.Empty;
            SettingsMailChimp.MailChimpId             = txtMailChimpId.Text;
        }
        else
        {
            if (!ckbActive.Checked)
            {
                return(true);
            }


            SettingsMailChimp.MailChimpId = txtMailChimpId.Text;
            //if (ddlMailChimpListsAll.SelectedValue == "0")
            //{
            //    MailChimp.UnsubscribeListMembers(SettingsMailChimp.MailChimpId, SettingsMailChimp.MailChimpAllUsersList);
            //}
            //else
            //{
            //    MailChimp.SubscribeListMember(SettingsMailChimp.MailChimpId, ddlMailChimpListsAll.SelectedValue,
            //                                 SubscribeService.SubscribeGetAllCustomerEmails());
            //}

            if (ddlMailChimpListsReg.SelectedValue == "0")
            {
                MailChimp.UnsubscribeListMembers(SettingsMailChimp.MailChimpId, SettingsMailChimp.MailChimpRegUsersList);
            }
            else
            {
                MailChimp.SubscribeListMember(SettingsMailChimp.MailChimpId, ddlMailChimpListsReg.SelectedValue,
                                              SubscribeService.SubscribeGetRegCustomerEmails());
            }

            if (ddlMailChimpListsUnReg.SelectedValue == "0")
            {
                MailChimp.UnsubscribeListMembers(SettingsMailChimp.MailChimpId,
                                                 SettingsMailChimp.MailChimpUnRegUsersList);
            }
            else
            {
                MailChimp.SubscribeListMember(SettingsMailChimp.MailChimpId, ddlMailChimpListsUnReg.SelectedValue,
                                              SubscribeService.SubscribeGetUnRegCustomerEmails());
            }

            SettingsMailChimp.MailChimpRegUsersList   = ddlMailChimpListsReg.SelectedValue;
            SettingsMailChimp.MailChimpUnRegUsersList = ddlMailChimpListsUnReg.SelectedValue;
            //SettingsMailChimp.MailChimpAllUsersList = ddlMailChimpListsAll.SelectedValue;
        }
        LoadData();
        return(true);
    }
Exemple #29
0
 public SubscribeBackgroundService(Microsoft.Extensions.Options.IOptions <QueueConfig> options, SubscribeService _subscribeService, IServiceProvider _serviceProvider)
 {
     queueConfig      = options.Value;
     subscribeService = _subscribeService;
     serviceProvider  = _serviceProvider;
 }
Exemple #30
0
        /// <summary>
        /// 是否具有评分的权限
        /// </summary>
        /// <returns></returns>
        public static bool BarRating(this Authorizer authorizer, BarThread thread, out string errorMessage)
        {
            BarSettings barSettings = DIContainer.Resolve <IBarSettingsManager>().Get();

            errorMessage = "没有找到对应的帖子";
            if (thread == null)
            {
                return(false);
            }
            errorMessage = "您还没有登录";
            IUser currentUser = UserContext.CurrentUser;

            if (currentUser == null)
            {
                return(false);
            }

            if (thread.UserId == currentUser.UserId)
            {
                errorMessage = "您不可以给自己的帖子评分哦";
                return(false);
            }

            BarRatingService barRatingService = new BarRatingService();

            //是否已经评过分
            errorMessage = "您已经评论过此贴";
            if (barRatingService.IsRated(currentUser.UserId, thread.ThreadId))
            {
                return(false);
            }
            errorMessage = "您的剩余积分不够了哦";
            if (barRatingService.GetUserTodayRatingSum(UserContext.CurrentUser.UserId) + barSettings.ReputationPointsMinValue > barSettings.UserReputationPointsPerDay)
            {
                return(false);
            }

            IBarSettingsManager barSettingsManager = DIContainer.Resolve <IBarSettingsManager>();
            BarSettings         barSetting         = barSettingsManager.Get();
            BarSectionService   barSectionService  = new BarSectionService();
            var barSection = barSectionService.Get(thread.SectionId);

            if (barSection == null)
            {
                return(false);
            }
            if (barSection.TenantTypeId == TenantTypeIds.Instance().Bar())
            {
                errorMessage = "此帖吧仅允许关注的用户评分哦";
                if (barSetting.OnlyFollowerCreatePost)
                {
                    SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection());
                    return(subscribeService.IsSubscribed(thread.SectionId, currentUser.UserId));
                }
            }
            else
            {
                if (authorizer.AuthorizationService.IsTenantMember(currentUser, barSection.TenantTypeId, barSection.SectionId))
                {
                    return(true);
                }
            }

            errorMessage = "站点没有开启帖子评分";
            if (!barSetting.EnableRating)
            {
                return(false);
            }
            return(true);
        }