Example #1
0
        public void PostNews()
        {
            var unity              = Cms.MvcApplication.Container;
            var newsService        = unity.Resolve <IRepository2 <News> >();
            var simpleValueService = unity.Resolve <SimpleValueService>();

            simpleValueService.EnableTracking();
            var siteObjectService = unity.Resolve <ISiteObjectRelationService>();

            var yesterday        = DateTime.Today.AddDays(-1);
            var lastPostedNewsId = simpleValueService.LastPostedNewsId;
            var news             = newsService
                                   .GetAll(x => x.IsActive && x.PublishDate == yesterday && x.NewsID > lastPostedNewsId)
                                   .OrderBy(x => x.NewsID).FirstOrDefault();

            if (news != null)
            {
                simpleValueService.LastPostedNewsId = news.NewsID;
                simpleValueService.SubmitChanges();

//				var tags =  siteObjectService.GetRelation(typeof (News),
//					_.List<object>(news.NewsID)).Select(x => x.RelationObject.Name)
//					.Where(x => !x.Contains(" ")).Take(3).ToList()
//					.Select(x => "#" + x).ToList().AddFluent("#курсы #обучение").JoinWith(" ");
                var link = CommonConst.SiteRoot + "/news/" + news.NewsID;
//				var fbmessage = news.ShortDescription + Environment.NewLine + link + Environment.NewLine + tags;
//				var vkmessage = news.ShortDescription + Environment.NewLine + link;
//				var imgUrl = GetImgUrl(news.Description);
//				imgUrl = imgUrl ?? Images.NewsSmall(news).GetSrc();
                Logger.Run(() => new OdnoklassnikiService().PostNews(link), "socialtask");
//				Logger.Run(() => new FacebookService(SpecFBToken).PostSpecUpdate(fbmessage, imgUrl), "socialtask");
                //Logger.Run(() => new VkontakteService(VkontakteService.Token).PostSpecUpdate(vkmessage, imgUrl),
//					"socialtask");
            }
        }
Example #2
0
        public void PostDiscounts()
        {
            var unity = Cms.MvcApplication.Container;
            var simpleValueService = unity.Resolve <SimpleValueService>();

            simpleValueService.EnableTracking();
            var groupService  = unity.Resolve <IGroupService>();
            var courseService = unity.Resolve <ICourseService>();

            if (simpleValueService.LastPostDiscountsDate.AddDays(2) <= DateTime.Today)
            {
                var treeDays = DateTime.Today.AddDays(3);
                var groups   = groupService.GetPlannedAndNotBegin().Where(x => x.Discount > 0 &&
                                                                          x.DateBeg > treeDays).Take(10).ToList();
                var texts      = _.List("Курсы со скидкой на " + DateTime.Today.DefaultString());
                var groupLines = groups.Select(x => {
                    var course = courseService.AllCourseLinks()[x.Course_TC];
                    var link   = Links.CourseLinkAnchor(null, course.UrlName, course.WebName);
                    return("{0} {1} — {2}% скидка".FormatWith(x.DateBeg.ShortString(),
                                                              link.ToFbLink(), x.Discount));
                });
                texts.AddRange(groupLines);
                texts.Add(H.Anchor(SimplePages.FullUrls.GroupDiscounts,
                                   "Все скидки на " + DateTime.Today.DefaultString()).ToFbLink());
                var text = texts.JoinWith("\n");
                Logger.Run(() => new FacebookService(SpecFBToken).PostSpecUpdate(text, null), "postdiscounts");
                simpleValueService.LastPostDiscountsDate = DateTime.Today;
                simpleValueService.SubmitChanges();
            }
        }