コード例 #1
0
        public ActionResult Add(PostTagsAddViewModel viewModel)
        {
            ValidatePostTags(viewModel);

            if (ModelState.IsValid)
            {
                var postTags = new PostTags()
                {
                    PostId = viewModel.PostId,
                    TagId  = viewModel.TagId,
                };

                _postTagsRepository.Add(postTags);

                TempData["Message"] = "Your tag was successfully added!";

                return(RedirectToAction("Edit", "Post", new { id = viewModel.PostId }));
            }


            viewModel.Post = _postRepository.Get(viewModel.PostId);
            viewModel.Init(_tagRepository);

            return(View(viewModel));
        }
コード例 #2
0
        public async Task <IHttpActionResult> PutPostTags(int id, PostTags postTags)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != postTags.PostTagsID)
            {
                return(BadRequest());
            }

            db.Entry(postTags).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostTagsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #3
0
        public async Task <IActionResult> PutPostTags(int id, PostTags postTags)
        {
            if (id != postTags.tagId)
            {
                return(BadRequest());
            }

            _context.Entry(postTags).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PostTagsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        public PostDTO CreatePost(CreatePostDTO postDTO)
        {
            var post = postDTO.ToPost();

            if (EnumerableExtensions.Any(postDTO.Tags))
            {
                foreach (var tagId in postDTO.Tags)
                {
                    var postTags = new PostTags()
                    {
                        Post = post, TagId = tagId
                    };
                    post.PostTags.Add(postTags);
                }
            }

            if (postDTO.PostId != 0)
            {
                ++post.PostNum;
                _database.Posts.Add(post);
            }
            else
            {
                _database.Posts.Add(post);
                _database.Save();
                post.PostId = post.Id;
                _database.Posts.Update(post);
            }

            _database.Save();
            return(post.ToPostDTO());
        }
コード例 #5
0
        public Dictionary <int, List <PostTags> > GetPostTagsByIds(int[] ids)
        {
            List <PostTags> tags = new List <PostTags>();

            dataProvider.ExecuteCmd(
                "PostTags_GetByPostIds",
                inputParamMapper: parameters =>
            {
                parameters.AddWithValue("@IdsJSON", JsonConvert.SerializeObject(ids));
            },
                singleRecordMapper: (reader, resultSetNumber) =>
            {
                PostTags tag = new PostTags();

                tag.Id         = (int)reader["Id"];
                tag.PostId     = (int)reader["PostId"];
                tag.TaggerId   = (int)reader["TaggerId"];
                tag.TaggedId   = (int)reader["TaggedId"];
                tag.PostItemId = (int)reader["PostItemId"];

                tags.Add(tag);
            });

            var tagsDict = tags
                           .ToLookup(postTag => postTag.PostId)
                           .ToDictionary(
                o => o.Key,
                o => o.ToList()
                );

            return(tagsDict);
        }
コード例 #6
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            PostTags postTags = await db.PostTags.FindAsync(id);

            db.PostTags.Remove(postTags);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "PostTagId,BlogId,PostId,Tag")] PostTags postTag)
 {
     if (ModelState.IsValid)
     {
         _unitOfWork._postTagRepository.Update(postTag);
         _unitOfWork.Save();
         return(RedirectToAction("Index"));
     }
     return(View(postTag));
 }
コード例 #8
0
        public ActionResult AddTag(PostAddViewModel viewModel)
        {
            var post = viewModel.Post;
            var tag  = new PostTags {
                PostId = post.Id, TagId = viewModel.TagId
            };

            _postTagsRepository.Add(tag);

            return(RedirectToAction("Edit", new { id = post.Id }));
        }
コード例 #9
0
        public async Task <IHttpActionResult> PostPostTags(PostTags postTags)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.PostTags.Add(postTags);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = postTags.PostTagsID }, postTags));
        }
コード例 #10
0
        public async Task <ActionResult> Edit([Bind(Include = "PostTagsID,TagID,PostID")] PostTags postTags)
        {
            if (ModelState.IsValid)
            {
                db.Entry(postTags).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewBag.PostID = new SelectList(db.Posts, "PostID", "Title", postTags.PostID);
            ViewBag.TagID  = new SelectList(db.Tags, "TagID", "content", postTags.TagID);
            return(View(postTags));
        }
コード例 #11
0
        // GET: PostTags/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PostTags postTag = _unitOfWork._postTagRepository.Get(Convert.ToInt32(id));

            if (postTag == null)
            {
                return(HttpNotFound());
            }
            return(View(postTag));
        }
コード例 #12
0
        // GET: PostTags/Details/5
        public async Task <ActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PostTags postTags = await db.PostTags.FindAsync(id);

            if (postTags == null)
            {
                return(HttpNotFound());
            }
            return(View(postTags));
        }
