Ejemplo n.º 1
0
        public ActionResult RssSubscribtion(Guid id)
        {
            var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == id);
            if (user == null)
                return new EmptyResult();

            var groupContent = (from _group in user.SubscriptionGroups
                                join content in DataService.PerThread.ContentSet on _group.Id equals content.GroupId
                                where content.AuthorId != id && content.State == (byte)ContentState.Approved && content.PublishDate.HasValue && (content.Group == null || (content.Group.Privacy & (byte)GroupPrivacy.Invisible) != (byte)GroupPrivacy.Invisible)
                                orderby content.PublishDate descending
                                select content).Take(100);

            var userContent = (from _user in user.SubscriptionUsers
                               join content in DataService.PerThread.ContentSet on _user.Id equals content.AuthorId
                               where content.AuthorId != id && content.State == (byte)ContentState.Approved && content.PublishDate.HasValue && (content.Group == null || (content.Group.Privacy & (byte)GroupPrivacy.Invisible) != (byte)GroupPrivacy.Invisible)
                               orderby content.PublishDate descending
                               select content).Take(100);

            var feed = groupContent.Union(userContent).Distinct().Where(x => x.AuthorId != user.Id).OrderByDescending(c => c.PublishDate.Value);

            var model = new _RssFeedViewModel
            {
                Title = "Демократия2. " + user.FullName + ". Подписка",
                Description = "RSS-лента подписки " + user.FullName + " на Демократии2",
                Link = "http://democratia2.ru/User/Index/" + user.Id
            };

            foreach (var content in feed)
            {
                var info = new StringBuilder();
                info.Append("<p>");
                info.Append("Автор: <a href='" + Url.Action("blog", "user", new { content.Author.Id }, "http") + "'>" + content.Author.FullName + "</a>");
                if (content.Group != null)
                    info.Append("<br/>Группа: <a href='" + Url.Action("index", "group", new { id = content.GroupId }, "http") + "'>" + content.Group.Name + "</a>");
                info.Append("</p>");

                var item = new _RssFeedItemViewModel
                {
                    Title = content.Title,
                    Link = content.GetUrl(false),
                    Description = info + content.Text
                };

                if (content.PublishDate.HasValue)
                    item.PublishDate = content.PublishDate.Value.ToString("R");

                model.Items.Add(item);
            }

            return View("_Rss", "_EmptyLayout", model);
        }
Ejemplo n.º 2
0
        public ActionResult Rss(string id)
        {
            Group group;
            Guid groupGuid;

            if (string.IsNullOrWhiteSpace(id))
                return new EmptyResult();

            if (Guid.TryParse(id, out groupGuid))
                group = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Id == groupGuid);
            else
                group = DataService.PerThread.GroupSet.SingleOrDefault(g => g.Label == id);

            if (group == null || group.PrivacyEnum.HasFlag(GroupPrivacy.Invisible))
                return new EmptyResult();

            var recentContent = group.Content
                .Where(x => x.State == (byte)ContentState.Approved && x.PublishDate.HasValue).OrderByDescending(x => x.PublishDate).Take(100);

            var model = new _RssFeedViewModel
            {
                Title = "Демократия2. " + group.Name + ". RSS",
                Description = "RSS-лента " + group.Name + " на Демократии2",
                Link = "http://democratia2.ru/Group/rss/" + group.Url
            };

            foreach (var content in recentContent)
            {
                var info = new StringBuilder();
                info.Append("<p>");
                info.Append("Автор: <a href='" + Url.Action("blog", "user", new { content.Author.Id }, "http") + "'>" + content.Author.FullName + "</a>");
                info.Append("</p>");

                var description = info + content.Text;
                var item = new _RssFeedItemViewModel
                    {
                        Title = content.Title,
                        Link = content.GetUrl(false),
                        Description = description
                    };

                if (content.PublishDate.HasValue)
                    item.PublishDate = content.PublishDate.Value.ToString("R");

                model.Items.Add(item);
            }

            return View("_Rss", "_EmptyLayout", model);
        }
Ejemplo n.º 3
0
        public ActionResult Rss(Guid id)
        {
            var user = DataService.PerThread.BaseUserSet.OfType<User>().SingleOrDefault(u => u.Id == id);
            if (user == null)
                return new EmptyResult();

            var recentContent = user.Contents
                .Where(x => x.State == (byte)ContentState.Approved && x.PublishDate.HasValue && (x.Group == null || ((x.Group.Privacy & (byte)GroupPrivacy.Invisible) != (byte)GroupPrivacy.Invisible)))
                .OrderByDescending(x => x.PublishDate.Value).Take(100);

            var model = new _RssFeedViewModel
            {
                Title = "Демократия2. " + user.FullName + ". Блог",
                Description = "RSS-лента " + user.FullName + " на Демократии2",
                Link = "http://democratia2.ru/User/Index/" + user.Id
            };

            foreach (var content in recentContent)
            {
                var item = new _RssFeedItemViewModel
                {
                    Title = content.Title,
                    Link = content.GetUrl(false),
                    Description = content.Text
                };

                if (content.PublishDate.HasValue)
                    item.PublishDate = content.PublishDate.Value.ToString("R");

                model.Items.Add(item);
            }

            return View("_Rss", "_EmptyLayout", model);
        }