Exemplo n.º 1
0
        /// <summary>
        /// 回覆取得
        /// </summary>
        /// <returns></returns>

        public ActionResult ReplyIndex(int?messagesId)
        {
            Library.MessageReply model = messageWeb.GetMessageReplys().ToList()
                                         .Find(x => x.Messages.Id == messagesId);
            string UserAccount = "";
            string UserName    = "";

            if (messagesId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            if (SessionManagement.LoginUser != null)
            {
                UserAccount         = SessionManagement.LoginUser.UserAccount;
                ViewBag.UserAccount = UserAccount;
                UserName            = SessionManagement.LoginUser.UserName;
                ViewBag.UserName    = UserName;
            }
            if (SessionManagement.LoginUser.UserClass != 2)
            {
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 取得留言回覆
        /// </summary>
        /// <returns></returns>
        public IEnumerable <MessageReply> GetMessageReplys()
        {
            List <MessageReply> result = new List <MessageReply>();

            using (SqlConnection con = new SqlConnection(DBConnection.ConnectString))
            {
                SqlCommand cmd = new SqlCommand(SPName.MessageReply.MessageRely_Get, con);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                SqlDataReader dr        = cmd.ExecuteReader();
                int           currentID = 0;
                MessageReply  item      = null;
                while (dr.Read())
                {
                    if (currentID == 0 || int.Parse(dr["Message_Id"].ToString()) != currentID)
                    {
                        Message msg = new Message()
                        {
                            Id        = Convert.ToInt32(dr["Message_Id"]),
                            UserId    = Convert.ToInt32(dr["Message_UserId"]),
                            UserName  = dr["Message_UserName"].ToString(),
                            Context   = dr["Message_Context"].ToString(),
                            CreatDate = Convert.ToDateTime(dr["Message_CreatDate"].ToString())
                        };
                        item           = new MessageReply();
                        item.Messages  = msg;
                        item.ReplyList = new List <Reply>();
                        if (dr["Reply_Id"] != DBNull.Value)
                        {
                            Reply reply = new Reply()
                            {
                                Id        = Convert.ToInt32(dr["Reply_Id"]),
                                UserName  = dr["Reply_UserName"].ToString(),
                                Context   = dr["Reply_Context"].ToString(),
                                CreatDate = Convert.ToDateTime(dr["Reply_CreatDate"].ToString())
                            };
                            item.ReplyList.Add(reply);
                        }

                        result.Add(item);
                        currentID = msg.Id;
                    }
                    else
                    {
                        item.ReplyList.Add(new Reply
                        {
                            Id        = Convert.ToInt32(dr["Reply_Id"]),
                            UserName  = dr["Reply_UserName"].ToString(),
                            Context   = dr["Reply_Context"].ToString(),
                            CreatDate = Convert.ToDateTime(dr["Reply_CreatDate"].ToString())
                        });
                    }
                }
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Session登入取得資料
        /// </summary>
        /// <returns></returns>
        //public string SessionGet()
        //{
        //    string UserAccount = "";
        //    string UserName = "";
        //    int Id = 0;
        //    byte UserClass = 0;
        //    if (Session["UserAccount"] != null)
        //    {
        //        UserAccount = Session["UserAccount"].ToString();
        //        ViewBag.UserAccount = UserAccount;
        //        UserName = Session["UserName"].ToString();
        //        ViewBag.UserName = UserName;
        //        int.TryParse(Session["Id"].ToString(), out Id);
        //        ViewBag.Id = Id;
        //        byte.TryParse(Session["UserClass"].ToString(), out UserClass);
        //        ViewBag.UserClass = UserClass;
        //    }
        //    return ();
        //}

        #endregion

        #region 回覆取得
        /// <summary>
        /// 回覆取得
        /// </summary>
        /// <returns></returns>
        public ActionResult ReplyIndex(int messagesId)
        {
            //List<MessageReply> model = messageWeb.GetMessageReplys().ToList();
            //Library.MessageReply model = messageWeb.GetMessageReplys().ToList()
            //    .Find(x => x.Messages.Id == messagesId);
            Library.MessageReply model = messageWeb.GetMessageReplys().ToList()
                                         .Find(x => x.Messages.Id == messagesId);

            return(View(model));
        }