示例#1
0
        public async Task PutAsyncWhenTrainingTutorsReturnsTrainingTutor()
        {
            // Arrange
            var mockTrainingTutorRepository = GetDefaultITrainingTutorRepositoryInstance();
            var mockIUnitOfWork             = GetDefaultIUnitOfWorkInstance();

            TrainingTutor trainingTutor = new TrainingTutor();
            int           trainingId    = 2;
            int           tutorId       = 102;

            trainingTutor.TrainingId = trainingId;
            trainingTutor.TutorId    = tutorId;
            trainingTutor.Assistance = false;

            TrainingTutor trainingTutorExpected = new TrainingTutor();

            trainingTutorExpected.Assistance = true;

            mockTrainingTutorRepository.Setup(r => r.FindByTrainingIdAndTutorId(trainingId, tutorId))
            .Returns(Task.FromResult <TrainingTutor>(trainingTutor));

            var service = new TrainingTutorService(mockTrainingTutorRepository.Object, mockIUnitOfWork.Object, null);

            // Act
            TrainingTutorResponse result = await service.UpdateAsync(trainingId, tutorId, trainingTutorExpected);

            // Assert
            Assert.AreEqual(trainingTutorExpected.Assistance, result.Resource.Assistance);
        }
示例#2
0
        public async Task <TrainingTutorResponse> SaveAsync(TrainingTutor trainingTutor)
        {
            try
            {
                await _trainingTutorRepository.AddAsync(trainingTutor);

                //Added by rodrigo rule 29
                NotificationUser nu = new NotificationUser();
                nu.NotificationId = 903;
                nu.UserId         = trainingTutor.TutorId;

                await _notificationUserRepository.AddAsync(nu);


                await _unitOfWork.CompleteAsync();

                return(new TrainingTutorResponse(trainingTutor));
            }
            catch (Exception ex)
            {
                return(new TrainingTutorResponse($"An error ocurred while saving the training tutor: {ex.Message}"));
            }
        }
示例#3
0
 public void Update(TrainingTutor trainingTutor)
 {
     _context.TrainingTutors.Update(trainingTutor);
 }
示例#4
0
 public void Remove(TrainingTutor trainingTutor)
 {
     _context.TrainingTutors.Remove(trainingTutor);
 }
示例#5
0
 public async Task AddAsync(TrainingTutor trainingTutor)
 {
     await _context.TrainingTutors.AddAsync(trainingTutor);
 }
示例#6
0
        public async Task <TrainingTutorResponse> UpdateAsync(int trainingId, int tutorId, TrainingTutor trainingTutor)
        {
            var existingTrainingTutor = await _trainingTutorRepository.FindByTrainingIdAndTutorId(trainingId, tutorId);

            if (existingTrainingTutor == null)
            {
                return(new TrainingTutorResponse("Training tutor not found"));
            }

            existingTrainingTutor.TrainingId = trainingTutor.TrainingId;
            existingTrainingTutor.TutorId    = trainingTutor.TutorId;
            existingTrainingTutor.Assistance = trainingTutor.Assistance;

            try
            {
                _trainingTutorRepository.Update(existingTrainingTutor);
                await _unitOfWork.CompleteAsync();

                return(new TrainingTutorResponse(existingTrainingTutor));
            }
            catch (Exception ex)
            {
                return(new TrainingTutorResponse($"An error ocurred while updating the training tutor: {ex.Message}"));
            }
        }