public bool Delete(Resource resource) { if (resource == null) { throw new ArgumentNullException("resource is null"); } _unitOfWork.ResourceRepository.Delete(resource); _unitOfWork.Save(); return true; }
public ActionResult Create(Resource resource) { try { resource.LastUpdateDate = DateTime.Now; _resourceService.New(resource); return RedirectToAction("Index"); } catch (Exception ex) { return View(); } }
public void GetFeedList(Resource resource) { if (resource == null) { throw new ArgumentNullException(); } WebClient wClient = new WebClient(); wClient.Encoding = Encoding.UTF8; var htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(wClient.DownloadString(resource.Url)); var feeds = new List<Feed>(); HtmlAgilityPack.HtmlNode root = htmlDoc.DocumentNode; foreach (HtmlAgilityPack.HtmlNode currentFeed in root.SelectNodes((resource.xPathFeed))) { var feed = new Feed(); var body = currentFeed.SelectSingleNode(resource.xPathBody); if (body != null) feed.Body = body.InnerHtml; var author = currentFeed.SelectSingleNode(resource.xPathAuthor); if (author != null) feed.Author = author.InnerHtml; var title = currentFeed.SelectSingleNode(resource.xPathTitle); if (title != null) feed.Title = title.InnerHtml; var date = currentFeed.SelectSingleNode(resource.xPathDate); // if (date != null) // feed.Date = new DateTime(date.GetAttributeValue("data-timestamp", 0)); feed.Date = DateTime.Now; feed.Resources = resource; _unitOfWork.FeedRepository.Insert(feed); feeds.Add(feed); } resource.Feed = feeds; }
public void Update(Resource resource) { if (resource == null) { throw new ArgumentNullException("resource is null"); } GetFeedList(resource); _unitOfWork.ResourceRepository.Update(resource); _unitOfWork.Save(); }