如何按日期订单 [英] how can I make order list by date

查看:84
本文介绍了如何按日期订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个课程,我需要通过突出显示然后按创建时间从他们两个订单生成一个有序列表





头等舱



公共类WebPost

{

public string id {get;组; } $ / $
public string page_id {get;组; }

public string page_name {get;组; }

公共字符串消息{get;组; }

公共字符串图片{get;组; }

公共字符串链接{get;组; }

public string source {get;组; }

公共字符串类型{get;组; }

public string shares_count {get;组; }

public string likes_count {get;组; }

public string comments_count {get;组; }

public DateTime created_time {get;组; }

}







二等奖



公共类WebResponse

{

public string feed_social_id {get;组; }

public string social_service_id {get;组; }

公共字符串值{get;组; }

public bool突出显示{get;组; }

}

解决方案

ConcurrentDictionary< webresponse,>> parallelPostsDictionary = new ConcurrentDictionary< webresponse,>>();



List< webpost> highlitedlist = new List< webpost>();

List< webpost> normallist = new List< webpost>();



foreach(var key in parallelPostsDictionary.Keys)

{

List< webpost> result = null;



parallelPostsDictionary.TryGetValue(key,out result);

if(key.highlighted)

{

highlitedlist.Add(result.ElementAt(0));

result.RemoveAt(0);

}



normallist.AddRange(结果);

}



highlitedlist = highlitedlist.OrderByDescending (x => x.created_time)。ToList();

normallist = normallist.OrderByDescending(x => x.created_time).ToList();

fb_Posts .AddRange(highlitedlist);

fb_Posts.AddRange(normallist);



Cache.Add< list>< webpost>>( cacheKey,fb_Posts,expiryTime);

 


I have two classes I need to make an ordered list from both of them fist order by highlighted then by created time


First Class

public class WebPost
{
public string id { get; set; }
public string page_id { get; set; }
public string page_name { get; set; }
public string message { get; set; }
public string picture { get; set; }
public string link { get; set; }
public string source { get; set; }
public string type { get; set; }
public string shares_count { get; set; }
public string likes_count { get; set; }
public string comments_count { get; set; }
public DateTime created_time { get; set; }
}



Second Class

public class WebResponse
{
public string feed_social_id { get; set; }
public string social_service_id { get; set; }
public string value { get; set; }
public bool highlighted { get; set; }
}

解决方案

ConcurrentDictionary<webresponse,>> parallelPostsDictionary = new ConcurrentDictionary<webresponse,>>();

List<webpost> highlitedlist = new List<webpost>();
List<webpost> normallist = new List<webpost>();

foreach (var key in parallelPostsDictionary.Keys)
{
List<webpost> result = null;

parallelPostsDictionary.TryGetValue(key, out result);
if (key.highlighted)
{
highlitedlist.Add(result.ElementAt(0));
result.RemoveAt(0);
}

normallist.AddRange(result);
}

highlitedlist = highlitedlist.OrderByDescending(x => x.created_time).ToList();
normallist = normallist.OrderByDescending(x => x.created_time).ToList();
fb_Posts.AddRange(highlitedlist);
fb_Posts.AddRange(normallist);

Cache.Add<list><webpost>>(cacheKey, fb_Posts, expiryTime);


这篇关于如何按日期订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