public HuoPingShenQing UpdateSingle(int id, HuoPingShenQingReq data) { HuoPingShenQing model = db.HuoPingShenQing.Find(id); SetHuoPingShenQing(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public HuoPingShenQing SetHuoPingShenQing(HuoPingShenQing model, HuoPingShenQingReq data) { if (data.projectid != null) { model.projectid = data.projectid.Value; } if (!string.IsNullOrEmpty(data.ProjectName)) { model.ProjectName = data.ProjectName; } if (data.HuoPingCount != null) { model.HuoPingCount = data.HuoPingCount.Value; } if (data.OptId != null) { model.OptId = data.OptId.Value; } if (!string.IsNullOrEmpty(data.OptName)) { model.OptName = data.OptName; } if (data.OptDateTime != null && data.OptDateTime != DateTime.MinValue && data.OptDateTime != SqlDateTime.MinValue.Value) { model.OptDateTime = data.OptDateTime.Value; } if (!string.IsNullOrEmpty(data.ServerMonth)) { model.ServerMonth = data.ServerMonth; } if (!string.IsNullOrEmpty(data.State)) { model.State = data.State; } return(model); }