public ActionResult DeleteBlogPost(int postId) { var result = new ResultViewModel(); using (context = new ETutorEntities()) { var post = context.Post_tbl.Where(w => w.Id == postId).FirstOrDefault(); try { if (post != null) { post.IsActive = false; post.UpdateOn = DateTime.Now; } context.SaveChanges(); result.isSuccess = true; result.message = "Delete Success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } context.SaveChanges(); } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult EidtComment(CommentViewModel comment) { var result = new ResultViewModel(); using (context = new ETutorEntities()) { var postComment = context.PostComment_tbl.Where(w => w.Id == comment.commentId).FirstOrDefault(); try { if (postComment != null) { postComment.Comment = comment.text; postComment.UpdateOn = DateTime.Now; context.SaveChanges(); } result.isSuccess = true; result.message = "Update Success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult AddComment(CommentViewModel comment) { GetUser(); using (context = new ETutorEntities()) { try { var newcomment = new PostComment_tbl { PostId = comment.attachmentId, Comment = comment.text, IsActive = true, CreatedBy = user.userId, CreateOn = DateTime.Now, UpdateOn = DateTime.Now }; context.PostComment_tbl.Add(newcomment); context.SaveChanges(); comment.commentId = newcomment.Id; } catch (Exception) { } return(new JsonResult { Data = comment, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); } }
public ActionResult EditBlogPost(string Title, string BodyText, int Id) { var result = new ResultViewModel(); using (context = new ETutorEntities()) { var Post = context.Post_tbl.Where(w => w.Id == Id).FirstOrDefault(); try { if (Post != null) { Post.PostBody = BodyText; Post.PostTitle = Title; Post.UpdateOn = DateTime.Now; context.SaveChanges(); } result.isSuccess = true; result.message = "Update Success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult DeleteComment(string commentId) { var result = new ResultViewModel(); using (context = new ETutorEntities()) { var id = 0; if (int.TryParse(commentId, out id)) { var postcomment = context.PostComment_tbl.Where(w => w.Id == id).FirstOrDefault(); try { if (postcomment != null) { context.PostComment_tbl.Remove(postcomment); context.SaveChanges(); } result.isSuccess = true; result.message = "Delete Success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } context.SaveChanges(); } } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
public ActionResult SaveStudentTutor(StudentTutorViewModel studentTutor) { GetUser(); var result = new ResultViewModel(); using (context = new ETutorEntities()) { try { studentTutor.selectedStudents.ForEach(f => { var studenttutor = context.StudentTutor_tbl.Where(w => w.StudentId == f.id).FirstOrDefault(); if (studenttutor != null) { studenttutor.IsCurrent = false; studenttutor.UpdatedBy = user.userId; studenttutor.UpdateOn = DateTime.Now; } var StudentTutor = new StudentTutor_tbl { StudentId = f.id, TutorId = studentTutor.tutorId != null ? studentTutor.tutorId.id : null, CreatedBy = user.userId, CreateOn = DateTime.Now, UpdatedBy = user.userId, UpdateOn = DateTime.Now, IsCurrent = true }; context.StudentTutor_tbl.Add(StudentTutor); context.SaveChanges(); }); result.isSuccess = true; result.message = "Save success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet, MaxJsonLength = int.MaxValue }); }
public ActionResult CreateBlogPost(string Title, string BodyText) { GetUser(); var result = new ResultViewModel(); using (context = new ETutorEntities()) { try { var post = new Post_tbl { PostBody = BodyText, PostTitle = Title, CreatedBy = user.userId, CreateOn = DateTime.Now, UpdateOn = DateTime.Now, IsActive = true, }; context.Post_tbl.Add(post); context.SaveChanges(); result.isSuccess = true; result.message = "Save Success"; } catch (Exception e) { result.isSuccess = false; result.message = e.Message; } } return(new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }