Example #1
0
 public void Delete(Guid id)
 {
     CommentRepository rep = new CommentRepository(_database);
     Comment comment = rep.GetCommentById(id);
     if (comment == null)
         throw new ArgumentException(ERROR_DELETE_COMMENT);
     _database.Comments.Remove(comment);
 }
Example #2
0
        public ActionResult DeleteComm(Guid id)
        {
            if (Session["LoginUserID"] != null)
            {
                using (UnitOfWork unit = new UnitOfWork())
                {
                    CommentRepository comRep = new CommentRepository(unit.DataContext);
                    CommentService comServ = new CommentService(unit.DataContext);
                    NewsAndComments newsAndComments = new NewsAndComments();
                    Guid newsId = new Guid(comRep.GetCommentById(id).Publication.NewsId.ToString());
                    newsAndComments.News = comRep.GetCommentById(id).Publication;

                    if (UserValidator.IsValid(Session["LoginUserID"].ToString(), comRep.GetCommentById(id).Publication.Owner))
                    {
                        comServ.Delete(id);
                        unit.Commit();
                    }

                    newsAndComments.Comments = comRep.GetCommentsByPublicationId(newsId);

                    if (Request.IsAjaxRequest())
                    {
                        return PartialView("_GridForComments", newsAndComments);
                    }
                    else
                    {
                        return View("ReadMore", newsAndComments);
                    }
                }
            }
            return HttpNotFound();
        }