コード例 #13
0
        public void Seed()
        {
            if (!Posts.Any())
            {
                Posts.AddRange(new List <Post> {
                    new Post {
                        Title = "Async", Description = "OData"
                    },
                    new Post {
                        Title = "Test", Description = "OData"
                    },
                    new Post {
                        Title = "Sample", Description = "OData"
                    }
                });
                SaveChanges();
            }

            if (!Tags.Any())
            {
                Tags.AddRange(new List <Tag> {
                    new Tag {
                        Title = "asp-core2.2"
                    },
                    new Tag {
                        Title = "odata4.0"
                    },
                    new Tag {
                        Title = "c#"
                    }
                });
                SaveChanges();
            }

            if (!PostTags.Any())
            {
                PostTags.AddRange(new List <PostTag> {
                    new PostTag {
                        PostId = 1, TagId = 1
                    },
                    new PostTag {
                        PostId = 1, TagId = 2
                    },
                    new PostTag {
                        PostId = 1, TagId = 3
                    }
                });
                SaveChanges();
            }
        }
コード例 #14
0
        public async Task <IHttpActionResult> DeletePostTags(int id)
        {
            PostTags postTags = await db.PostTags.FindAsync(id);

            if (postTags == null)
            {
                return(NotFound());
            }

            db.PostTags.Remove(postTags);
            await db.SaveChangesAsync();

            return(Ok(postTags));
        }
コード例 #15
0
        // GET: PostTags/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PostTags postTags = await db.PostTags.FindAsync(id);

            if (postTags == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PostID = new SelectList(db.Posts, "PostID", "Title", postTags.PostID);
            ViewBag.TagID  = new SelectList(db.Tags, "TagID", "content", postTags.TagID);
            return(View(postTags));
        }
コード例 #16
0
ファイル: News.cs プロジェクト: DmitryXann/RssAgregator
 public NewsModel GetModel()
 {
     return(new NewsModel
     {
         Id = Id,
         AuthorName = AuthorName,
         AuthorId = AuthorId,
         AuthorLink = AuthorLink,
         PostLikes = PostLikes,
         PostName = PostName,
         PostLink = PostLink,
         PostContent = PostContent,
         PostTags = PostTags.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries),
         External = External,
         AdultContent = AdultContent,
         DataSource = DataSource.Type.ToString()
     });
 }
コード例 #17
0
        /// <summary>
        /// Returns a streaming sequence of T deserialized from a stackoverflow
        /// data dump xml document.
        /// </summary>
        /// <typeparam name="T">The type of domain object to stream</typeparam>
        /// <param name="path">A stackoverflow data dump directory</param>
        /// <param name="site"></param>
        /// <returns></returns>
        public static IEnumerable <T> FromXmlDocument(string path, string site)
        {
            Regex rx = new Regex(@"\<([^>]+)\>", RegexOptions.Compiled);

            string filename = GetTableName(typeof(T));
            string filePath = Path.Combine(path, filename);

            using (XmlReader rdr = XmlReader.Create(filePath))
            {
                rdr.MoveToContent();
                while (rdr.Read())
                {
                    if ((rdr.NodeType == XmlNodeType.Element) && (rdr.Name == "row"))
                    {
                        XElement node = (XElement)XNode.ReadFrom(rdr);
                        if (typeof(T) == typeof(PostTags))
                        {
                            XAttribute tagsAtt = node.Attributes("Tags").FirstOrDefault();
                            if (tagsAtt != null)
                            {
                                // ReSharper disable PossibleNullReferenceException
                                int postId = Convert.ToInt32(node.Attribute("Id").Value);
                                // ReSharper restore PossibleNullReferenceException
                                IEnumerable <string> distinctTags =
                                    rx.Matches(tagsAtt.Value).Cast <Match>().Select(m => m.Groups[1].Value).Distinct();
                                foreach (string tag in distinctTags)
                                {
                                    T newPostTags = new PostTags {
                                        Tag = tag, PostId = postId
                                    } as T;
                                    yield return(newPostTags);
                                }
                            }
                        }
                        else
                        {
                            yield return(FromXElement(node));
                        }
                    }
                }
                rdr.Close();
            }
        }
コード例 #18
0
        public ActionResult <BlogPostView> AddBlogPost([FromBody] InsertBlogView ibv)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            BlogPost blogPost = new BlogPost();

            blogPost.Title       = ibv.Title;
            blogPost.Description = ibv.Description;
            blogPost.Body        = ibv.Body;

            foreach (string tag in ibv.TagList)
            {
                // If for some reason an non-existant an unknown tag is passed
                try
                {
                    PostTags pt = new PostTags {
                        BlogPostID = blogPost.BlogPostID, TagID = db.Tags.SingleOrDefault(t => t.TagName == tag).TagID
                    };
                    if (pt != null)
                    {
                        blogPost.PostTags.Add(pt);
                    }
                }
                catch {
                    continue;
                }
            }

            blogPost.CreatedAt      = DateTime.Now;
            blogPost.UpdatedAt      = blogPost.CreatedAt;
            blogPost.Favorited      = false;
            blogPost.FavoritesCount = 0;
            blogPost.Slug           = SlugGenerator(blogPost.Title);

            db.BlogPosts.Add(blogPost);
            db.SaveChanges();

            return(bpConverter.ToBlogPostView(blogPost));
        }
