コード例 #1
0
        public ActionResult Single(long id)
        {
            var blog = repository.GetBlog(id);

            if (blog == null)
            {
                return(ReturnNotFoundView());
            }

            var viewdata = new BlogViewData(baseviewmodel)
            {
                blog        = blog.ToModel(),
                method      = blog.layoutMethod.HasValue?(LayoutMethod)blog.layoutMethod.Value:LayoutMethod.NONE,
                attachments = blog.blog_files.ToModel()
            };

            if (viewdata.method == LayoutMethod.GALLERY)
            {
                viewdata.photos = blog.blog_images.ToModel(Imgsize.GALLERY, Imgsize.BLOG);
            }
            else
            {
                viewdata.photos = blog.blog_images.ToModel(Imgsize.USER_PROFILE);
            }

            return(View(viewdata));
        }
コード例 #2
0
        //
        // GET: /Admin/

        public AdminController()
        {
            model = new BlogViewData();

            // Fill four of the most recent blogs
            model.allTags = (from tag in db.Tags
                             orderby tag.name ascending
                             select tag).ToList();
        }
コード例 #3
0
        //
        // GET: /Blog/Date/Id/Title/
        public ActionResult Article(int?id)
        {
            BlogViewData blogData = new BlogViewData();

            blogData.BlogCategories = blogDB.BlogCategories.OrderBy(c => c.Name).Where(c => c.Blogs.Count > 0).ToList();
            blogData.RecentPosts    = blogDB.BlogArticles.OrderByDescending(c => c.DateCreated).Take(5).ToList();
            blogData.Blog           = blogDB.BlogArticles.Find(id);
            return(View(blogData));
        }
コード例 #4
0
        // GET: /blog/category/id/categoryname
        public ActionResult Category(int?id, string categoryName)
        {
            BlogViewData blogData = new BlogViewData();

            blogData.BlogInCategories = blogDB.BlogArticles.Where(c => c.CategoryId == id).OrderByDescending(c => c.DateCreated).ToList();
            blogData.BlogCategories   = blogDB.BlogCategories.OrderBy(c => c.Name).Where(c => c.Blogs.Count > 0).ToList();
            blogData.RecentPosts      = blogDB.BlogArticles.OrderByDescending(c => c.DateCreated).Take(5).ToList();
            blogData.CurrentCategory  = blogDB.BlogCategories.Single(c => c.BlogCategoryId == id);
            return(View(blogData));
        }
コード例 #5
0
        public HomeController()
        {
            blogViewData = new BlogViewData();

            // Fill four of the most recent blogs
            blogViewData.allBlogs = (from blog in db.Blogs
                                     orderby blog.date descending
                                     select blog).Take(4).ToList();

            blogViewData.allTags = (from tag in db.Tags
                                    orderby tag.name ascending
                                    select tag).Take(4).ToList();
        }
コード例 #6
0
ファイル: blogController.cs プロジェクト: seanlinmt/ioschools
        public ActionResult Add()
        {
            var viewmodel = new BlogViewData(baseviewmodel);

            viewmodel.blog.pagetitle = "New Circular / News";
            viewmodel.schools        = new[] { new SelectListItem()
                                               {
                                                   Text = "All schools", Value = ""
                                               } }.Union(
                db.schools
                .OrderBy(x => x.id)
                .Select(x => new SelectListItem()
            {
                Text  = x.name,
                Value = x.id.ToString()
            }));

            return(View(viewmodel));
        }
コード例 #7
0
ファイル: blogController.cs プロジェクト: seanlinmt/ioschools
        public ActionResult Edit(long id)
        {
            var blog = repository.GetBlog(id);

            if (blog == null)
            {
                return(ReturnNotFoundView());
            }

            if (sessionid.Value != blog.creator && !auth.perms.HasFlag(Permission.NEWS_ADMIN))
            {
                return(Json("Only creator or admin can edit this entry".ToJsonFail()));
            }

            var viewmodel = new BlogViewData(baseviewmodel)
            {
                blog        = blog.ToModel(),
                photos      = blog.blog_images.ToModel(Imgsize.USER_PROFILE),
                attachments = blog.blog_files.ToModel(),
                method      =
                    blog.layoutMethod.HasValue
                                            ? (LayoutMethod)blog.layoutMethod.Value
                                            : LayoutMethod.NONE,
                schools = new[] { new SelectListItem()
                                  {
                                      Text = "All schools", Value = ""
                                  } }.Union(
                    db.schools
                    .OrderBy(x => x.id)
                    .Select(x => new SelectListItem()
                {
                    Text  = x.name,
                    Value = x.id.ToString()
                }))
            };

            return(View("Add", viewmodel));
        }
コード例 #8
0
        public ActionResult Save(BlogViewData model, string blog_title, string blog_content)
        {
            Blog newBlog = new Blog();

            newBlog.title      = blog_title;
            newBlog.date       = System.DateTime.Now;
            newBlog.content    = blog_content;
            newBlog.creationTS = System.DateTime.Now;
            newBlog.updatedTS  = System.DateTime.Now;
            int[] tagIds = model.SelectedTags;

            List <Tag> selectedTags = new List <Tag>();

            // Get the Tag objects from the DB
            for (int i = 0; i < tagIds.Count(); i++)
            {
                int currentTag = tagIds[i];
                Tag t          = (from tag in db.Tags
                                  where tag.id == currentTag
                                  select tag).FirstOrDefault();
                selectedTags.Add(t);
            }

            // Add the Tag Objects to the Blog Object
            newBlog.tags.AddRange(selectedTags);

            db.Blogs.Add(newBlog);
            db.SaveChanges();

            //Reset the Tags
            model.allTags = (from tag in db.Tags
                             orderby tag.name ascending
                             select tag).ToList();

            return(RedirectToAction("Index"));
        }