Exemplo n.º 1
0
        public HopsController(IngredientsContext ctx, ILogger <HopsController> logger, HopRepository hopRepo)
        {
            _logger  = logger;
            _context = ctx;

            _hopRepo = hopRepo;
        }
Exemplo n.º 2
0
        public static void Seed(this IngredientsContext context)
        {
            context.Items.RemoveRange(context.Items);
            context.Products.RemoveRange(context.Products);
            context.Stores.RemoveRange(context.Stores);

            context.SaveChanges();

            PopularDadosStores(context);
        }
Exemplo n.º 3
0
        private static void PopularDadosStores(IngredientsContext context)
        {
            context.Stores.AddRange(new List <Store> {
                new Store {
                    Name = "Los Angeles - Pasadena", StoreId = new Guid("8048e9ec-80fe-4bad-bc2a-e4f4a75c834e")
                },
                new Store {
                    Name = "Los Angeles - Beverly Hills", StoreId = new Guid("8d618778-85d7-411e-878b-846a8eef30c0")
                }
            });

            context.SaveChanges();
        }
Exemplo n.º 4
0
        private async Task MessageHandler(Message message, CancellationToken cancellationToken)
        {
            if (_subscriptionClient.IsClosedOrClosing)
            {
                return;
            }

            _logService.SendMessagesAsync("LabelImageAddedService consumindo topico");

            var labelImageAddedString = Encoding.UTF8.GetString(message.Body);
            var responseItens         = JsonConvert.DeserializeObject <List <Produto> >(labelImageAddedString);

            foreach (var responseItem in responseItens)
            {
                using (var context = new IngredientsContext())
                {
                    var productRepository   = new ProductsRepository(context);
                    var itemsWithIngredient = productRepository.ListProductByIngredientName(responseItem.ItemName);

                    if (itemsWithIngredient.Any())
                    {
                        itemsWithIngredient.ForEach(x =>
                        {
                            x.Ingredients.Clear();
                            x.Ingredients.AddRange(responseItem.Ingredients.Select(ingredient => new Ingredient
                            {
                                ItemId = x.ItemId,
                                Name   = ingredient.ToUpper()
                            }));

                            productRepository.Save();
                        });
                    }
                }
            }

            _logService.SendMessagesAsync("LabelImageAddedService consumido com sucesso");

            await Task.CompletedTask;
        }