コード例 #19
0
        public async Task <ActionResult <PostTags> > PostPostTags(PostTags postTags)
        {
            _context.PostTags.Add(postTags);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PostTagsExists(postTags.tagId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPostTags", new { id = postTags.tagId }, postTags));
        }
コード例 #20
0
        public IActionResult Create(Post post)
        {
            var TagString = this.Request.Form["TagString"];

            db.Posts.Add(post);
            var OldTags = db.Tags.ToList();

            db.SaveChanges();
            List <Tag> NewTags = db.TagSaver(TagString);

            foreach (var oldTag in OldTags)
            {
                for (int i = 0; i < NewTags.Count; i++)
                {
                    if (NewTags[i].Name == oldTag.Name)
                    {
                        NewTags[i].TagId = oldTag.TagId;
                    }
                }
            }
            foreach (var tag in NewTags)
            {
                if (tag.TagId == 0)
                {
                    db.Tags.Add(tag);
                    db.SaveChanges();
                }
                var newPostTag = new PostTags()
                {
                    TagId = tag.TagId, PostId = post.PostId
                };
                db.PostTags.Add(newPostTag);
                db.SaveChanges();
            }
            return(RedirectToAction("Index/" + post.LocationId));
        }
コード例 #21
0
        /// <summary>
        /// Wraps the returning posts into Post objects. Uses JSON.net for deserialization
        /// </summary>
        /// <param name="site">the site url. insert without http:// prefix</param>
        /// <param name="type">the type of posts that shall be returned (post or page)</param>
        /// <param name="status">the status of posts that shall be returned</param>
        /// <param name="number">the number of posts that shall be returned</param>
        /// <param name="offset">the 0-indexed offset for the request. Default value goes to 0. Use this parameter for pagination.</param>
        /// <returns>List of all posts that matching the query</returns>
        public async Task <PostsList> GetPostList(string site, PostType type, PostStatus status, int?number = null, int?offset = null)
        {
            PostsList post_list = new PostsList();

            var response = await getPosts(site, type, status, number, offset);

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                post_list = JsonConvert.DeserializeObject <PostsList>(responseString);

                if (post_list.posts_total_count != 0)
                {
                    foreach (var item in post_list.posts_list)
                    {
                        //getting categories as string but handled as object to keep deserializing of posts possible
                        if (item.categories != null)
                        {
                            var cat_object = item.categories;
                            item.categories = PostCategories.GetString(cat_object);
                        }

                        //getting tags as string but handled as object to keep deserializing of posts possible
                        if (item.tags != null)
                        {
                            var tags_object = item.tags;
                            item.tags = PostTags.GetString(tags_object);
                        }

                        //getting attachments as List but handled as object to keep deserializing of posts possible
                        if (item.attachments != null)
                        {
                            var attachments_obj = item.attachments;
                            item.attachments = PostAttachments.GetList(attachments_obj);
                        }

                        //getting metadata as List but handled as object to keep deserializing of posts possible
                        if (item.metadata != null)
                        {
                            var metadata_obj = item.metadata;
                            item.metadata = PostMetaData.GetList(metadata_obj);
                        }
                    }
                }
                else
                {
                    Debug.WriteLine("WARNING: GetPostList returned 0 results. Wrong parameters?");
                }
            }
            else if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                var responseString = await response.Content.ReadAsStringAsync();

                var Error = JsonConvert.DeserializeObject <apiError>(responseString);

                Debug.WriteLine(string.Format("ERROR on GetPostList: The site returned: {0}. JetPack not installed on WordPress or JetPack JSON API not active?", Error.message));
            }

            return(post_list);
        }
コード例 #22
0
 public PostTagsDTO(PostTags t)
 {
     TagName = t.TagName;
 }
