Exemplo n.º 1
0
        public void AddOrUpdateAction(MainResource action)
        {
            var entity = _mainResourceRepository.GetByID(action.Id);

            if (entity != null)
            {
                _mainResourceRepository.Detach(entity);
                _mainResourceRepository.Update(action);
            }
            else
            {
                _mainResourceRepository.Insert(action);
            }

            _mainResourceRepository.Save();
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Resource(string id, string ResourceName, int?page)
        {
            int pageSize   = 4;
            int pageNumber = (page ?? 1);

            if (currencResource.ResourceName == ResourceName)
            {
                ViewBag.URL            = currencResource.URL;
                ViewBag.RSSName        = ResourceName;
                ViewBag.CollectionName = id;

                return(View(RSSFeedData.ToPagedList(pageNumber, pageSize)));
            }

            // find collection by name (made for user-friendly url despite the speed)
            currentCollection = await repository.FindCollectionByNameAsync(ViewBag.CollectionName);

            // find resource
            currencResource = await repository.FindResourceByNameAsync(ResourceName);

            WebClient wclient = new WebClient();

            string RSSData = wclient.DownloadString(currencResource.URL);

            XDocument xml = XDocument.Parse(RSSData);

            RSSFeedData = (from x in xml.Descendants("item")
                           let bytesTitle = Encoding.Default.GetBytes(((string)x.Element("title")))
                                            let bytesDesc = Encoding.Default.GetBytes(((string)x.Element("description")))

                                                            select new RSSFeed
            {
                Title = Encoding.UTF8.GetString(bytesTitle),
                Link = ((string)x.Element("link")),
                Description = Encoding.UTF8.GetString(bytesDesc),
                PubDate = ((string)x.Element("pubDate"))
            });

            ViewBag.URL            = currencResource.URL;
            ViewBag.RSSName        = ResourceName;
            ViewBag.CollectionName = ViewBag.CollectionName;

            return(View(RSSFeedData.ToPagedList(pageNumber, pageSize)));
        }
Exemplo n.º 3
0
 public void Post([FromBody] MainResource value)
 {
     _mainResourceService.AddOrUpdateAction(value);
 }
Exemplo n.º 4
0
 public ActionResult AddResource(MainResource mainResource)
 {
     repository.SaveResource(mainResource);
     repository.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 5
0
 public ActionResult AddResource(MainResource mainResource)
 {
     db.MainResources.Add(mainResource);
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }