public IHttpActionResult FindNewsItem(int id)
        {
            //Find the data
            NewsItem NewsItem = db.NewsItems.Find(id);

            //if not found, return 404 status code.
            if (NewsItem == null)
            {
                return(NotFound());
            }

            //An easy to access entry into the Hop information, safely through the DTO
            NewsItemDto NewsItemDto = new NewsItemDto
            {
                NewsItemID           = NewsItem.NewsItemID,
                Title                = NewsItem.Title,
                NewsBody             = NewsItem.NewsBody,
                NewItemDate          = NewsItem.NewItemDate,
                NewsItemHasPic       = NewsItem.NewsItemHasPic,
                NewsItemPicExtension = NewsItem.NewsItemPicExtension,
                UserID               = NewsItem.UserID
            };


            //pass along data as 200 status code OK response
            return(Ok(NewsItemDto));
        }
Ejemplo n.º 2
0
        public ActionResult DeleteConfirm(int id)
        {
            string url = "NewsItemData/FindNewsItem/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                //Put data into Hop data transfer object
                NewsItemDto SelectedNewsItem = response.Content.ReadAsAsync <NewsItemDto>().Result;
                return(View(SelectedNewsItem));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Ejemplo n.º 3
0
        //allows the view to find the specific news item to be edited
        public ActionResult Edit(int id)
        {
            UpdateNewsItem ViewModel = new UpdateNewsItem();

            string url = "NewsItemData/FindNewsItem/" + id;
            HttpResponseMessage response = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                //Put data into newsitem data transfer object
                NewsItemDto SelectedNewsItem = response.Content.ReadAsAsync <NewsItemDto>().Result;
                ViewModel.newsItem = SelectedNewsItem;

                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
Ejemplo n.º 4
0
        private NewsItemDto referenceLightItem(NewsItemDto item)
        {
            JObject tmpObj = new JObject();

            // get all news items authors
            List <NewsAuthorRelation> authourRelList =
                _relationService.getAutherNewsRelationByNewsId(item.Id);

            // get all news items categories
            List <NewsCategoryRelation> categoryRelList =
                _relationService.getNewsCateoryRelationByNewsId(item.Id);

            tmpObj.TryAdd("href", "api/" + item.Id);
            item.addReference("self", tmpObj);
            item.addReference("edit", tmpObj);
            item.addReference("delete", tmpObj);

            List <JObject> aObjList = new List <JObject>();

            foreach (NewsAuthorRelation aItem in authourRelList)
            {
                JObject authorObject = new JObject();
                authorObject.TryAdd("href", "api/authors/" + aItem.authorId);
                aObjList.Add(authorObject);
            }

            item.addReference("authors", aObjList);

            List <JObject> cObjList = new List <JObject>();

            foreach (NewsCategoryRelation cItem in categoryRelList)
            {
                JObject catObject = new JObject();
                catObject.TryAdd("href", "api/categories/" + cItem.categoryId);
                cObjList.Add(catObject);
            }

            item.addReference("categories", cObjList);

            return(item);
        }
Ejemplo n.º 5
0
        public void AddReferenceLinks(NewsItemDto newsItem)
        {
            //Constructing an object to hold the reference to self
            ExpandoObject newLink = new ExpandoObject();

            //Setting references for self, edit and href
            newLink.AddReference("href", $"api/{newsItem.Id}");
            newsItem.Links.AddReference("self", newLink);
            newsItem.Links.AddReference("edit", newLink);
            newsItem.Links.AddReference("delete", newLink);
            //Constructing an object to hold the reference to the author of the newsItem
            ExpandoObject authorLink = new ExpandoObject();

            authorLink.AddReference("href", $"api/categories/{newsItem.AuthorId}");
            newsItem.Links.AddReference("author", authorLink);
            //Constructing an object to hold the reference to the category of the newsItem
            ExpandoObject categoryLink = new ExpandoObject();

            categoryLink.AddReference("href", $"api/categories/{newsItem.CategoryId}");
            newsItem.Links.AddReference("category", categoryLink);
        }
Ejemplo n.º 6
0
        //Gets the specified details of an individual news item
        public ActionResult Details(int id)
        {
            //instantiates the ShowNEwsITem viewmodle
            ShowNewsItem        ViewModel = new ShowNewsItem();
            string              url       = "NewsItemData/FindNewsItem/" + id;
            HttpResponseMessage response  = client.GetAsync(url).Result;

            if (response.IsSuccessStatusCode)
            {
                //Finds the info for one specific news item through the dto
                NewsItemDto SelectedNewsItem = response.Content.ReadAsAsync <NewsItemDto>().Result;
                ViewModel.newsItem = SelectedNewsItem;



                return(View(ViewModel));
            }
            else
            {
                return(RedirectToAction("Error"));
            }
        }
        public IHttpActionResult GetNewsItems()
        {
            List <NewsItem>    NewsItems    = db.NewsItems.ToList();
            List <NewsItemDto> NewsItemDtos = new List <NewsItemDto> {
            };

            foreach (var NewsItem in NewsItems)
            {
                NewsItemDto NewNewsItem = new NewsItemDto
                {
                    NewsItemID           = NewsItem.NewsItemID,
                    Title                = NewsItem.Title,
                    NewsBody             = NewsItem.NewsBody,
                    NewItemDate          = NewsItem.NewItemDate,
                    NewsItemHasPic       = NewsItem.NewsItemHasPic,
                    NewsItemPicExtension = NewsItem.NewsItemPicExtension,
                    UserID               = NewsItem.UserID
                };
                NewsItemDtos.Add(NewNewsItem);
            }

            return(Ok(NewsItemDtos));
        }
Ejemplo n.º 8
0
        public List <NewsItemDto> GetAllNewsByAuthorId(int id)
        {
            var resultList         = new List <NewsItemDto>();
            var listOfNewsItemsIds = DataProvider.NewsItemsAuthors.Where(x => x.AuthorId == id);

            foreach (var auth in listOfNewsItemsIds)
            {
                var entityDto = DataProvider.NewsItems.FirstOrDefault(r => r.Id == auth.NewsItemId);
                if (entityDto != null)
                {
                    var entity = new NewsItemDto()
                    {
                        Id               = entityDto.Id,
                        Title            = entityDto.Title,
                        ImgSource        = entityDto.ImgSource,
                        ShortDescription = entityDto.ShortDescription
                    };
                    resultList.Add(entity);
                }
            }
            ;
            return(resultList);
        }
 /// <summary>
 /// Adds correct HATEOAS link references to News Item hypermedia model
 /// </summary>
 /// <param name="HyperMediaModel">Hypermedia model of type News Item to add references to</param>
 /// <param name="Id">Id of author news item to add reference to</param>
 public static void AddReferences(this NewsItemDto item, int Id, IEnumerable <NewsItemCategoryRelation> categoryRelations, IEnumerable <AuthorNewsItemRelation> authorRelations)
 {
     item.AddNewsItemReferences(Id, categoryRelations, authorRelations);
 }