public async Task Edit(SemesterInput input) { //检查Id参数 if (!input.Id.HasValue) { throw new UserFriendlyException("传入参数Id不正确。"); } //获取需要修改的对象 var semester = await _semesterRepository.FirstOrDefaultAsync(x => x.Id == input.Id.Value); if (semester == null) { throw new UserFriendlyException("当前学期不存在!"); } //修改属性值 if (!string.IsNullOrEmpty(input.Name)) { semester.Name = input.Name; } if (input.Start.HasValue) { semester.Start = input.Start.Value; } if (input.End.HasValue) { semester.End = input.End.Value; } //执行修改数据方法 await _semesterRepository.UpdateAsync(semester); }
public async Task Add(SemesterInput input) { //验证传入参数 if (!input.Start.HasValue) { throw new UserFriendlyException("传入Start参数不正确!"); } if (!input.End.HasValue) { throw new UserFriendlyException("传入End参数不正确!"); } if (string.IsNullOrEmpty(input.Name)) { throw new UserFriendlyException("传入Name参数不正确!"); } //创建学期对象 var semester = new Education.Semester { Name = input.Name, Start = input.Start.Value, End = input.End.Value }; //执行插入数据方法 await _semesterRepository.InsertAsync(semester); }