/// <summary>
        /// Get all of the landings
        /// </summary>
        /// <param name="dbContext">DB Context to work with</param>
        /// <param name="log">Logging object to log operations</param>
        /// <returns>Collection of landings from the database</returns>
        public async Task <ICollection <BusinessModels.Landing> > GetAll()
        {
            var dbModels = await(from landing in DbContext.Landings
                                 orderby landing.Order
                                 select landing).ToListAsync();

            var ret = new List <BusinessModels.Landing>(dbModels.Count);

            foreach (var landing in dbModels)
            {
                var newLanding = new BusinessModels.Landing()
                {
                    LandingOrigin = landing,
                    Id            = landing.Id,
                    Href          = landing.Href,
                    Title         = landing.Title,
                    Subtitle      = landing.Subtitle,
                    Icon          = landing.Icon,
                    Order         = landing.Order,
                };
                newLanding.Pages = await PagesService.GetFromLanding(newLanding);

                ret.Add(newLanding);
            }

            return(ret);
        }
Example #2
0
        /// <summary>
        /// Get the pages for a particular landing
        /// </summary>
        /// <param name="landing">Landing to get the pages for (can include just Id, but must included that)</param>
        /// <returns>Collection of pages for the specified landing</returns>
        public async Task <ICollection <BusinessModels.Page> > GetFromLanding(BusinessModels.Landing landing)
        {
            ICollection <DbModels.Page> pages;

            if (landing.LandingOrigin != null)
            {
                pages = (from page in landing.LandingOrigin.Pages
                         orderby page.Order
                         select page).ToList();
            }
            else
            {
                pages = await(from page in DbContext.Pages
                              where page.LandingId == landing.Id
                              orderby page.Order
                              select page).ToListAsync();
            }
            var ret = new List <BusinessModels.Page>(pages.Count);

            foreach (var page in pages)
            {
                ret.Add(await ParsePage(page));
            }
            return(ret);
        }
        /// <summary>
        /// Get a specific landing by its ID
        /// </summary>
        /// <param name="dbContext">DB Context to get landing from</param>
        /// <param name="id">ID of the landing to search for</param>
        /// <param name="log">Logging object to log information</param>
        /// <returns>Business object representing the landing</returns>
        /// <exception cref="IndexOutOfRangeException">Invalid GUID string</exception>
        /// <exception cref="KeyNotFoundException">ID Passed was not discovered in database</exception>
        public async Task <BusinessModels.Landing> GetById(Guid id)
        {
            var landing = await DbContext.Landings.FirstOrDefaultAsync(l => id.Equals(l.Id));

            if (landing == null)
            {
                Logger.LogError("Invalid ID Passed, not found");
                throw new KeyNotFoundException();
            }

            var retLanding = new BusinessModels.Landing()
            {
                LandingOrigin = landing,
                Id            = landing.Id,
                Href          = landing.Href,
                Title         = landing.Title,
                Subtitle      = landing.Subtitle
            };

            retLanding.Pages = await PagesService.GetFromLanding(retLanding);

            return(retLanding);
        }