//Crud public async Task <FacultyResponse> GetByIdAsync(int id) { var existingFaculty = await _facultyRepository.FindById(id); if (existingFaculty == null) { return(new FacultyResponse("Faculty not found")); } return(new FacultyResponse(existingFaculty)); }
//CRUD public async Task <TutorResponse> SaveAsync(Tutor tutor) { if (_accountRepository.FindById(tutor.AccountId) != null) { if (_facultyRepository.FindById(tutor.FacultyId) != null) { try { await _tutorRepository.AddAsync(tutor); await _unitOfWork.CompleteAsync(); return(new TutorResponse(tutor)); } catch (Exception e) { return(new TutorResponse($"An error ocurred while saving {e.Message}")); } } else { return(new TutorResponse($"The faculty with id {tutor.FacultyId}, doesn't exist")); } } else { return(new TutorResponse($"The account with id {tutor.AccountId}, doesn't exist")); } }
public async Task Create(Career career) { var faculty = await _facultyRepository.FindById(career.FacultyId); var newCareer = new Career { Name = career.Name, Code = career.Code, Faculty = faculty }; await _careerRepository.Add(newCareer); }
public async Task <CareerResponse> SaveAsync(Career career, int facultyId) { if (_facultyRepository.FindById(facultyId) != null) { try { career.FacultyId = facultyId; await _careerRepository.AddAsync(career); await _unitOfWork.CompleteAsync(); return(new CareerResponse(career)); } catch (Exception e) { return(new CareerResponse($"An error ocurred while saving {e.Message}")); } } else { return(new CareerResponse($"An error ocurred, the faculty with id {facultyId} doesn't exist")); } }
public async Task <Faculty> FindById(int id) { return(await _facultyRepository.FindById(id)); }