private async Task <EntitySingleResult <TrainingBuildCoursesAttendeeReadModel> > GetAttendee(
            MapToCourseCommand <TrainingBuildCoursesAttendeeUpdateModel> message, CancellationToken cancellationToken)
        {
            var search = Query <Data.Entities.TrainingBuildCourseAttendee> .Create(x => x.Id == message.Id);

            search.IncludeProperties = "Course";

            var query   = new SingleQuery <Data.Entities.TrainingBuildCourseAttendee>(search);
            var command = new EntitySingleQuery <Data.Entities.TrainingBuildCourseAttendee,
                                                 TrainingBuildCoursesAttendeeReadModel>(query);

            return(await _mediator.Send(command, cancellationToken).ConfigureAwait(false));
        }
Beispiel #2
0
        public async Task <IActionResult> MaptoOtherCourse(CancellationToken cancellationToken,
                                                           Guid Id, TrainingBuildCoursesAttendeeUpdateModel model)
        {
            var command = new MapToCourseCommand <TrainingBuildCoursesAttendeeUpdateModel>(model, Id);
            var result  = await Mediator.Send(command, cancellationToken).ConfigureAwait(false);

            Cache.Remove($"{CacheKey.TrainingCourses.ToString()}");
            return(new OkObjectResult(new
            {
                Data = result,
                Status = StatusCodes.Status200OK
            }));
        }
        protected override async Task <EntitySingleResult <TrainingBuildCoursesAttendeeReadModel> > ProcessAsync(MapToCourseCommand <TrainingBuildCoursesAttendeeUpdateModel> message, CancellationToken cancellationToken)
        {
            var result = await GetAttendee(message, cancellationToken).ConfigureAwait(false);

            if (result.Data.CourseId == message.Course.CourseId)
            {
                throw new DomainException(422, $"Trainee is already in in this course. Please select different course.");
            }

            var resultQueryNewCourse = await GetNewCourse(message.Course.CourseId, cancellationToken).ConfigureAwait(false);

            if (resultQueryNewCourse.MaxAttendee == resultQueryNewCourse.NoAttendee)
            {
                throw new DomainException(422, $"This course is already full. Please select other course or remove other trainee.,");
            }

            var output = await ReAssignedToCourse(message.Course, cancellationToken).ConfigureAwait(false);

            var old = await UpdateOldAttendee(result.Data, message.Id, cancellationToken).ConfigureAwait(false);

            var resultNewCourse = await AddToNewCourse(resultQueryNewCourse, cancellationToken).ConfigureAwait(false);

            var resultOldCourse = await UpdateOldCourse(result.Data.Courses, cancellationToken).ConfigureAwait(false);

            var transaction = await PaymentTransaction(result.Data.AttendeeId, result.Data.CourseId, message.Course.CourseId, cancellationToken).ConfigureAwait(false);

            return(new EntitySingleResult <TrainingBuildCoursesAttendeeReadModel> {
                Data = output
            });
        }