Example #1
0
        /// <summary>
        /// Method that picks the 3 newest valid advs and make it a teaser.
        /// </summary>
        /// <returns>List with 3 newest advs as teasers</returns>
        public List <Teaser> newAdvs()
        {
            // Get list with all advertisements and reverse it to get newest adv as first entries.
            List <Advertisement> revAdv = AdvertisementList.advertisementList;

            revAdv.Reverse();

            List <Teaser> returnTeasers = new List <Teaser>();

            // Run while not yet 3 teasers to return found.
            while (returnTeasers.Count < 3)
            {
                for (int i = 0; i < revAdv.Count; i++)
                {
                    Teaser teaser = teaserController.advToTeaser(revAdv[i]);

                    if (teaserController.checkEmptyReturnProps(teaser))
                    {
                        returnTeasers.Add(teaser);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(returnTeasers);
        }
Example #2
0
        /// <summary>
        /// Method that converts an advertisement to a teaser.
        /// </summary>
        /// <param name="adv">The to converted advertisement.</param>
        /// <returns>The converted teaser.</returns>
        public Teaser advToTeaser(Advertisement adv)
        {
            Teaser teaser = new Teaser();

            teaser.title      = adv.title;
            teaser.imageUrl   = adv.media.mediaList[0].url;
            teaser.advertiser = adv.advertiser.advertiser.name;
            return(teaser);
        }
Example #3
0
 /// <summary>
 /// Method that checks if there are no empty properties in a teaser
 /// </summary>
 /// <param name="adv">Advertisement that needs to be checked.</param>
 /// <returns>True if no empty properties.</returns>
 public bool checkEmptyReturnProps(Teaser teaser)
 {
     if (teaser.title == null || teaser.imageUrl == null || teaser.advertiser == null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Example #4
0
 /// <summary>
 /// Convert teaser object to JSON
 /// </summary>
 /// <param name="teaser">Teaser to be converted.</param>
 /// <returns>Converted json teaser string.</returns>
 public string serializeJson(Teaser teaser)
 {
     return(JsonConvert.SerializeObject(teaser));
 }