Esempio n. 1
0
        /// <summary>
        /// 追踪失物招领启示
        /// </summary>
        /// <param name="sender">点击按钮对象</param>
        /// <param name="e">事件参数</param>
        protected void TraceBtn_Click(object sender, EventArgs e)
        {
            if (!IsSignIn()) // 判断用户是否登录
            {
                Response.Redirect("layout/SignIn.aspx");
                return;
            }

            bool   isTraced = false;
            Button btn      = (Button)sender;

            if (!isTraced)
            {
                Int64 noticeId = !String.IsNullOrEmpty(btn.Attributes["data-notice-id"]) ? Int64.Parse(btn.Attributes["data-notice-id"]) : 0;

                if (noticeId == 0)
                {
                    return;
                }

                User user = (User)Session["User"];

                NoticeTrace trace = new NoticeTrace()
                {
                    NoticeId  = noticeId,
                    UserId    = user.Id,
                    TraceDate = DateTime.Now.ToLocalTime()
                };

                bool isOk = NoticeTraceService.AddNoticeTrace(trace);

                if (isOk)
                {
                    Int64 traceCount = NoticeService.GetFieldValue <Int64>(noticeId, "trace_count");

                    btn.Text = String.Format("追踪 · {0}", traceCount);
                }
            }
            else
            {
                // TODO: 取消追踪
            }
        }