private async Task PublishUpdatingDepartment(string oldDepartmentCode, Department department)
        {
            var parent = await this.departmentRepository.GetByIdAsync(department.Id_DV_Cha);

            var message = this.mapper.Map <DepartmentMessage>(department);

            if (parent != null)
            {
                message.Ma_DV_Cha = parent.Ma_DonVi;
            }

            message.Ma_DV_Cu = oldDepartmentCode;

            rabbitMQService.Publish(message, RabbitActionTypes.Update, RabbitEntities.Department);
        }
        public void PublishConsumeAcknowledge(string queue, string message)
        {
            var before = new Class {
                String = message,
            };

            _service.Publish(queue, before);

            var(actual, deliveryTag) = _service.Consume <Class>(queue);

            Assert.NotNull(actual);
            Assert.Equal(message, actual.String);
            Assert.NotEqual(default, deliveryTag);
Beispiel #3
0
        public async Task <T> MailCreateAsync(T model, IHostingEnvironment hostEnv)
        {
            ///await elasticSearchService.CreateAsync();
            IndexResponseDTO indexResponse = await elasticSearchService.IndexAsync(model);

            bool rabbitMqResponse = await rabbitMqService.Publish(model, "mail.exchangeName", "mail.queue");

            T mail = await rabbitMqService.Consume("mail.exchangeName", "mail.queue");

            string body = mailHelper.CreateMailBody((MailRequest)(object)mail, hostEnv.WebRootPath);
            await mailHelper.SendAsync("mail example", body);

            return(mail);
        }
        /// <summary>
        /// Delete employee by employee code
        /// </summary>
        /// <param name="employeeCode">idNhanVien</param>
        /// <param name="currUserId">Current user id</param>
        /// <returns>the task</returns>
        public async Task <Employee> DeleteEmployeeByCode(string employeeCode, int currUserId)
        {
            var employee = await this.employeeRepository.GetEmployeeByCode(employeeCode);

            // validate employee
            await ValidateEmployeeForDelete(employee);

            employee = await this.employeeRepository.DeteteEmployee(employee, currUserId);

            await this.PublishUpdatingEmployee(employee.Ma_NhanVien, employee);

            var accounts = await this.accountRepository.GetAllAccountsByEmployeeId(employee.Id_NhanVien);

            foreach (var a in accounts)
            {
                var message = this.mapper.Map <AccountMessage>(a);
                message.Ma_NhanVien     = employee.Ma_NhanVien;
                message.Ma_NguoiDung_Cu = a.Ma_NguoiDung;
                // update accounts that are deleted when the employee is deleted
                rabbitMQService.Publish(message, RabbitActionTypes.Update, RabbitEntities.Account);
            }

            return(employee);
        }
Beispiel #5
0
 public void Publish(string value)
 {
     _mqService.Publish(value);
 }