Esempio n. 1
0
        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
                    }));
                }
            }
        }
Esempio n. 2
0
 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));
 }
Esempio n. 3
0
        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 = ""
                }));
            }
        }
Esempio n. 5
0
        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 = ""
                }));
            }
        }
Esempio n. 9
0
 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
     }));
 }
Esempio n. 10
0
        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
            }));
        }
Esempio n. 11
0
        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
            }));
        }
Esempio n. 12
0
    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;
        }
    }
Esempio n. 13
0
    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;
        }
    }
Esempio n. 14
0
 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
         }));
     }
 }
Esempio n. 15
0
 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"));
     }
 }
Esempio n. 16
0
 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
             }));
         }
     }
 }
Esempio n. 17
0
 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
             }));
         }
     }
 }
Esempio n. 18
0
 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
             }));
         }
     }
 }
Esempio n. 19
0
        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"));
            }
        }
Esempio n. 20
0
    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();
    }
Esempio n. 21
0
 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
         }));
     }
 }
Esempio n. 22
0
        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 = ""
                }));
            }
        }
Esempio n. 23
0
 //Returnerar alla trådobjekt (ThreadOnly) till specifik föreläsning.
 public IEnumerable <ThreadOnly> getThreadByID2(int LectureID)
 {
     return(ThreadDAL.getThreadByID2(LectureID));
 }
Esempio n. 24
0
 //Startar ny diskussionstråd i förelsäning. Argument - Tråd-objket.
 public void StartThread(Thread Thread)
 {
     ThreadDAL.StartThread(Thread);
 }