Ejemplo n.º 1
0
        private async Task <bool> ProcessSignupAsync(Models.CourseStudent courseStudent)
        {
            try
            {
                if (courseStudent == null || courseStudent.CourseId == 0 || courseStudent.StudentId == 0)
                {
                    _logger.LogInformation(INVALID_INPUTS);
                    return(false);
                }
                var course = await _courseDbContext.FindAsync(courseStudent.CourseId);

                if (course == null)
                {
                    throw new KeyNotFoundException();
                }
                if (course.CourseStudents.Count() >= course.Capacity)
                {
                    throw new CourseCapacityFullException();
                }

                courseStudent.JoinDate = DateTime.UtcNow;

                _courseStudentDbContext.Add(courseStudent);

                var records = await _courseStudentDbContext.SaveChangesAsync();

                return(records > 0);
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }
Ejemplo n.º 2
0
        public Task SignupPublishAsync(int courseId, int studentId, CancellationToken cancellationToken)
        {
            // Publish creation of course student to messaging service bus queue.
            var courseStudent = new Models.CourseStudent()
            {
                CourseId  = courseId,
                StudentId = studentId,
            };
            var publishTask = Task.Factory.StartNew(
                action: () => _messagingServiceBus.Publish("Course_Student_Create", courseStudent),
                cancellationToken: cancellationToken,
                creationOptions: TaskCreationOptions.PreferFairness,
                scheduler: null
                );

            return(publishTask);
        }