Пример #1
0
 public void AddWebpage(Models.Webpage page)
 {
     using (var context = new Models.PostContext())
     {
         context.Webpages.Add(page);
         context.SaveChanges();
     }
 }
Пример #2
0
        //public void UpdatePost(Post toUpdate)
        //{
        //    using (var context = new Models.PostContext())
        //    {
        //        var post = context.Posts.FirstOrDefault(x => x.PostID == toUpdate.PostID);
        //        post = toUpdate;
        //        context.SaveChanges();
        //    }
        //}
        public void ApprovePost(List<int> postID)
        {
            using (var context = new Models.PostContext())
            {
                foreach (var p in postID)
                {
                    var post = context.Posts.FirstOrDefault(x => x.PostID == p);

                    post.IsApproved = true;
                    context.SaveChanges();
                }
            }
        }
Пример #3
0
        public void DeletePost(List<int> postID)
        {
            foreach (var ID in postID)
            {
                using (var context = new Models.PostContext())
                {
                    var post = context.Posts.Where(x => x.PostID == ID);

                    foreach (var p in post)
                    {
                        context.Posts.Remove(p);
                    }
                    context.SaveChanges();
                }
            }
        }
Пример #4
0
        public void AddPost(Post newPost)
        {
            using (var context = new Models.PostContext())
            {
                Models.Post post = new Models.Post();

                post.Title = newPost.Title;
                post.IsApproved = newPost.IsApproved;
                post.DatePosted = newPost.DatePosted;
                post.Content = newPost.Content;
                post.CatID = newPost.CatID;
                post.Categories = newPost.Categories.Select(x => new Models.Category() { category = x.category }).ToList();

                context.Posts.Add(post);
                context.SaveChanges();
            }
        }
Пример #5
0
        public List<Post> GetAllPosts()
        {
            var list = new List<Post>();
            using (var context = new Models.PostContext())
            {

                var posts = context.Posts;
                foreach(var post in posts)
                {
                    list.Add(MapPost(post));
                }

                return list;
            }
        }
Пример #6
0
        public Models.Webpage GetWebpageByTitle(string Title)
        {
            var pages = new List<Models.Webpage>();

            using (var context = new Models.PostContext())
            {
                foreach(var page in context.Webpages)
                {
                    pages.Add(page);
                }

                return pages.FirstOrDefault(x => x.Title == Title);
            }
        }