public PingXiangInfo UpdateSingle(int id, PingXiangInfoReq data) { PingXiangInfo model = db.PingXiangInfo.Find(id); SetPingXiangInfo(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public PingXiangInfo SetPingXiangInfo(PingXiangInfo model, PingXiangInfoReq data) { if (!string.IsNullOrEmpty(data.PingXiangName)) { model.PingXiangName = data.PingXiangName; } if (!string.IsNullOrEmpty(data.GongXiao)) { model.GongXiao = data.GongXiao; } if (!string.IsNullOrEmpty(data.ShouFeiType)) { model.ShouFeiType = data.ShouFeiType; } if (!string.IsNullOrEmpty(data.ValidState)) { model.ValidState = data.ValidState; } if (data.OptId != null) { model.OptId = data.OptId.Value; } if (!string.IsNullOrEmpty(data.OptName)) { model.OptName = data.OptName; } if (data.CreateDate != null && data.CreateDate != DateTime.MinValue && data.CreateDate != SqlDateTime.MinValue.Value) { model.CreateDate = data.CreateDate.Value; } if (!string.IsNullOrEmpty(data.ManagerType)) { model.ManagerType = data.ManagerType; } return(model); }