public async Task <IActionResult> Update(Product product)
 {
     using (ElasticContext dbContext = new ElasticContext())
     {
         if (product.Id == 0)
         {
             var newProduct = new Product();
             newProduct.Name       = product.Name;
             newProduct.SeriNumber = product.SeriNumber;
             newProduct.Price      = product.Price;
             newProduct.Count      = product.Count;
             await dbContext.Products.AddAsync(newProduct);
         }
         else
         {
             var updateProduct = dbContext.Products.FirstOrDefault(prod => prod.Id == product.Id);
             updateProduct.Name       = product.Name;
             updateProduct.SeriNumber = product.SeriNumber;
             updateProduct.Price      = product.Price;
             updateProduct.Count      = product.Count;
         }
         dbContext.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 2
0
        public virtual void AddUpdateElastic(IEnumerable<TElastic> listElastic)
        {
            using (var context = new ElasticContext(ElasticConnectionString, Config))
            {
                if (!EnvironmentHelper.IsProduction())
                {
                    context.TraceProvider = new ConsoleTraceProvider();
                }

                foreach (var elastic in listElastic)
                    context.AddUpdateDocument(elastic, elastic.Id);

                context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public virtual void DeleteElastic(IEnumerable<int> listElasticId)
        {
            using (var context = new ElasticContext(ElasticConnectionString, Config))
            {
                if (!EnvironmentHelper.IsProduction())
                {
                    context.TraceProvider = new ConsoleTraceProvider();
                }

                foreach (var elasticId in listElasticId)
                {
                    context.DeleteDocument<TElastic>(elasticId);
                }

                context.SaveChanges();
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.WriteLine("1. Zobacz wszystkie zapytania");
                Console.WriteLine("2. Dodaj nowe zapytanie");
                Console.WriteLine("3. Wykonaj testowo zapytanie");
                int choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    using (var ctx = new ElasticContext())
                    {
                        foreach (var item in ctx.Queries.ToList())
                        {
                            Console.WriteLine(item.Query);
                        }
                    }
                    break;

                case 2:
                    int    minutePeriod;
                    string Query, IndexName;
                    bool   Active;
                    Console.WriteLine("Podaj nazwe indeksu pod jakim będzie zapisywane zapytanie\n");
                    IndexName = Console.ReadLine().ToLower();
                    Console.WriteLine("Podaj tresc zapytania ktore zrobi tabele cache - select ID,X,Y into ElasticCache.elastic_cache from X\n");
                    Query = Console.ReadLine();
                    Console.WriteLine("Czy na starcie zapytanie ma byc aktywne? 0/1");
                    int z = int.Parse(Console.ReadLine());
                    if (z == 1)
                    {
                        Active = true;
                    }
                    else
                    {
                        Active = false;
                    }
                    Console.WriteLine("Podaj czas w minutach (bez liter) co ile zapytanie ma sie wykonywac");
                    minutePeriod = int.Parse(Console.ReadLine());
                    using (var ctx = new ElasticContext())
                    {
                        ctx.Queries.Add(new Queries()
                        {
                            Active       = Active ? (byte)0x1 : (byte)0x0,
                            Query        = Query,
                            IndexName    = IndexName,
                            MinutePeriod = minutePeriod
                        });
                        ctx.SaveChanges();
                    }
                    break;

                case 3:
                    using (var ctx = new ElasticContext())
                    {
                        int index = 0;
                        foreach (var item in ctx.Queries.ToList())
                        {
                            Console.WriteLine(index + " -> " + item.IndexName);
                            index++;
                        }
                        int w     = int.Parse(Console.ReadLine());
                        var query = ctx.Queries.ToList().ElementAt(w);
                        ElasticController.Instance.StartImportToElastic(query.IndexName, query.Query);
                    }
                    break;
                }
                Console.ReadKey();
                Console.Clear();
            }
        }