public CaipuModel UpdateSingle(int id, CaipuModelReq data) { CaipuModel model = db.CaipuModel.Find(id); SetCaipuModel(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public CaipuModel SetCaipuModel(CaipuModel model, CaipuModelReq data) { if (!string.IsNullOrEmpty(data.Name)) { model.Name = data.Name; } if (!string.IsNullOrEmpty(data.CaiType)) { model.CaiType = data.CaiType; } if (!string.IsNullOrEmpty(data.CanType)) { model.CanType = data.CanType; } if (data.Step != null) { model.Step = data.Step.Value; } //if(!string.IsNullOrEmpty(data.Peiliao)) model.Peiliao = data.Peiliao; 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 (!string.IsNullOrEmpty(data.Type)) { model.Type = data.Type; } if (!string.IsNullOrEmpty(data.ServerWeekDay)) { model.ServerWeekDay = data.ServerWeekDay; } //if(!string.IsNullOrEmpty(data.Gongxiao)) model.Gongxiao = data.Gongxiao; if (data.TypeId != null) { model.TypeId = data.TypeId.Value; } return(model); }