public TrainingRecord UpdateSingle(int id, TrainingRecordReq data) { TrainingRecord model = db.TrainingRecord.Find(id); SetTrainingRecord(model, data); db.SaveChanges(); return(model); }
/// <summary> /// 设置model,如果不为空就设置,如果为空则和之前一样 /// </summary> /// <param name="target"></param> /// <param name="source"></param> /// <returns></returns> public TrainingRecord SetTrainingRecord(TrainingRecord model, TrainingRecordReq data) { if (data.WeekNumber != null) { model.WeekNumber = data.WeekNumber.Value; } if (!string.IsNullOrEmpty(data.DayClass)) { model.DayClass = data.DayClass; } if (!string.IsNullOrEmpty(data.TrainContent)) { model.TrainContent = data.TrainContent; } if (!string.IsNullOrEmpty(data.ZhangWoQingKuang)) { model.ZhangWoQingKuang = data.ZhangWoQingKuang; } if (!string.IsNullOrEmpty(data.StudentFeedBack)) { model.StudentFeedBack = data.StudentFeedBack; } if (!string.IsNullOrEmpty(data.TeacherFeedBack)) { model.TeacherFeedBack = data.TeacherFeedBack; } if (!string.IsNullOrEmpty(data.TrainPlace)) { model.TrainPlace = data.TrainPlace; } if (!string.IsNullOrEmpty(data.State)) { model.State = data.State; } if (data.CreateDate != null && data.CreateDate != DateTime.MinValue && data.CreateDate != SqlDateTime.MinValue.Value) { model.CreateDate = data.CreateDate.Value; } if (data.OptId != null) { model.OptId = data.OptId.Value; } if (!string.IsNullOrEmpty(data.OptName)) { model.OptName = data.OptName; } if (data.StudentId != null) { model.StudentId = data.StudentId.Value; } if (!string.IsNullOrEmpty(data.StudentName)) { model.StudentName = data.StudentName; } return(model); }