/// <exception cref="InvalidModelException"/> /// <exception cref="NotFoundException"/> public async Task UpdateAsync(Dtos.Curriculum dto) { if (dto.Id.Equals(Guid.Empty)) { throw new InvalidModelException("Property Id failed validation. Error was: Id is empty"); } var validator = new Dtos.CurriculumValidator(); 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.Department>().AnyAsync(d => d.Id == dto.DepartmentId)) { throw new InvalidModelException($"Department with id: {dto.DepartmentId} not found"); } if (!await _context.Set <Entities.EducationLevel>().AnyAsync(d => d.Id == dto.EducationLevelId)) { throw new InvalidModelException($"Education level with id: {dto.EducationLevelId} 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"); } 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"); } var curriculum = await _context.FindAsync <Dtos.Curriculum>(dto.Id); if (curriculum == null) { throw new NotFoundException($"Entity with id: {dto.Id} not found."); } curriculum.ListOfApprovals = dto.ListOfApprovals; curriculum.DateOfApproval = dto.DateOfApproval; curriculum.DepartmentId = dto.DepartmentId; curriculum.EducationLevelId = dto.EducationLevelId; curriculum.EducationProgramId = dto.EducationProgramId; curriculum.FormOfEducationId = dto.FormOfEducationId; curriculum.OrderOfApprovals = dto.OrderOfApprovals; curriculum.ProtocolOfAcademicCouncilOfUnit = dto.ProtocolOfAcademicCouncilOfUnit; curriculum.ProtocolOfAcademicCouncilOfUniversity = dto.ProtocolOfAcademicCouncilOfUniversity; curriculum.ScheduleOfEducationProcess = dto.ScheduleOfEducationProcess; curriculum.SpecialtyGuarantor = dto.SpecialtyGuarantor; curriculum.SpecialtyId = dto.SpecialtyId; curriculum.StructuralUnitId = dto.StructuralUnitId; curriculum.UpdatedAt = DateTime.UtcNow; curriculum.YearOfAdmission = dto.YearOfAdmission; await _context.SaveChangesAsync(); }
/// <exception cref="InvalidModelException"/> /// <exception cref="NotFoundException"/> public async Task <Guid> AddAsync(Dtos.Curriculum dto) { var validator = new Dtos.CurriculumValidator(); 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.Department>().AnyAsync(d => d.Id == dto.DepartmentId)) { throw new InvalidModelException($"Department with id: {dto.DepartmentId} not found"); } if (!await _context.Set <Entities.EducationLevel>().AnyAsync(d => d.Id == dto.EducationLevelId)) { throw new InvalidModelException($"Education level with id: {dto.EducationLevelId} 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"); } 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"); } var id = Guid.NewGuid(); var now = DateTime.UtcNow; var curriculum = new Entities.Curriculum { CreatedAt = now, DateOfApproval = dto.DateOfApproval, DepartmentId = dto.DepartmentId, EducationLevelId = dto.EducationLevelId, EducationProgramId = dto.EducationProgramId, FormOfEducationId = dto.FormOfEducationId, Id = id, ListOfApprovals = dto.ListOfApprovals, OrderOfApprovals = dto.OrderOfApprovals, ProtocolOfAcademicCouncilOfUnit = dto.ProtocolOfAcademicCouncilOfUnit, ProtocolOfAcademicCouncilOfUniversity = dto.ProtocolOfAcademicCouncilOfUniversity, ScheduleOfEducationProcess = dto.ScheduleOfEducationProcess, SpecialtyGuarantor = dto.SpecialtyGuarantor, SpecialtyId = dto.SpecialtyId, StructuralUnitId = dto.StructuralUnitId, UpdatedAt = now, YearOfAdmission = dto.YearOfAdmission }; _context.Add(curriculum); await _context.SaveChangesAsync(); return(id); }