Exemplo n.º 1
0
        public async Task <IActionResult> Index()
        {
            //Notifications message = new Notifications();

            using (var bus = RabbitHutch.CreateBus("host=localhost"))
            {
                bus.SubscribeAsync <CategoryGroups>("create_category_groups",
                                                    groups => Task.Factory.StartNew(() =>
                {
                    var message = "Added Category Group: " + groups.Name;
                    SubscriberViewModel.Notifications.Message          = message;
                    SubscriberViewModel.Notifications.NotificationType = "CategoryGroup";
                }));


                bus.Subscribe <CategoryTypes>("create_category_types",
                                              categoryTypes => Task.Factory.StartNew(() =>
                {
                    var message = "Added Category Type: " + categoryTypes.Name;
                    SubscriberViewModel.Notifications.Message          = message;
                    SubscriberViewModel.Notifications.NotificationType = "CategoryType";
                }));

                //bus.Subscribe<Products>("create_product_by_admin",
                //    categoryTypes => Task.Factory.StartNew(() =>
                //    {
                //        var message = "Added Product by Admin: " + typeof(Products);
                //        SubscriberViewModel.Notifications.Message = message;
                //        SubscriberViewModel.Notifications.NotificationType = "ProductsByAdmin";
                //    }));
            }

            // persist
            if (SubscriberViewModel.Notifications.Message != null)
            {
                await _colibriDbContext.AddAsync(SubscriberViewModel.Notifications);

                await _colibriDbContext.SaveChangesAsync();
            }

            return(View(SubscriberViewModel));
        }