コード例 #1
0
        public ContentResult DestroyCard()
        {
            Response.ContentType = "application/json";
            ResultInfo <Card> result;

            try
            {
                if (Request.Cookies["CardId"] == null)
                {
                    throw new Exception("没有公交卡可供销毁");
                }

                HttpCookie cookie = new HttpCookie("CardId")
                {
                    Expires = DateTime.Now.AddDays(-2)
                };
                Response.Cookies.Add(cookie);

                CardOperation.DestroyCard(Request.Cookies["CardId"].Value);
                result = new ResultInfo <Card>(ResultInfoEnum.OK, "访问成功", Request.Url.ToString(), null);


                return(Content(JsonConvert.SerializeObject(result)));
            }
            catch (Exception e)
            {
                HttpCookie cookie = new HttpCookie("CardId")
                {
                    Expires = DateTime.Now.AddDays(-2)
                };
                Response.Cookies.Add(cookie);
                result = result = new ResultInfo <Card>(ResultInfoEnum.ERROR, e.Message, Request.Url.ToString(), null);
                return(Content(JsonConvert.SerializeObject(result)));
            }
        }