public async Task <IHttpActionResult> Modify([FromBody] PutData p)
        {
            var r  = new ResultBase();
            var md = p.md;
            var id = p.id;

            using (db0 = new Bpple_DBEntities())
            {
                try
                {
                    #region set value
                    db0.Entry(md).State = EntityState.Modified;
                    await db0.SaveChangesAsync();

                    #endregion
                    r.state = 0;
                }
                catch (Exception ex)
                {
                    r.state   = 999;
                    r.message = ex.Message;
                }
                return(Ok(r));
            }
        }
        public async Task <IHttpActionResult> Remove([FromBody] QItem p)
        {
            var r  = new ResultBase();
            var id = p.id;

            using (db0 = new Bpple_DBEntities())
            {
                try
                {
                    var md = await db0.Member.FindAsync(id);

                    var entry = db0.Entry <Member>(md);
                    entry.State = EntityState.Deleted;
                    await db0.SaveChangesAsync();

                    r.state = 0;
                }
                catch (Exception ex)
                {
                    r.state   = 999;
                    r.message = ex.Message;
                }
                return(Ok(r));
            }
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public async Task <IHttpActionResult> Post([FromBody] PostData p)
        {
            var r = new ResultInsert <int>();

            var md = p.md;
            var id = p.id;

            using (db0 = new Bpple_DBEntities())
            {
                try
                {
                    db0.Member.Add(md);
                    await db0.SaveChangesAsync();

                    r.state = 0;
                    r.id    = md.id;
                }
                catch (Exception ex)
                {
                    r.state   = 999;
                    r.message = ex.Message;
                }
                return(Ok(r));
            }
        }
        public async Task <string> loginCheck(LoginViewModel model)
        {
            LoginResult r = new LoginResult();

            if (!ModelState.IsValid)
            {
                r.message = ModelStateErrorPack();
                r.state   = 3; //填寫不完整
                return(defJSON(r));
            }
            if (string.IsNullOrEmpty((Session[WebSetup.CheckCodeSession] ?? "").ToString()))
            {
                r.state = 1;
                Session[WebSetup.CheckCodeSession] = Guid.NewGuid();
                r.message = "驗證碼不正確";

                return(defJSON(r));
            }
            r.vildate = Session[WebSetup.CheckCodeSession].Equals(model.validate) ? true : false;
            if (!r.vildate)
            {
                Session[WebSetup.CheckCodeSession] = Guid.NewGuid(); //只要有錯先隨意產生唯一碼 以防暴力破解,新的CheckCode會在Validate產生。
                r.state   = 1;                                       //驗證碼不正確
                r.message = "驗證碼不正確";
                return(defJSON(r));
            }
            #region 帳密碼檢查
            using (var db0 = new Bpple_DBEntities())
            {
                try
                {
                    var account  = model.account.Trim();
                    var password = ProcCore.EncryptString.Cryp(model.password.Trim());
                    var get_user = await db0.TBLogin.Where(x => x.LoginId == account& x.Pwd == password).FirstOrDefaultAsync();

                    if (get_user == null)
                    {
                        //帳密碼錯誤
                        r.state   = 1;
                        r.message = "帳號或密碼錯誤,請重新輸入。";//帳號或密碼錯誤 請重新輸入
                        return(defJSON(r));
                    }
                    if (get_user.state == UserState.Stop) //帳號停權
                    {
                        r.state   = 2;                    //帳號停權
                        r.message = "此帳號已停權,無法登入!";
                        return(defJSON(r));
                    }
                    #region 後台登錄

                    string user_data = get_user.LoginType; //記錄登錄權限類型
                                                           //有效期限 三天
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, get_user.LoginId, DateTime.Now, DateTime.Now.AddDays(3),
                                                                                     false, user_data, FormsAuthentication.FormsCookiePath);
                    string encTicket = FormsAuthentication.Encrypt(ticket);
                    Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                    DateTime last_login_time = get_user.last_login ?? DateTime.Now;
                    get_user.last_login = DateTime.Now;
                    await db0.SaveChangesAsync();

                    //寫入所需的Cookie資訊
                    var cookie_loginid = new HttpCookie(WebSetup.Cookie_LoginId, get_user.LoginId.Trim());
                    cookie_loginid.HttpOnly = true;
                    Response.Cookies.Add(cookie_loginid);

                    var cookie_login_type = new HttpCookie(WebSetup.Cookie_RoleId, get_user.LoginType);
                    cookie_login_type.HttpOnly = true;
                    Response.Cookies.Add(cookie_login_type);

                    var cookie_login_name = new HttpCookie(WebSetup.Cookie_UserName, Server.UrlPathEncode(get_user.name));
                    cookie_login_name.HttpOnly = true;
                    Response.Cookies.Add(cookie_login_name);

                    #endregion


                    r.url   = Url.Content("~/Home/Member");
                    r.state = 0;
                    return(defJSON(r));
                }
                catch (Exception ex)
                {
                    r.message = ex.Message;
                    r.state   = 99;
                    return(defJSON(r));
                }
            }
            #endregion
        }