Example #1
0
 public ActionResult AddComment(NewsAndComments comments)
 {
     if (Session["LoginUserID"] != null)
     {
         using (UnitOfWork unit = new UnitOfWork())
         {
             UserRepository userRep = new UserRepository(unit.DataContext);
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             CommentRepository comRep = new CommentRepository(unit.DataContext);
             //News news = newsRep.GetNewsById(id);
             User user = userRep.GetUserById(new Guid((Session["LoginUserID"]).ToString()));
             CommentService comServ = new CommentService(unit.DataContext);
             comments.News = newsRep.GetNewsById(new Guid((Session["NewsId"]).ToString()));
             //comments.News.Comments = comRep.GetCommentsByPublicationId(new Guid((Session["NewsId"]).ToString())).ToList();
             //comments.News.Owner = user;
             comServ.Create(user, comments.News, comments.CurrentComment);
             unit.Commit();
             comments.Comments = newsRep.GetNewsById(comments.News.NewsId).Comments;
         }
     }
     if (Request.IsAjaxRequest())
     {
         return PartialView("_GridForComments", comments);
     }
     return RedirectToAction("ReadMore/" + comments.News.NewsId.ToString());
 }
Example #2
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;
     }
 }
Example #3
0
 public void Delete(Guid id)
 {
     NewsRepository rep = new NewsRepository(_database);
     News news = rep.GetNewsById(id);
     CommentRepository comRep = new CommentRepository(_database);
     if (news == null)
         throw new ArgumentException(ERROR_DELETE_NEWS);
     IEnumerable<Comment> comments = comRep.GetCommentsByPublicationId(id);
     if (comments != null)
         foreach (var comment in comments)
             _database.Comments.Remove(comment);
     _database.News.Remove(news);
 }
Example #4
0
 public ActionResult Delete(Guid id)
 {
     if (Session["LoginUserID"] != null)
     {
         using (UnitOfWork unit = new UnitOfWork())
         {
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             User user = newsRep.GetNewsById(id).Owner;
             if (UserValidator.IsValid(Session["LoginUserID"].ToString(), user))
             {
                 NewsService newsServ = new NewsService(unit.DataContext);
                 newsServ.Delete(id);
                 unit.Commit();
             }
         }
     }
     return RedirectToAction("Index");
 }
Example #5
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");
 }
Example #6
0
        public ActionResult ReadMore(Guid id)
        {
            NewsAndComments newsAndComms = new NewsAndComments();
            IEnumerable<Comment> comments = null;
            using (UnitOfWork unit = new UnitOfWork())
            {
                NewsRepository newsRep = new NewsRepository(unit.DataContext);
                News news = newsRep.GetNewsById(id);
                CommentRepository comRep = new CommentRepository(unit.DataContext);
                comments = comRep.GetCommentsByPublicationId(id);
                newsAndComms.News = news;
                newsAndComms.Comments = comments;
                Session["NewsId"] = news.NewsId;
            }

            return View(newsAndComms);
        }
Example #7
0
 //
 // 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);
 }
Example #8
0
 public ActionResult Edit(News news, HttpPostedFileBase upload)
 {
     if (ModelState.IsValid && Session["LoginUserID"] != null)
     {
         byte[] file = null;
         if (upload != null)
             file = ConverterFileToBytes.Convert(upload);
         using (UnitOfWork unit = new UnitOfWork())
         {
             NewsService newsServ = new NewsService(unit.DataContext);
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             UserRepository userRep = new UserRepository(unit.DataContext);
             CommentRepository comRep = new CommentRepository(unit.DataContext);
             news.NewsId = new Guid(Session["NewsId"].ToString());
             news.Image = file;
             news.DatePublication = newsRep.GetNewsById(news.NewsId).DatePublication;
             news.Owner = userRep.GetUserById(new Guid(Session["LoginUserID"].ToString()));
             news.Comments = comRep.GetCommentsByPublicationId(new Guid(Session["LoginUserID"].ToString())).ToList();
             newsServ.Edit(news);
             unit.Commit();
         }
         return RedirectToAction("Index");
     }
     return HttpNotFound();
 }
Example #9
0
 public ActionResult Edit(Guid id)
 {
     if (Session["LoginUserID"] != null)
     {
         News news;
         using (UnitOfWork unit = new UnitOfWork())
         {
             NewsRepository newsRep = new NewsRepository(unit.DataContext);
             news = newsRep.GetNewsById(id);
             if (UserValidator.IsValid(Session["LoginUserID"].ToString(), news.Owner))
             {
                 Session["NewsId"] = id;
                 return View(news);
             }
         }
     }
     return HttpNotFound();
 }