예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IMemoryCache cache)
        {
            BooksCache.Recuperar(cache);

            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
예제 #2
0
        // GET: Books
        public JsonResult Index(string d, string autor, string nome)
        {
            //Isso está aqui pois estou com preguiça de atualizar o código do request no angular =)
            string busca = d;

            if (_cache.TryGetValue(cacheKey, out List <LivroEntity> livroCollectionCache))
            {
                if (string.IsNullOrWhiteSpace(autor) == false && string.IsNullOrWhiteSpace(nome) == false)
                {
                    nome  = nome.ToUpper().RemoveDiacritics();
                    autor = autor.ToUpper().RemoveDiacritics();
                    var book =
                        livroCollectionCache.FirstOrDefault(
                            b =>
                            b.nomeNormalized.ToUpper() == nome &&
                            b.autorNormalized.ToUpper() == autor);
                    return(Json(book));
                }
                else
                {
                    busca = busca.ToUpper();
                    //var books =
                    //    livroCollectionCache.Where(
                    //        b =>
                    //                b.nomeNormalized.Contains(busca)
                    //                || b.autorNormalized.Contains(busca)
                    //        ).OrderByDescending(l => l.qtd).Take(5);
                    var books =
                        livroCollectionCache.Where(
                            b =>
                            b.search.Contains(busca.Split(' '))

                            ).OrderByDescending(l => l.qtd).Take(5);

                    return(Json(books));
                }
            }
            else
            {
                BooksCache.Recuperar(_cache);

                if (string.IsNullOrWhiteSpace(autor) == false && string.IsNullOrWhiteSpace(nome) == false)
                {
                    BooksDao booksDao      = new BooksDao();
                    var      bookColletion = booksDao.GetBook(autor, nome);
                    return(Json(bookColletion));
                }
                else
                {
                    BooksDao booksDao      = new BooksDao();
                    var      bookColletion = booksDao.GetBooks(busca);
                    return(Json(bookColletion));
                }
            }
        }