Example #1
0
        public Post UpdatePost(Post post)
        {
            var postToEdit = _context.Posts
                .Include(x => x.Tags)
                .Include(x => x.Comments)
                .Single(x => x.Id == post.Id);

            postToEdit.Tags = post.Tags;
            postToEdit.Comments = post.Comments;
            postToEdit.Body = post.Body;
            postToEdit.Title = post.Title;
            postToEdit.UrlTitle = post.UrlTitle;
            postToEdit.PhotoPath = post.PhotoPath;
            postToEdit.Preview = post.Preview;
            postToEdit.DateEdited = DateTime.UtcNow;

            _context.Entry(postToEdit).State = EntityState.Modified;
            _context.SaveChanges();

            return postToEdit;
        }
Example #2
0
        public bool SeedPostTagComments()
        {
            if (!_context.Posts.Any())
            {
                int numberOfPosts = 17;

                var bodyTextFirstSample =
                    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae scelerisque tortor. Fusce ac augue in nulla lobortis auctor fringilla id urna. Aenean eleifend metus mi, non fringilla libero tempus ac. Curabitur vitae posuere ligula, ac faucibus ex. Cras placerat est lectus, condimentum dictum est volutpat quis. Proin bibendum vel tortor sit amet lobortis. Curabitur bibendum porttitor erat vel molestie. Morbi auctor cursus nisl et posuere. Donec ac placerat mauris, quis rutrum turpis";

                var bodyTextSecondSample =
                    "Aenean sed fringilla lectus, vitae placerat mi. Proin non ante interdum, congue metus dignissim, gravida enim. Praesent pulvinar vehicula sodales. In congue hendrerit vestibulum. Sed vitae interdum quam. Maecenas nec quam urna. Nulla sollicitudin, nisi a vulputate luctus, leo neque luctus turpis, quis ultrices mauris dui sit amet diam. Nunc imperdiet quam id lectus convallis, eget condimentum lorem consectetur. Sed dignissim bibendum ultrices. Proin in sem ac dolor vestibulum sodales a nec lacus. Praesent lectus quam, interdum a condimentum accumsan, congue in ante. Phasellus at mi euismod, mollis dui in, ornare nisl.";

                var postList = new List<Post>();

                var angularJsTag = new Tag {TimesUsed = 3, Name = "AngularJS"};
                var javaScriptTag = new Tag {TimesUsed = 6, Name = "JavaScript"};
                var cSharpTag = new Tag {TimesUsed = 2, Name = "C#"};
                var fundamentalsTag = new Tag {TimesUsed = 3, Name = "Fundamentals"};
                var dotNetTag = new Tag {TimesUsed = 6, Name = ".NET"};

                _context.Tags.Add(angularJsTag);
                _context.Tags.Add(javaScriptTag);
                _context.Tags.Add(cSharpTag);

                var random = new Random();

                for (int i = 0; i < numberOfPosts; i++)
                {
                    var post = new Post
                    {
                        Preview =
                            i%2 == 0 ? bodyTextFirstSample.Substring(50, 400) : bodyTextSecondSample.Substring(50, 400),
                        Body =
                            i%2 == 0
                                ? bodyTextFirstSample + "<br><br>" + bodyTextSecondSample
                                : bodyTextSecondSample + "<br><br>" + bodyTextFirstSample,
                        PostedDate = DateTime.UtcNow,
                        Title = i%2 == 0 ? "AngularJS Routing" : "JavaScript Fundamentals",
                        UrlTitle = i%2 == 0 ? "AngularJS-Routing" : "JavaScript-Fundamentals",
                        Views = random.Next(100),
                        PhotoPath = @"C:\dev\PhotoPath",
                        Inactive = false,
                        Comments = BuildCommentList(random.Next(7))
                    };

                    postList.Add(post);
                }

                _context.Posts.AddRange(postList);
                _context.SaveChanges();
                return true;
            }
            return false;
        }
Example #3
0
 public Post UpdatePost(Post updatedPost)
 {
     return _postDataAccess.UpdatePost(updatedPost);
 }
Example #4
0
 public Post SaveNewPost(Post post)
 {
     _context.Add(post);
     _context.SaveChanges();
     return post;
 }
Example #5
0
 public Post SaveNewPost(Post post)
 {
     return _postDataAccess
         .SaveNewPost(post);
 }