public void UpdatePost_TitleIsUpdated_UpdateSlug() { IFileSystem testFileSystem = new FakeFileSystem(); BlogDataStore testDataStore = new BlogDataStore(new FakeFileSystem()); SlugGenerator slugGenerator = new SlugGenerator(testDataStore); ExcerptGenerator excerptGenerator = new ExcerptGenerator(); Post post = new Post() { Slug = "Title", IsPublic = true, PubDate = DateTimeOffset.Now, }; testDataStore.SavePost(post); EditedPostModel editedPost = new EditedPostModel() { Title = "Edited Title", }; EditModel model = new EditModel(testDataStore, slugGenerator, excerptGenerator); model.OnPostPublish(post.Id, true); testDataStore.UpdatePost(post, post.IsPublic); Assert.True(testFileSystem.FileExists($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml")); Post result = testDataStore.CollectPostInfo($"BlogFiles\\Posts\\{post.PubDate.ToFileTime()}_{post.Id}.xml"); Assert.Equal("Edited-Title", post.Slug); }
public void OnGet([FromRoute] int id) { Post post = _dataStore.GetPost(id); EditedPost = new EditedPostModel { Title = post.Title, Body = post.Body, Excerpt = post.Excerpt, }; if (post == null) { RedirectToPage("/Index"); } }
public void OnGet([FromRoute] string id) { Post post = _dataStore.GetPost(id); if (post == null) { RedirectToPage("/Index"); } EditedPost = new EditedPostModel { Title = post.Title, Body = post.Body, Excerpt = post.Excerpt, }; hasSlug = !string.IsNullOrEmpty(post.Slug); ViewData["id"] = post.Id; }
public IActionResult OnPostSaveDraft(EditedPostModel editedPost) { if (ModelState.IsValid) { var post = _db.Posts.Find(editedPost.PostId); { post.Title = editedPost.Title; post.Excerpt = editedPost.Excerpt; post.Body = editedPost.Body; // Image = newPost.ImagePath, post.IsPublic = false; //nuk publikohet,editohet dhe =>tek drafts. post.CategoryId = editedPost.CategoryId; }; _db.Set <Post>(); _db.Posts.Update(post); //per te ruajtur ne db te dhenat _db.SaveChanges(); return(RedirectToPage("Drafts")); } return(Page()); //nqs kushti nuk plotesohet. }
public IActionResult OnPostPublish([FromForm] EditedPostModel editedPost) { if (ModelState.IsValid) { var post = _db.Posts.Find(editedPost.PostId); //gjen postin me id qe duam te modifikojme. post.Title = editedPost.Title; //cojme vlerat e reja ne databaze post.Excerpt = editedPost.Excerpt; post.Body = editedPost.Body; // post.Image = editedPost.ImagePath, post.IsPublic = true; post.CategoryId = editedPost.CategoryId; _db.Set <Post>(); _db.Posts.Update(post); //per te ruajtur ne db te dhenat _db.SaveChanges(); return(RedirectToPage("/Index")); } return(Page()); }