总结Linq或者lamdba的写法

 1                var head = new OmsEcorderHead
 2                 {
 3                     PkEcorderHead = OrderHeadId,
 4                     AppId = appid,
 5                     Integral = Convert.ToDecimal(reqdata.Body.Integral.ToString()),
 6                     ShipIntegral = Convert.ToDecimal(reqdata.Body.ShipIntegral.ToString()),
 7                     //必填
 8                     Co = reqdata.Body.CO,
 9                     Whse = reqdata.Body.WHSE,
10                     ReceiptTime = Convert.ToDateTime(reqdata.Body.ReceiptTime.ToString("yyyy-MM-dd HH:mm:ss"))
11                 }
                var InvoiceTitle = new string[] { "a", "b", "c", "d ", "e" };
                if (InvoiceTitle.Where<string>(l => l == reqdata.Body.InvoiceTitle.ToLower()).Count() == 0)
                     throw new ECOrderException { ErrorCode = "X1007-01", TransMessage = "传入的InvoiceTitle的值不正确,请修改" };

  

 将传递过来的一个实体,赋值给一个自己的类, 
1
var ary = reqdata.Body.Detail.Select(l => new OMSECData.orderDetail 2 {
4
GoodsName = l.GoodsName, 5 GoodsNumber = l.GoodsNumber, 6 GoodsPrice = l.GoodsPrice, 7 TradeIntegral = l.TradeIntegral, 8 ShopMoney = l.ShopMoney, 9 GoodsAmount = l.GoodsAmount,
16 CreateDateTime = Convert.ToDateTime(DateTime.UtcNow.AddHours(8)) 17 }).ToList();
                   foreach (var item in ary)
                    head.OmsEcorderDetail.Add(item);

 

 1 ActionResult result = null;
 2 
 3  var obj = new JObject
 4                 {
 5                     {"Head", new JObject
 6                         {
 7                             { "TransMessage","" },
 8                             { "TransCode",transCode },
 9                             { "TransId", reqdata.Head.TransId },
10                             { "ErrorCode", "" }
11                         }
12                     },
13                     {"Body", new JObject
14                         {
15                             { "CreateDateTime", DateTimeOffset.Now.AddHours(8).ToUnixTimeSeconds().ToString() }
16                         }
17                     }
18                 };
19 
20                 result = new ContentResult()
21                 {
22                     Content = Newtonsoft.Json.JsonConvert.SerializeObject(obj),
23                     ContentType = "application/json"
24                 };

 

posted @ 2019-05-10 10:07  ProZkb  阅读(207)  评论(0编辑  收藏  举报