zoukankan      html  css  js  c++  java
  • 总结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                 };
  • 相关阅读:
    多选按钮CheckBox
    DatePicker和DataPickerDialog以及AutoCompleteTextView的基本使用方法
    Broadcast机制(二)
    广播机制(一)
    XML文件解析
    WIFI网络操作
    SQL Server Profiler工具
    SQL Server执行计划的理解
    SQL Server常用元数据函数
    SQL Server数学函数
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/10842791.html
Copyright © 2011-2022 走看看