Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Hugh 30 posts 64 karma points
    Jan 30, 2014 @ 15:00
    Hugh
    0

    OrderBy issue

    Hi all

    I am trying to order my list of nodes by createdate in decsending order.  Here is my code that is failing:

     IEnumerable<IPublishedContent> articles;

        if (string.IsNullOrEmpty(suburb))

        {

            articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderBy("createDate desc");

        }

    But this works
     IEnumerable<IPublishedContent> articles;
        if (string.IsNullOrEmpty(suburb))
        {
            articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderBy("createDate");
        }
    Not sure why OrderBy("createDate desc"); is failing.... 
    I am using a Partial View Marco.
    Thanks in advance.
    Hugh

     

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jan 30, 2014 @ 15:04
    Mike Chambers
    0

    .OrderByDescending("createDate") ??

  • Hugh 30 posts 64 karma points
    Jan 30, 2014 @ 15:06
    Hugh
    0

    Nope, tried that too.  

     articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending("createDate desc");

    Fails.............

  • Mike Chambers 636 posts 1253 karma points c-trib
    Jan 30, 2014 @ 15:10
    Mike Chambers
    0

    http://our.umbraco.org/forum/developers/razor/42030-Sort-by-price-razor

     

    articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x

    => x.createDate);

     

    ??

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 30, 2014 @ 15:36
    Fuji Kusaka
    0

    Hi hugh,

    You should be able to apply the LINQ OrderByDescending() syntax for this query.

    OrderByDescending(x=>x.CreateDate)
  • Hugh 30 posts 64 karma points
    Jan 30, 2014 @ 23:51
    Hugh
    0

    Hi Fuji

    No, that still does not work.  Causes a macro error.

    Here is the code (inlcuding your orderby)

    @inherits Umbraco.Web.Macros.PartialViewMacroPage

    @using System.Linq;

    @{

        var articleContainerId = 1067;

        var topCat = Request.QueryString["topCat"];

        var subCat = Request.QueryString["subCat"];

        var suburb = Request.QueryString["sub"];

        var categoryId = CurrentPage.Id.ToString();

        var idToUse = string.Empty;

        int pageSize = 25;

        int page = 1; // The page we are viewing

        if (!int.TryParse(Request.QueryString["page"], out page))

        {

            page = 1;

        }

        if (!string.IsNullOrEmpty(topCat))

        {

            idToUse = topCat;

        }

        if (!string.IsNullOrEmpty(subCat))

        {

            idToUse = subCat;

        }

        if (string.IsNullOrEmpty(idToUse))

        {

            idToUse = categoryId;

        }

       IEnumerable<IPublishedContent> articles;

        if (string.IsNullOrEmpty(suburb))

        {

            articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).OrderByDescending(x=>x.CreateDate);

        }

        else

        {

            if (topCat == "1")

            {

                articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));

            }

            else

            {

                articles = Umbraco.TypedContent(articleContainerId).Children.Where(x => x.GetPropertyValue<string>("cats").Contains(idToUse)).Where(x => x.GetPropertyValue("suburb".ToUpper()).Equals(suburb.ToUpper()));

            }

        }

        int totalNodes = articles.Count();

        int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);

        if (page > totalPages)

        {

            page = totalPages;

        }

        else if (page < 1)

        {

            page = 1;

        }

        foreach (var p in articles.Skip((page - 1) * pageSize).Take(pageSize))

        {

            var advImgStr = p.GetPropertyValue<string>("photos").Split(',');

            var selectedMedia = Umbraco.Media(advImgStr[0]);

            var bId = p.GetPropertyValue("broker");

            var strPrice = p.GetPropertyValue("salePrice");

    var featureClass = "";

    if (p.GetPropertyValue<bool>("isFeatured"))

    {

    featureClass = "background-color:#b7b8b8; padding:5px;";

    }

            <article style="@featureClass">

    @if (p.GetPropertyValue<bool>("isFeatured"))

    {

    <p><strong>FEATURED AD</strong></p>

    }

                <a href="@p.Url" class="single-image picture">

                    <img src="/[email protected]&width=190&height=115&Align=center&Crop=Resize" alt="@p.GetPropertyValue("pageHeading")" title="@p.GetPropertyValue("pageHeading")">

                </a>

                <div class="detailed">

                    <h6 class="title-item">

                        <a href="@p.Url">@p.GetPropertyValue("pageHeading")</a>

                    </h6>

                    @if (p.GetPropertyValue<string>("salePrice") == "0")

                    {

                        <span class="price">TBA</span>

                    }

                    else

                    {

                        <span class="price">[email protected]("salePrice")</span>

                    }

                    <div class="clear"></div>

                    <ul class="list-entry">

                        <li><b class="label">Reference:</b><span>@p.GetPropertyValue("propertyReference")</span></li>

                        <li><b class="label">Location:</b><span>@p.GetPropertyValue("suburb") @p.GetPropertyValue("state") </span></li>

                        <li><b class="label">Broker:</b><span> @Umbraco.RenderMacro("BrokerInfoById", new { BrokerId = bId.ToString() })  </span></li>

                    </ul><!--/ .list-entry-->

                    <a href="@p.Url" class="button orange">Details</a>

                </div><!--/ .detailed-->

            </article>

        }

        <div class="wp-pagenavi clearfix">

            <div style="padding-bottom:10px;"><span class="pages">Page @page of @totalPages</span></div>

            @for (int p = 1; p < totalPages + 1; p++)

            {

                var top1Cat = Request.QueryString["topCat"];

                var subCat1 = Request.QueryString["subCat"];

                var suburb1 = Request.QueryString["sub"];

                string selected = (p == page) ? "selected" : string.Empty;

                if (selected == "selected")

                {

                    <span class="current">@p</span>

                }

                else

                {

                    string strURL = "?page=" + p;

                    strURL = strURL + "&topCat=" + top1Cat;

                    strURL = strURL + "&sub=" + suburb1;

                    strURL = strURL + "&subCat=" + subCat1;

                    <a class="page" href="@strURL" title="Go to page @p of results">@p</a>

                }

            }

        </div><!--/ .wp-pagenavi-->

        if (articles.Count() == 0)

        {

            <p>There are no listings in this category</p>

        }

    }

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 31, 2014 @ 03:44
    Fuji Kusaka
    0

    Try this instead,

    OrderBy(x => x.createDate)
  • Hugh 30 posts 64 karma points
    Jan 31, 2014 @ 03:59
    Hugh
    0

    how do i specify descending?  OrderBy(x => x.createDate) with work ascending.

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 31, 2014 @ 05:00
    Fuji Kusaka
    0

    Are you still getting the same error though ?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 31, 2014 @ 06:05
    Fuji Kusaka
    1

    Does the following work ? Or still having the macro error.

    What happen if you remove Order ?

    OrderByDescending(x => x.CreateDate.ToString())
Please Sign in or register to post replies

Write your reply to:

Draft