Exemple #1
0
 public bool Find()
 {
     if (KeyWords != null)
         KeyWords = KeyWords.ToLower();
     if (Title != null)
         Title = Title.ToLower();
     using (UnitOfWork unit = new UnitOfWork())
     {
         NewsRepository newsRep = new NewsRepository(unit.DataContext);
         Results = newsRep.GetAllNews().OrderBy(n => n.DatePublication);
         if (KeyWords != null)
         {
             String[] keys = KeyWords.Split(' ');
             List<News> temp = new List<News>();
             foreach(var k in keys)
             {
                 temp.AddRange(Results.Where(c => c.Content.ToLower().Contains(k)));
             }
             Results = temp;
         }
         if (Category != null && Category != String.Empty)
             Results = Results.Where(n => n.Category.Equals(Category));
         if (Title != null && Title != String.Empty)
             Results = Results.Where(n => n.Title.ToLower().Contains(Title));
         return Results.Count() > 0;
     }
 }
 public ActionResult SelectCategory(String category)
 {
     if (ModelState.IsValid && Request.IsAjaxRequest())
     {
         IEnumerable<News> news = null;
         using (UnitOfWork unit = new UnitOfWork())
         {
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             news = newsRep.GetAllNews().OrderBy(n => n.DatePublication).Reverse();
             if (category != "Все")
                 news = news.Where(n => n.Category.Equals(category)).OrderBy(n => n.DatePublication).Reverse();
         }
         return PartialView("_GridForNews", news);
     }
     return View("Index");
 }
 //
 // GET: /Home/
 public ActionResult Index()
 {
     IEnumerable<News> news = null;
     //IEnumerable<User> users = null;
     using (UnitOfWork unit = new UnitOfWork())
     {
         NewsRepository newsRep = new NewsRepository(unit.DataContext);
         news = newsRep.GetAllNews().OrderBy(n => n.DatePublication).Reverse();
     }
     return View(news);
 }