Exemplo n.º 1
0
        public PostIndexModelPost(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title.ToString();

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Comments  = "0"; // todo: add comments table, and do a count of them here
            Timestamp = post.Timestamp.ToString();
        }
Exemplo n.º 2
0
        // todo: comments list

        public PostViewModel(Blog.Post post)
        {
            BlogDataDataContext database = new BlogDataDataContext();

            Id    = post.Id.ToString();
            Title = post.Title;
            Body  = post.Body;

            Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author);
            Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName);

            Dictionary <Guid, string>   categoriesTemp = new Dictionary <Guid, string>();
            List <Blog.PostCategoryMap> categoryMaps   = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var categoryMap in categoryMaps)
            {
                Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId);
                categoriesTemp.Add(category.Id, category.Name);
            }
            Categories = categoriesTemp;

            Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>();
            List <Blog.PostTagMap>    tagMaps  = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList();

            foreach (var tagMap in tagMaps)
            {
                Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId);
                tagsTemp.Add(tag.Id, tag.Name);
            }
            Tags = tagsTemp;

            Timestamp       = post.Timestamp.ToString();
            CommentsEnabled = post.CommentsEnabled;
            Status          = post.Status;
            Visibility      = post.Visibility;
            Slug            = post.Slug;
        }