public DietSpecial UpdateSingle(int id, DietSpecialReq data) { DietSpecial model = db.DietSpecial.Find(id); SetDietSpecial(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public DietSpecial SetDietSpecial(DietSpecial model, DietSpecialReq data) { if (data.ServerDate != null && data.ServerDate != DateTime.MinValue && data.ServerDate != SqlDateTime.MinValue.Value) { model.ServerDate = data.ServerDate.Value; } if (data.RoomId != null) { model.RoomId = data.RoomId.Value; } if (!string.IsNullOrEmpty(data.RoomNumber)) { model.RoomNumber = data.RoomNumber; } if (data.KeHuId != null) { model.KeHuId = data.KeHuId.Value; } if (!string.IsNullOrEmpty(data.KeHuName)) { model.KeHuName = data.KeHuName; } 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.SelectDiet)) { if (data.IsAppend != null) { if (data.IsAppend.Value) { if (model.SelectDiet.IndexOf(data.SelectDiet) < 0) { if (!string.IsNullOrEmpty(model.SelectDiet)) { model.SelectDiet += ","; } model.SelectDiet += data.SelectDiet; } } else { if (model.SelectDiet.IndexOf(data.SelectDiet) >= 0) { model.SelectDiet = model.SelectDiet.Replace("," + data.SelectDiet, ""); model.SelectDiet = model.SelectDiet.Replace(data.SelectDiet, ""); } } } else { model.SelectDiet = data.SelectDiet; } } if (!string.IsNullOrEmpty(data.OtherDiet)) { model.OtherDiet = data.OtherDiet; } //if (!string.IsNullOrEmpty(data.Desc)) model.Desc = data.Desc; if (!string.IsNullOrEmpty(data.JiShiDesc)) { model.JiShiDesc = data.JiShiDesc; } if (data.projectid != null) { model.ProjectId = data.projectid.Value; } if (data.SaveId != null) { model.SaveId = data.SaveId.Value; } if (!string.IsNullOrEmpty(data.SaveName)) { model.SaveName = data.SaveName; } if (data.StartPersonId != null) { model.StartPersonId = data.StartPersonId.Value; } if (!string.IsNullOrEmpty(data.StartPersonName)) { model.StartPersonName = data.StartPersonName; } if (data.SetStep != null) { model.SetStep = data.SetStep.Value; } if (!string.IsNullOrEmpty(data.CenterCheckState)) { model.CenterCheckState = data.CenterCheckState; } if (data.CenterCheckDate != null) { model.CenterCheckDate = data.CenterCheckDate; } if (data.CenterCheckPersonId != null) { model.CenterCheckPersonId = data.CenterCheckPersonId; } if (!string.IsNullOrEmpty(data.CenterCheckPersonName)) { model.CenterCheckPersonName = data.CenterCheckPersonName; } if (!string.IsNullOrEmpty(data.MenDianCheckState)) { model.MenDianCheckState = data.MenDianCheckState; } if (data.MDCheckDate != null) { model.MDCheckDate = data.MDCheckDate; } if (data.MDCheckPersonId != null) { model.MDCheckPersonId = data.MDCheckPersonId; } if (!string.IsNullOrEmpty(data.MDCheckPersonName)) { model.MDCheckPersonName = data.MDCheckPersonName; } return(model); }