public void AddSite() { SiteModel site = new SiteModel { Id = Id, Url = Url, Name = Name, Priority = Priority }; //Url = string.Empty; using var dbContext = new DailyDevDbContext(); if (Id > 0) { dbContext.Update(site); } else { dbContext.SiteModels.Add(site); } dbContext.SaveChanges(); Id = 0; Url = string.Empty; Name = string.Empty; ButtonText = "Add Site"; SetupSites(); }
private async Task OnRemoveSiteAsync(SiteModel model) { using var dbContext = new DailyDevDbContext(); dbContext.Remove(model); await dbContext.SaveChangesAsync(); Sites.Remove(model); TotalBlogsCount = Sites.Count(); }
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; } ); } } }