public HuLiRegist UpdateSingle(int id, HuLiRegistReq data) { HuLiRegist model = db.HuLiRegist.Find(id); SetHuLiRegist(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public HuLiRegist SetHuLiRegist(HuLiRegist model, HuLiRegistReq data) { if (data.StartDate != null && data.StartDate != DateTime.MinValue && data.StartDate != SqlDateTime.MinValue.Value) { model.StartDate = data.StartDate.Value; } if (data.EndDate != null && data.EndDate != DateTime.MinValue && data.EndDate != SqlDateTime.MinValue.Value) { model.EndDate = data.EndDate.Value; } if (!string.IsNullOrEmpty(data.ServerType)) { model.ServerType = data.ServerType; } if (data.PareCount != null) { model.PareCount = data.PareCount.Value; } 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 (data.projectid != null) { model.projectid = data.projectid.Value; } if (data.ServerDate != null && data.ServerDate != DateTime.MinValue && data.ServerDate != SqlDateTime.MinValue.Value) { model.ServerDate = data.ServerDate.Value; } return(model); }