public JsonResult Like(int id, string value)
        {
            bool success = false;
            Like like = new Like();
            Article article = new Article();
            ArticleRepository articleRepository = new ArticleRepository();
            LikeRepository likeRepository = new LikeRepository();
            article = articleRepository.GetById(id);
            List<Like> likeList = new List<Like>();
            string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
            int start = type.LastIndexOf(".") + 1;
            int positions = type.Length - start;
            type = type.Substring(start, positions);
            if (value == "Like")
            {
                like.ArticleID = id;
                like.UserID = AuthenticationManager.LoggedUser.Id;

                like.UserType = type;
                likeRepository.Save(like);
                success = true;
            }
            if (value == "UnLike")
            {
                like = likeRepository.GetAll(filter: l => l.ArticleID == id && l.UserID == AuthenticationManager.LoggedUser.Id && l.UserType == type).FirstOrDefault();
                likeRepository.Delete(like);
                success = true;
            }
            return Json(success, JsonRequestBehavior.AllowGet);
        }
 public ActionResult EditArticle(ArticleControllerArticlesVM model)
 {
     TryUpdateModel(model);
     if (model.SubjectID < 1 || !ModelState.IsValid)
     {
         model.ArticleId = 0;
         List<CourseSubject> courseSubject = new List<CourseSubject>();
         Teacher teacher = new Teacher();
         TeacherRepository teacherRepository = new TeacherRepository();
         teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
         courseSubject = teacher.CourseSubject.ToList();
         List<SelectListItem> listSubjects = new List<SelectListItem>();
         listSubjects.Add(new SelectListItem() { Text = "Select subject", Value = "" });
         foreach (var item in courseSubject)
         {
             if (item.Subject.Id != model.ArticleId)
             {
                 listSubjects.Add(new SelectListItem() { Text = item.Subject.Name, Value = item.Subject.Id.ToString() });
             }
         }
         model.SubjectsListItems = listSubjects;
     }
     if (ModelState.IsValid)
     {
         Article article = new Article();
         ArticleRepository articleRepository = new ArticleRepository();
         Subject subject = new Subject();
         SubjectRepository subjectRepository = new SubjectRepository();
         Teacher teacher = new Teacher();
         TeacherRepository teacherRepository = new TeacherRepository();
         teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
         if (model.ArticleId > 0)
         {
             article = articleRepository.GetById(model.ArticleId);
             article.Content = model.Content;
             article.DateCreated = model.DateCreated;
             article.DateModified = DateTime.Now;
             article.SubjectID = model.SubjectID;
             article.TeacherID = teacher.Id;
             article.Title = model.Title;
         }
         else
         {
             article.Content = model.Content;
             article.DateCreated = DateTime.Now;
             article.SubjectID = model.SubjectID;
             article.TeacherID = teacher.Id;
             article.Title = model.Title;
         }
         articleRepository.Save(article);
         return RedirectToAction("Articles");
     }
     return View(model);
 }
 public ActionResult DeleteArticle(int id)
 {
     if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
     {
         Article article = new Article();
         ArticleRepository articleRepository = new ArticleRepository();
         article = articleRepository.GetById(id);
         articleRepository.Delete(article);
         return RedirectToAction("Articles");
     }
     return RedirectToAction("Articles");
 }
        public ActionResult EditArticle(int id)
        {
            if (AuthenticationManager.LoggedUser.GetType().BaseType.Equals(typeof(Teacher)))
            {
                ArticleControllerArticlesVM model = new ArticleControllerArticlesVM();
                TeacherRepository teacherRepository = new TeacherRepository();
                Article article = new Article();
                ArticleRepository articleRepository = new ArticleRepository();
                List<Subject> subjectList = new List<Subject>();
                SubjectRepository subjectRepository = new SubjectRepository();
                Teacher teacher = new Teacher();
                List<SelectListItem> listSubjects = new List<SelectListItem>();
                teacher = teacherRepository.GetById(AuthenticationManager.LoggedUser.Id);
                List<int> subjectId = new List<int>();
                foreach (var item in teacher.CourseSubject)
                {
                    subjectId.Add(item.Subject.Id);
                }
                subjectId = subjectId.Distinct().ToList();
                foreach (var item in subjectId)
                {
                    subjectList.Add(subjectRepository.GetById(item));
                }

                if (id > 0)
                {
                    article = articleRepository.GetById(id);
                    model.ArticleId = article.Id;
                    model.TeacherID = teacher.Id;
                    model.Title = article.Title;
                    model.Content = article.Content;
                    model.DateCreated = article.DateCreated;
                    model.DateModified = article.DateModified;
                    model.Subject = article.Subject;
                    model.Teacher = teacher;
                    listSubjects.Add(new SelectListItem() { Text = article.Subject.Name, Value = article.Subject.Id.ToString(), Selected = true });
                }
                if (id == 0)
                {
                    model.ArticleId = 0;
                    listSubjects.Add(new SelectListItem() { Text = "Select subject", Value = "" });
                }
                foreach (var item in subjectList)
                {
                    if (item.Id != model.ArticleId)
                    {
                        listSubjects.Add(new SelectListItem() { Text = item.Name, Value = item.Id.ToString() });
                    }
                }
                model.SubjectsListItems = listSubjects;
                return View(model);
            }
            return RedirectToAction("Articles");
        }
 public JsonResult Comment(int articleId, int commentId, string content)
 {
     ArticleRepository articleRepository = new ArticleRepository();
     CommentRepository commentRepository = new CommentRepository();
     Article article = new Article();
     Comment comment = new Comment();
     article = articleRepository.GetById(articleId);
     if (commentId == 0)
     {
         comment.ArticleID = articleId;
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         comment.UserID = AuthenticationManager.LoggedUser.Id;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     else
     {
         comment = commentRepository.GetById(commentId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     commentRepository.Save(comment);
     string comentator = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName;
     SelectListItem commentContent = new SelectListItem() { Text = comment.Content, Value = comentator };
     return Json(commentContent, JsonRequestBehavior.AllowGet);
 }