Beispiel #1
0
        public async Task AnswerNotification(NotificationAnswerDTO notificationAnswerDto)
        {
            var notificationAnswer = new DAL.App.DTO.NotificationAnswer
            {
                Attending      = notificationAnswerDto.Coming,
                Content        = notificationAnswerDto.Content,
                NotificationId = Guid.Parse(notificationAnswerDto.NotificationId),
            };
            await ServiceRepository.AddNewAnswer(notificationAnswer);

            await ServiceUnitOfWork.SaveChangesAsync();

            var notification = await ServiceUnitOfWork.NotificationRepository.FirstOrDefaultAsync(Guid.Parse(notificationAnswerDto.NotificationId));

            await ServiceUnitOfWork.NotificationRepository.UpdateNotification(notification);

            await ServiceUnitOfWork.SaveChangesAsync();

            var userInTraining =
                await ServiceUnitOfWork.UsersInTrainingRepository.FindByAppUserIdAndTrainingId(Guid.Parse(notificationAnswerDto.AppUserId),
                                                                                               Guid.Parse(notificationAnswerDto.TrainingId));

            if (notificationAnswerDto.Coming)
            {
                userInTraining.AttendingTraining = true;
                ServiceUnitOfWork.UsersInTrainingRepository.UpdateUserInTraining(userInTraining);
            }
            await ServiceUnitOfWork.SaveChangesAsync();
        }