コード例 #23
0
ファイル: SqlPostTagsRepo.cs プロジェクト: phungNT/SWDAPI
 public void UpdatePostTags(PostTags post)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new SuetiaeBloggDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <SuetiaeBloggDbContext> >()))
            {
                if (context.Posts.Any())
                {
                    return; // DB has been seeded
                }

                var category1 = new Category {
                    Name = "General"
                };
                var category2 = new Category {
                    Name = "Event"
                };
                var category3 = new Category {
                    Name = "Sverige"
                };
                var category4 = new Category {
                    Name = "Nationaldag"
                };
                var category5 = new Category {
                    Name = "Historia"
                };

                context.Categories.AddRange(category1, category2, category3, category4, category5);

                var tag1 = new Tag {
                    Name = "General"
                };
                var tag2 = new Tag {
                    Name = "Väder"
                };
                var tag3 = new Tag {
                    Name = "Natur"
                };

                context.Tags.AddRange(tag1, tag2, tag3);

                var author1 = new Author {
                    FirstName = "Anna"
                };
                var author2 = new Author {
                    FirstName = "Evelyn"
                };
                var author3 = new Author {
                    FirstName = "Niloufar"
                };



                context.Authors.AddRange(author1, author2, author3);


                var post1 = new Post
                {
                    Author  = author1,
                    Title   = "This is the first post with complete model and author",
                    Summary = "This is what I want to see in the homepage",
                    Body    = "Write something here!",
                };
                var post2 = new Post
                {
                    Author = author2,

                    Title   = "This is the first post with complete model and author",
                    Summary = "This is what I want to see in the homepage",
                    Body    = "Write something here!",
                };

                var postCategory1 = new PostCategories {
                    Post     = post1,
                    Category = category1
                };
                var postTag1 = new PostTags {
                    Post = post1,
                    Tag  = tag1
                };
                var postTag2 = new PostTags {
                    Post = post1,
                    Tag  = tag2
                };

                var post3 = new Post {
                    Author = new Author {
                        FirstName = "AlbertoM"
                    },

                    Title   = "This is the second post with complete model and author",
                    Summary = "This is what I want to see in the homepage",
                    Body    = "Alla Västtrafiks expressbussar till Göteborg ska byta namn och utseende." +
                              "Först ut är Gul, Blå och Rosa express som får nya namn och rutter redan i december. " +
                              "Förändringar som inte tas emot väl av alla." +
                              "– Det känns som ett misslyckande i planeringen" +
                              "säger Anna Andrén som är en av dem som drabbas.!",
                };
                var post4 = new Post
                {
                    Author  = author3,
                    Title   = "This is the third post with complete model and author",
                    Summary = "This is what I want to see in the homepage",
                    Body    = "Flera av stadens anställda varnar för att smittspridningen åter tagit fart inom stadens verksamheter" +
                              ". Även fast antalet smittade fortfarande är lågt jämfört med sommarens siffror, så uppmanar nu Babbs Edberg, " +
                              "stadsdelsdirektör i Majorna-Linné och Centrum, till att ta riskerna på allvar.",
                };

                var comment1 = new Comment
                {
                    Body   = "I would like to write something mre original but anyway this a comment in the first post",
                    Author = author3,
                    Post   = post1
                };
                var comment2 = new Comment
                {
                    Body   = "I think the comment goes with every post.",
                    Author = author1,
                    Post   = post1
                };
                var comment3 = new Comment
                {
                    Body   = "I completely disagree, it is a complotto!",
                    Author = author2,
                    Post   = post3
                };
                var comment4 = new Comment
                {
                    Body   = "ok, loooks nice. Where is the author name for the comment?",
                    Author = author1,
                    Post   = post4
                };


                var postCategory2 = new PostCategories {
                    Post = post1, Category = category2
                };
                var postCategory3 = new PostCategories {
                    Post = post1, Category = category3
                };
                var postCategory4 = new PostCategories {
                    Post = post2, Category = category4
                };
                var postCategory5 = new PostCategories {
                    Post = post2, Category = category5
                };
                var postCategory6 = new PostCategories {
                    Post = post2, Category = category2
                };
                var postCategory7 = new PostCategories {
                    Post = post3, Category = category4
                };
                var postCategory8 = new PostCategories {
                    Post = post3, Category = category2
                };
                var postCategory9 = new PostCategories {
                    Post = post3, Category = category3
                };
                var postCategory10 = new PostCategories {
                    Post = post4, Category = category1
                };

                var postTag3 = new PostTags {
                    Post = post2, Tag = tag2
                };
                var postTag4 = new PostTags {
                    Post = post3, Tag = tag3
                };
                var postTag5 = new PostTags {
                    Post = post3, Tag = tag2
                };

                //context.Comments.AddRange(comment1, comment2, comment3, comment4);

                context.PostCategories.AddRange(postCategory1, postCategory2, postCategory3);
                context.PostCategories.AddRange(postCategory4, postCategory5, postCategory6);
                context.PostCategories.AddRange(postCategory7, postCategory8, postCategory9, postCategory10);
                context.PostTags.AddRange(postTag1, postTag2, postTag3, postTag4, postTag5);
                context.AddRange(post1, post2, post3, post4);

                context.SaveChanges();
            }
        }
コード例 #25
0
        public List <Tag> GetTags()
        {
            var tags = PostTags.Select(x => x.Tag).Distinct().ToList();

            return(tags);
        }