public IHttpActionResult AddSubComment(AddSubCommentDTO comment) { int CurrenUser = 0; using (var db = new UserDAL()) { CurrenUser = db.GetUserByUserNameOrEmail(User.Identity.Name).UserID; } var newSubComment = new SubCommentThread { UserId = CurrenUser, CommentThreadId = comment.CommentThreadId, Content = comment.CommentContent, Status = true, CommentDate = DateTime.Now }; using (var db = new ThreadDAL()) { try { newSubComment = db.AddNewSubComment(newSubComment); return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR })); } } }
public ActionResult CreateDiscussion(CreateThreadInfo thread, IEnumerable <HttpPostedFileBase> Images) { WingS.Models.Thread newThread = null; //Add thread to DB using (var db = new ThreadDAL()) { newThread = db.AddNewThread(thread, User.Identity.Name); } //Add Imgaes of Discussion to server try { foreach (HttpPostedFileBase img in Images) { //rebuild imgae name string imageName = WsConstant.randomString() + Path.GetExtension(img.FileName).ToLower(); string path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Content/Upload"), imageName); img.SaveAs(path); string imgaeUrl = "/Content/Upload/" + imageName; //Add Image to db. using (var db = new AlbumImageDAL()) { db.AddNewAlbum(new ThreadAlbumImageDTO(newThread.ThreadId, imgaeUrl)); } } } catch (Exception) { return(Redirect("/#/Error")); } return(Redirect("/#/ThreadDetail/" + newThread.ThreadId)); }
public IHttpActionResult GetThreadById(int id) { try { using (var db = new ThreadDAL()) { Thread current = db.GetThreadById(id); ThreadBasicInfo threadBasic = new ThreadBasicInfo(); threadBasic.ThreadID = current.ThreadId; threadBasic.UserID = current.UserId; threadBasic.ThreadName = current.Title; threadBasic.ImageUrl = db.GetAllImageThreadById(id); threadBasic.Content = current.Content; threadBasic.Status = current.Status; threadBasic.ShortDescription = current.ShortDescription; threadBasic.CreatedDate = current.CreatedDate.ToString("H:mm:ss MM/dd/yyyy"); return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = threadBasic })); } } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR })); } }
public IHttpActionResult GetThreadManageBasicInfor() { try { ThreadManageBasicInforDTO threadManageInfor = new ThreadManageBasicInforDTO(); using (var db = new ThreadDAL()) { threadManageInfor.NumberBanThread = db.CountThreadIsBan(); threadManageInfor.NumberNewThread = db.CountNewThread(); threadManageInfor.NumberTotalthread = db.CountTotalThread(); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "", Type = "", Data = threadManageInfor })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "", Type = "" })); } }
public IHttpActionResult GetCreatedThreadOfUser(string userName) { try { List <ThreadBasicInfo> userCreatedThread; int userId = 0; using (var db = new Ws_DataContext()) { userId = db.Ws_User.Where(x => x.UserName == userName).SingleOrDefault().UserID; } using (var db = new ThreadDAL()) { userCreatedThread = db.GetThreadsOfUser(userId); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "Get User Profile Successfully", Type = "", Data = userCreatedThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "Cannot Get User Donation Infomation!", Type = "" })); } }
public IHttpActionResult GetTopLikeThread() { try { var topLikeThread = new List <ThreadBasicInfo>(); using (var db = new ThreadDAL()) { topLikeThread = db.GetTopLikeNumberThread(5); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "", Type = "", Data = topLikeThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "", Type = "" })); } }
public IHttpActionResult GetThreadWithId(int threadId) { try { ThreadBasicInfo currentThread; using (var db = new ThreadDAL()) { currentThread = db.GetFullThreadBasicInformation(threadId); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "Get Thread with ID Successfully", Type = "", Data = currentThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "Cannot Get Thread with ID", Type = "" })); } }
public IHttpActionResult GetCreatedThreadOfUser(int userId) { try { List <ThreadBasicInfo> userCreatedThread; using (var db = new ThreadDAL()) { userCreatedThread = db.GetThreadsOfUser(userId); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "Get User Profile Successfully", Type = "", Data = userCreatedThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "Cannot Get User Donation Infomation!", Type = "" })); } }
public IHttpActionResult ChangeLikeState(int ThreadId) { using (var db = new ThreadDAL()) { var change = db.ChangelikeState(ThreadId, User.Identity.Name); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS })); }
public IHttpActionResult CountLikeInCommentThread(int CommentId) { int numberOfLikes = 0; using (var db = new ThreadDAL()) { numberOfLikes = db.CountLikeInCommentThread(CommentId); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = numberOfLikes })); }
public IHttpActionResult CheckCurrentUserIsLikedOrNot(int ThreadId) { bool isLiked = false; using (var db = new ThreadDAL()) { isLiked = db.CheckUserIsLikedOrNot(ThreadId, User.Identity.Name); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = isLiked })); }
protected void btnAdd_Click(object sender, EventArgs e) { User u = (User)Session["user"]; string msg = ThreadDAL.AddNewThread(u.Id, ddlSubjects.SelectedItem.Value, txtText.Text); if (msg == null) { lblMsg.Text = "Thread has been added sucessfully!"; } else { lblMsg.Text = "Sorry! Error -->" + msg; } }
protected void btnReply_Click(object sender, EventArgs e) { User u = (User)Session["user"]; string msg = ThreadDAL.AddReply(u.Id, Request.QueryString["tid"].ToString(), txtReply.Text); if (msg == null) { lblMsg.Text = "Reply has been added sucessfully!"; } else { lblMsg.Text = "Sorry! Error -->" + msg; } }
public IHttpActionResult DeleteSubComment(int subCommentId) { using (var db = new ThreadDAL()) { var result = db.DeleteSubComment(subCommentId, User.Identity.Name); return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Message = "", Type = "", Data = result })); } }
public ActionResult EditThread(CreateThreadInfo thread) { WingS.Models.Thread newThread = null; //Add thread to DB using (var db = new ThreadDAL()) { newThread = db.UpdateThread(thread, User.Identity.Name); } if (newThread != null) { return(Redirect("/#/ThreadDetail/" + newThread.ThreadId)); } else { return(Redirect("/#/Error")); } }
public IHttpActionResult CheckExistedSubCommentOrNot() { using (var db = new ThreadDAL()) { var commentList = db.GetAllCommentIdAndSubCommentId(); if (commentList == null || commentList.Count == 0) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.NOT_FOUND })); } else { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = commentList })); } } }
public IHttpActionResult GetAllComment(int threadId) { using (var db = new ThreadDAL()) { var commentList = db.GetAllCommentInThread(threadId, User.Identity.Name); if (commentList == null || commentList.Count == 0) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.NOT_FOUND })); } else { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = commentList })); } } }
public IHttpActionResult GetAllSubComment() { //Select All SubComment and return using (var db = new ThreadDAL()) { var SubcommentList = db.GetAllSubCommentInThread(); if (SubcommentList == null) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.NOT_FOUND })); } else { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = SubcommentList })); } } }
public IHttpActionResult GetTopThreadByCreatedDate() { List <Thread> topFourThread = null; var basicThreadList = new List <ThreadBasicInfo>(); try { using (var db = new ThreadDAL()) { topFourThread = db.GetTopThreadByCreatedDate(4); foreach (Thread thread in topFourThread) { int Like = db.CountLikeInThread(thread.ThreadId); int Comment = db.CountCommentInThread(thread.ThreadId); List <String> threadImage = db.GetAllImageThreadById(thread.ThreadId); basicThreadList.Add(new ThreadBasicInfo { ThreadID = thread.ThreadId, UserID = thread.UserId, ThreadName = thread.Title, ImageUrl = threadImage, Content = thread.Content, ShortDescription = thread.ShortDescription, Likes = Like, Comments = Comment, Status = true, CreatedDate = thread.CreatedDate.ToString("H:mm:ss dd/MM/yy"), }); } } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = basicThreadList })); } catch (Exception) { // ViewBag.ErrorMessage = ex; return(Redirect("/#/Error")); } }
protected void btnSearch_Click(object sender, EventArgs e) { string cond = " 1 = 1 "; if (txtText.Text.Length > 0) { cond += " and text like '%" + txtText.Text + "%'"; } if (txtFromDate.Text.Length > 0) { cond += " and dp >='" + txtFromDate.Text + "'"; } if (txtToDate.Text.Length > 0) { cond += " and dp <='" + txtToDate.Text + "'"; } DataSet ds = ThreadDAL.Search(cond); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); }
public IHttpActionResult ChangeStatusThread(int threadId) { try { bool statusThread; using (var threadDal = new ThreadDAL()) { var thread = threadDal.GetThreadById(threadId); thread.Status = !thread.Status; statusThread = thread.Status; threadDal.UpdateThread(thread); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = statusThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR })); } }
public IHttpActionResult GetNewestThread() { List <ThreadBasicInfo> listThread = new List <ThreadBasicInfo>(); try { using (var db = new ThreadDAL()) { listThread = db.GetNewestThreadByCreatedDate(); } return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.SUCCESS, Data = listThread })); } catch (Exception) { return(Ok(new HTTPMessageDTO { Status = WsConstant.HttpMessageType.ERROR, Message = "", Type = "" })); } }
//Returnerar alla trådobjekt (ThreadOnly) till specifik föreläsning. public IEnumerable <ThreadOnly> getThreadByID2(int LectureID) { return(ThreadDAL.getThreadByID2(LectureID)); }
//Startar ny diskussionstråd i förelsäning. Argument - Tråd-objket. public void StartThread(Thread Thread) { ThreadDAL.StartThread(Thread); }