async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { BlogPosts.Clear(); var items = await BlogStore.GetItemsAsync(); foreach (var item in items) { BlogPosts.Add(item); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void Add_WhenCalled_ReturnsOKResult() { //Given //Arrange var mockService = new Mock <IPostService>(); Post data = new Post { Title = "Titulo", Body = "contenido del post", Autor = "el equipo" }; Post expected = new Post { Id = 1, Title = "Titulo", Body = "contenido del post", Autor = "el equipo" }; mockService.Setup(serv => serv.Add(data)).Returns(expected); BlogPosts post = new BlogPosts(mockService.Object); // When // Act var result = post.Add(data); // Then // Assert Assert.IsType <OkObjectResult>(result); }
public void AddBlog(BlogPost toAdd) { toAdd.BlogWriter = Users.Single(u => u.Id == toAdd.BlogWriter.Id); BlogPosts.Add(toAdd); SaveChanges(); }
public Guid Create(BlogPost blogPost) { blogPost.UniqueId = Guid.NewGuid(); blogPost.CreateDate = blogPost.ModifiedDate = DateTime.Now.ToJavaScriptMilliseconds(); BlogPosts.Add(blogPost); return(blogPost.UniqueId); }
public void UpdateBlog(BlogPost toUpdate) { var toReplace = GetBlog(toUpdate.BlogPostId); if (toReplace == null) { throw new Exception("Blog ID does not exist"); } BlogPosts.Remove(toReplace); BlogPosts.Add(toUpdate); }
public async Task OnItemSelectedAsync(SiteModel model) { if (model != null) { BlogPosts.Clear(); ButtonText = "Update Site"; Url = model.Url; Name = model.Name; Id = model.Id; Priority = model.Priority; FeedService service = new FeedService(); var(feedModel, error) = await service.FetchAsync(model.Url); if (feedModel != null) { BlogTitle = feedModel.Title; BlogPosts.Clear(); foreach (FeedItemModel item in feedModel.Items) { BlogPosts.Add(item); } } else { var psi = new ProcessStartInfo { FileName = model.Url, UseShellExecute = true }; Process.Start(psi); NotificationBackground = Brushes.Red; NotificationText = error; ShowNotification = Visibility.Visible; await Task.Factory.StartNew( async() => { await Task.Delay(2000); NotificationBackground = Brushes.Green; NotificationText = string.Empty; ShowNotification = Visibility.Collapsed; } ); } } }
public void AddBlog(BlogPost toAdd) { var checkForExistingPost = GetBlog(toAdd.BlogPostId); if (checkForExistingPost != null) { throw new Exception("Blog Id already exists"); } else { toAdd.BlogPostId = BlogPosts.Max(m => m.BlogPostId) + 1; BlogPosts.Add(toAdd); } }
public ActionResult Create(BlogPostViewModel data) { try { if (ModelState.IsValid) { BlogPosts blogPosts = new BlogPosts(); BlogPost post = blogPosts.Add(data); if (post.PostSerial > 0) { return(RedirectToAction("Edit", new { id = post.PostSerial.ToString() })); } else { return(View()); } } return(View()); } catch { return(View()); } }
public void Seed() { if (BlogPosts.Any()) { return; } Authors.Add(new Author { AppUserName = "******", Email = "*****@*****.**", DisplayName = "Administrator", Avatar = "data/admin/avatar.png", Bio = "<p>Something about <b>administrator</b>, maybe HTML or markdown formatted text goes here.</p><p>Should be customizable and editable from user profile.</p>", IsAdmin = true, Created = DateTime.UtcNow.AddDays(-120) }); Authors.Add(new Author { AppUserName = "******", Email = "*****@*****.**", DisplayName = "Demo user", Bio = "Short description about this user and blog.", Created = DateTime.UtcNow.AddDays(-110) }); SaveChanges(); var adminId = Authors.Single(a => a.AppUserName == "admin").Id; var demoId = Authors.Single(a => a.AppUserName == "demo").Id; BlogPosts.Add(new BlogPost { Title = "Welcome to Blogifier!", Slug = "welcome-to-blogifier!", Description = SeedData.FeaturedDesc, Content = SeedData.PostWhatIs, Categories = "welcome,blog", AuthorId = adminId, Cover = "data/admin/cover-blog.png", PostViews = 5, Rating = 4.5, IsFeatured = true, Published = DateTime.UtcNow.AddDays(-100) }); BlogPosts.Add(new BlogPost { Title = "Blogifier Features", Slug = "blogifier-features", Description = "List of the main features supported by Blogifier, includes user management, content management, plugin system, markdown editor, simple search and others. This is not the full list and work in progress.", Content = SeedData.PostFeatures, Categories = "blog", AuthorId = adminId, Cover = "data/admin/cover-globe.png", PostViews = 15, Rating = 4.0, Published = DateTime.UtcNow.AddDays(-55) }); BlogPosts.Add(new BlogPost { Title = "Demo post", Slug = "demo-post", Description = "This demo site is a sandbox to test Blogifier features. It runs in-memory and does not save any data, so you can try everything without making any mess. Have fun!", Content = SeedData.PostDemo, AuthorId = demoId, Cover = "data/demo/demo-cover.jpg", PostViews = 25, Rating = 3.5, Published = DateTime.UtcNow.AddDays(-10) }); SaveChanges(); }