Beispiel #1
0
        public HttpResponseMessage GetAll(string parentId)
        {
            int    start         = 0;
            int    limit         = 12;
            string startPosition = Request.GetQueryNameValuePairs()
                                   .SingleOrDefault(x => x.Key == "start")
                                   .Value;

            Int32.TryParse(startPosition, out start);

            try
            {
                PortfolioListModel model = new PortfolioListModel();
                IPublishedContent  page  = GetPage(parentId);
                if (page.Children().Any())
                {
                    IEnumerable <IPublishedContent> items = page.Children()
                                                            .Where(x => x.DocumentTypeAlias.Equals("Site"))
                                                            .Skip(start)
                                                            .Take(limit);

                    foreach (IPublishedContent portfolio in items)
                    {
                        // Prepare data
                        IEnumerable <string> images = portfolio.GetImagesAsList("image", 400, 300);
                        string thumbnail            = images.Any() ? images.ElementAt(0) : "";
                        Uri    alias = new Uri(portfolio.UrlAbsolute());

                        // Add current item to the model
                        model.Items.Add(new PortfolioModel
                        {
                            Name       = portfolio.Name,
                            Heading    = portfolio.GetString("heading"),
                            Responsive = portfolio.GetPropertyValue <bool>("responsive"),
                            Thumbnail  = thumbnail,
                            SiteUrl    = portfolio.GetString("url"),
                            Slogan     = portfolio.GetString("slogan"),
                            Url        = alias.Segments.Last().TrimEnd('/')
                        });

                        // Mark the last page
                        if (portfolio.IsLast())
                        {
                            model.IsLast = true;
                        }
                    }
                }

                return(Json(model));
            }
            catch
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest));
            }
        }
Beispiel #2
0
        public List <PortfolioListModel> GetPortfolio()
        {
            List <PortfolioListModel> Models = new List <PortfolioListModel>();

            base.Connect();
            DataTable dt = base.Select("SELECT [P_Id],[Subject],[LogoPicId],[Deleted],B.PicAddress FROM [tbl_Portfolio] as A inner join [tbl_PicUploader] as B on A.LogoPicId=B.PicId");

            base.DC();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                var model = new PortfolioListModel()
                {
                    P_Id     = Convert.ToInt32(dt.Rows[i]["P_Id"]),
                    Deleted  = Convert.ToInt32(dt.Rows[i]["Deleted"]),
                    Subject  = dt.Rows[i]["Subject"].ToString(),
                    LogoPath = dt.Rows[i]["PicAddress"].ToString()
                };
                Models.Add(model);
            }

            return(Models);
        }