private void UpdateItems(Producer producer) { var shows = _rssReader.ReadOne(producer.FeedUrl); var allLinks = shows.Items.Select(x => x.Link).ToArray(); var existingLinks = _db.Shows.AsQueryable() .Where(x => allLinks.Contains(x.Link)) .Select(x => x.Link) .Distinct() .ToArray(); LoggerService.Info("Received to be updated: " + allLinks); shows.Items .Where(x => !existingLinks.Contains(x.Link)) .ToList() .ForEach(x => { var show = new Show { Title = x.Title, Description = x.Description, Mp3 = x.Mp3, PublicationDate = x.PublicationDate, Link = x.Link, ProducerName = producer.Name, ProducerUrl = producer.Url }; if (x.PublicationDate > DateTime.Now.AddYears(-10)) _db.Shows.Save(show); }); }
public ActionResult Create(Producer producer) { if (!ModelState.IsValid) return View(producer); _db.Producers.Save(producer); return RedirectToAction("Index"); }
public void Update(Producer producer) { try { UpdateItems(producer); } catch (Exception exp) { LoggerService.Exception(exp); } }
public ActionResult Edit(string id, Producer model) { if (!ModelState.IsValid) return View(model); var producer = _db.Producers.AsQueryable().FirstOrDefault(x => x.Id == id); if (producer == null) { LoggerService.Exception( new ApplicationException( string.Format( "No producer found to update for id:{0} \n with the following data to post: \n {1}", id, model.ToJson()) )); return RedirectToAction("Index"); } _db.Producers.Save(model); return RedirectToAction("Index"); }