Esempio n. 1
0
        private async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            // Process the message.
            Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");

            var    student      = studentDomain.ConvertToStudentEntity(Encoding.UTF8.GetString(message.Body));
            string errorMessage = await studentDomain.ApplyBusinessRules(student);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                SendMail("Student not added, " + errorMessage);
            }
            else
            {
                await studentRepository.AddAsync(student);

                await databaseUnitOfWork.SaveChangesAsync();

                SendMail($"Student added Successfully. StudentId:{student.StudentId}");
            }

            // Complete the message so that it is not received again.
            // This can be done only if the queue Client is created in ReceiveMode.PeekLock mode (which is the default).
            await queuClient.CompleteAsync(message.SystemProperties.LockToken);

            // Note: Use the cancellationToken passed as necessary to determine if the queueClient has already been closed.
            // If queueClient has already been closed, you can choose to not call CompleteAsync() or AbandonAsync() etc.
            // to avoid unnecessary exceptions.
        }
Esempio n. 2
0
        public async Task <IDataResult <long> > Add(AddStudentModel addStudentModel)
        {
            var validation = new AddStudentModelValidator().Valid(addStudentModel);

            if (!validation.Success)
            {
                return(new ErrorDataResult <long>(validation.Message));
            }

            StudentDomain domain = new StudentDomain(DatabaseUnitOfWork, StudentRepository, CourseRepository);

            var    student      = domain.ConvertToStudentEntity(addStudentModel);
            string errorMessage = await domain.ApplyBusinessRules(student);

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                return(new ErrorDataResult <long>(errorMessage));
            }

            await StudentRepository.AddAsync(student);

            await DatabaseUnitOfWork.SaveChangesAsync();

            return(new SuccessDataResult <long>(student.StudentId));
        }