/// <exception cref="InvalidModelException"/> /// <exception cref="NotFoundException"/> public async Task UpdateAsync(Dtos.ExamsGradesSpreadsheet dto) { if (dto.Id.Equals(Guid.Empty)) { throw new InvalidModelException("Property Id failed validation. Error was: Id is empty"); } var validator = new Dtos.ExamsGradesSpreadsheetValidator(); ValidationResult result = validator.Validate(dto); if (!result.IsValid) { string errMess = string.Empty; foreach (var failure in result.Errors) { errMess += $"Property { failure.PropertyName } failed validation. Error was: { failure.ErrorMessage }\n"; } throw new InvalidModelException(errMess); } if (!await _context.Set <Entities.Specialty>().AnyAsync(d => d.Id == dto.SpecialtyId)) { throw new InvalidModelException($"Specialty with id: {dto.SpecialtyId} not found"); } if (!await _context.Set <Entities.StructuralUnit>().AnyAsync(d => d.Id == dto.StructuralUnitId)) { throw new InvalidModelException($"Structural unit with id: {dto.StructuralUnitId} not found"); } if (!await _context.Set <Entities.AcademicDiscipline>().AnyAsync(d => d.Id == dto.AcademicDisciplineId)) { throw new InvalidModelException($"Academic discipline with id: {dto.AcademicDisciplineId} not found"); } if (!await _context.Set <Entities.AcademicGroup>().AnyAsync(d => d.Id == dto.AcademicGroupId)) { throw new InvalidModelException($"Academic group with id: {dto.AcademicGroupId} not found"); } if (!await _context.Set <Entities.EducationProgram>().AnyAsync(d => d.Id == dto.EducationProgramId)) { throw new InvalidModelException($"Education program with id: {dto.EducationProgramId} not found"); } if (!await _context.Set <Entities.FormOfEducation>().AnyAsync(d => d.Id == dto.FormOfEducationId)) { throw new InvalidModelException($"Form of education with id: {dto.FormOfEducationId} not found"); } var examsGradesSpreadsheet = await _context.FindAsync <Entities.ExamsGradesSpreadsheet>(dto.Id); if (examsGradesSpreadsheet == null) { throw new NotFoundException($"Entity with id: {dto.Id} not found."); } examsGradesSpreadsheet.UpdatedAt = DateTime.UtcNow; examsGradesSpreadsheet.StructuralUnitId = dto.StructuralUnitId; examsGradesSpreadsheet.AcademicDisciplineId = dto.AcademicDisciplineId; examsGradesSpreadsheet.AcademicGroupId = dto.AcademicGroupId; examsGradesSpreadsheet.EducationProgramId = dto.EducationProgramId; examsGradesSpreadsheet.ExamDate = dto.ExamDate; examsGradesSpreadsheet.ExamsSpreadsheetAttestationType = dto.ExamsSpreadsheetAttestationType; examsGradesSpreadsheet.ExamsSpreadsheetType = dto.ExamsSpreadsheetType; examsGradesSpreadsheet.FormOfEducationId = dto.FormOfEducationId; examsGradesSpreadsheet.SemesterNumber = dto.SemesterNumber; examsGradesSpreadsheet.SpecialtyId = dto.SpecialtyId; examsGradesSpreadsheet.SpreadsheetNumber = dto.SpreadsheetNumber; await _context.SaveChangesAsync(); }
/// <exception cref="InvalidModelException"/> /// <exception cref="NotFoundException"/> public async Task <Guid> AddAsync(Dtos.ExamsGradesSpreadsheet dto) { var validator = new Dtos.ExamsGradesSpreadsheetValidator(); ValidationResult result = validator.Validate(dto); if (!result.IsValid) { string errMess = string.Empty; foreach (var failure in result.Errors) { errMess += $"Property { failure.PropertyName } failed validation. Error was: { failure.ErrorMessage }\n"; } throw new InvalidModelException(errMess); } if (!await _context.Set <Entities.Specialty>().AnyAsync(d => d.Id == dto.SpecialtyId)) { throw new InvalidModelException($"Specialty with id: {dto.SpecialtyId} not found"); } if (!await _context.Set <Entities.StructuralUnit>().AnyAsync(d => d.Id == dto.StructuralUnitId)) { throw new InvalidModelException($"Structural unit with id: {dto.StructuralUnitId} not found"); } if (!await _context.Set <Entities.AcademicDiscipline>().AnyAsync(d => d.Id == dto.AcademicDisciplineId)) { throw new InvalidModelException($"Academic discipline with id: {dto.AcademicDisciplineId} not found"); } if (!await _context.Set <Entities.AcademicGroup>().AnyAsync(d => d.Id == dto.AcademicGroupId)) { throw new InvalidModelException($"Academic group with id: {dto.AcademicGroupId} not found"); } if (!await _context.Set <Entities.EducationProgram>().AnyAsync(d => d.Id == dto.EducationProgramId)) { throw new InvalidModelException($"Education program with id: {dto.EducationProgramId} not found"); } if (!await _context.Set <Entities.FormOfEducation>().AnyAsync(d => d.Id == dto.FormOfEducationId)) { throw new InvalidModelException($"Form of education with id: {dto.FormOfEducationId} not found"); } var id = Guid.NewGuid(); var now = DateTime.UtcNow; var examsGradesSpreadsheet = new Entities.ExamsGradesSpreadsheet { Id = id, CreatedAt = now, UpdatedAt = now, StructuralUnitId = dto.StructuralUnitId, AcademicDisciplineId = dto.AcademicDisciplineId, AcademicGroupId = dto.AcademicGroupId, EducationProgramId = dto.EducationProgramId, ExamDate = dto.ExamDate, ExamsSpreadsheetAttestationType = dto.ExamsSpreadsheetAttestationType, ExamsSpreadsheetType = dto.ExamsSpreadsheetType, FormOfEducationId = dto.FormOfEducationId, SemesterNumber = dto.SemesterNumber, SpecialtyId = dto.SpecialtyId, SpreadsheetNumber = dto.SpreadsheetNumber }; await _context.AddAsync(examsGradesSpreadsheet); await _context.SaveChangesAsync(); return(id); }