public bool UpdateClassInfo(AddOrUpdateClassModel model) { ExceptionHelper.ThrowIfNull(model, nameof(model)); bool isUpdate = false; if (!string.IsNullOrWhiteSpace(model.Name)) { _LazyEntity.Value.name = model.Name; isUpdate = true; } if (model.StartDate != StartDate) { _LazyEntity.Value.startDate = model.StartDate; isUpdate = true; } if (model.EndDate != EndDate) { _LazyEntity.Value.endDate = model.EndDate; isUpdate = true; } if (!string.IsNullOrWhiteSpace(model.Property)) { _LazyEntity.Value.property = model.Property; isUpdate = true; } if (isUpdate) { _ClassRepository.SaveChanges(); } return(isUpdate); }
public void AddClass(AddOrUpdateClassModel args) { var isExist = _ClassRepository.Entities.AsNoTracking().Any(p => p.name == args.Name.Trim()); ExceptionHelper.ThrowIfTrue(isExist, nameof(args.Name), "添加的班级已存在"); if (!isExist) { _ClassRepository.Add(new Data.Class() { name = args.Name, startDate = args.StartDate, endDate = args.EndDate, property = args.Property, //班级属性 type = InsOfGrowthClassType.None, //班级类型(默认没类型) isEnable = true }); _ClassRepository.SaveChanges(); } }