Пример #1
0
        public IBarelyView Edit(BlogRouteModel route, BlogEntryData data)
        {
            var entry = BlogEntryData.Get(route.Date);

            if (Method != HttpMethod.Post)
            {
                //first diplay the page
                var v = new ModifyBlogView();
                v.Entry        = entry;
                v.Layout.Title = "Editing '" + entry.Title + "'";
                return(v);
            }
            else
            {
                //then receive the form and store it
                data.ID     = entry.ID;             //set ID so mongodb can find it (and update it instead of create)
                data.Posted = entry.Posted;
                if (!entry.Publish && data.Publish) //if not previously published, update the time so it's "bumped"
                {
                    data.Posted = DateTime.Now;     //this shouldn't have any SEO implications unless I unpublish and then republish.
                }
                data.Edited = DateTime.Now;
                BetterCache.Remove <string>(data.ID.ToString());
                data.Save();
                Response.Redirect(GetUrl(data));
                return(null);                //never actually reaches here
            }
        }
Пример #2
0
        public IBarelyView Index()
        {
            var c = BlogEntryData.All().Find(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted"));

            c = c.SetLimit(Config.PageSize);
            var entries = new List <BlogEntryData>();

            foreach (var e in c)
            {
                string text = BetterCache.Get <string>(e.ID.ToString());
                if (text == null)
                {
                    e.Text = Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text = text;
                }

                entries.Add(e);
            }
            var v = new BlogIndexView();

            v.ShowPaging = true;
            v.Page       = 1;
            v.PageMax    = ((int)c.Count()) / Config.PageSize + 1;
            v.Entries    = entries;

            v.Layout.Active = "home";
            v.Layout.Title  = "Earlz.Net - Programming, Electronics, Hacking, Oh My!";
            return(v);
        }
Пример #3
0
        public IBarelyView View(BlogRouteModel route)
        {
            BlogEntryData entry;

            try{
                entry = BlogEntryData.Get(route.Date);
            }catch {
                throw new HttpException(404, "Blog entry not found");
            }
            if (entry == null)
            {
                throw new HttpException(404, "Blog entry not found");
            }
            if (GetUrl(entry) != Request.Url.AbsolutePath)
            {
                PermanentRedirect(GetUrl(entry));
            }
            string text = BetterCache.Get <string>(entry.ID.ToString());

            if (text == null)
            {
                entry.Text = Config.GetMarkdown().Transform(entry.Text);
                BetterCache.Add(entry.ID.ToString(), entry.Text);
            }
            else
            {
                entry.Text = text;
            }
            var v = new BlogEntryView();

            v.Layout.Title = "";
            if (entry.Tags != null)
            {
                v.Layout.Title = entry.Tags[0] + " - ";
            }
            v.Layout.Title += entry.Title + " - Earlz.Net";
#if DEBUG
            v.Layout.Title += "-" + entry.ID.ToString();
#endif
            v.ShowComments = true;
            v.Entry        = entry;
            v.Summary      = false;
            return(v);
        }
Пример #4
0
        public IBarelyView Index(int page)
        {
            var c = BlogEntryData.All().FindAs <BlogEntryData>(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted"));

            page -= 1;           //so that routes start with /blog/1 than /blog/0
            if (page == 0)
            {
                PermanentRedirect("/");
            }
            c = c.SetSkip(page * Config.PageSize).SetLimit(Config.PageSize);
            int pagecount = ((int)c.Count()) / Config.PageSize + 1;       //this takes a total count on the collection, not the query.

            var entries = new List <BlogEntryData>();

            foreach (var e in c)
            {
                string text = BetterCache.Get <string>(e.ID.ToString());
                if (text == null)
                {
                    e.Text = Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text = text;
                }

                entries.Add(e);
            }
            if (entries.Count == 0)
            {
                throw new HttpException(404, "not found");
            }
            var v = new BlogIndexView();

            v.ShowPaging    = true;
            page           += 1;
            v.Page          = page;
            v.PageMax       = pagecount;
            v.Entries       = entries;
            v.Layout.Active = "home";
            v.Layout.Title  = "Archive - Page " + (page) + " of " + (v.PageMax) + " - Earlz.Net";
            return(v);
        }
Пример #5
0
        public IBarelyView Get()
        {
            var v = new BlogEntryView();

            v.Layout.Title  = "About Me - Earlz.Net";
            v.Layout.Active = "aboutme";
            v.Entry         = BlogEntryData.All().FindOneAs <BlogEntryData>(Query.In("Tags", new BsonValue[] { "page-aboutme" }));

            string text = BetterCache.Get <string>(v.Entry.ID.ToString());

            if (text == null)
            {
                v.Entry.Text = Config.GetMarkdown().Transform(v.Entry.Text);
                BetterCache.Add(v.Entry.ID.ToString(), v.Entry.Text);
            }
            else
            {
                v.Entry.Text = text;
            }
            v.ShowComments = true;
            v.Summary      = false;
            return(v);
        }