public bool UpdateAdmin(mAdmin.Admin admin) { try { using (EFContext context = new EFContext()) { context.Entry(admin).State = EntityState.Modified; // 修改State为Modified等同于Attach return(context.SaveChanges() > 0 ? true : false); } } catch (Exception ex) { LogHelper.Error(ex); return(false); } }
public static void SetCurrentAdmin(mAdmin.Admin admin, bool remember) { try { string jsonStr = JsonConvert.SerializeObject(admin); HttpContext.Current.Session[SESSION_ADMIN] = jsonStr; if (remember) { //jsonStr = HttpContext.Current.Server.UrlEncode(jsonStr); jsonStr = System.Web.HttpUtility.UrlEncode(jsonStr, Encoding.UTF8); // TODO jsonstr需要加密 var cookieAdmin = new HttpCookie(COOKIE_ADMIN, jsonStr); cookieAdmin.Expires = DateTime.Now.AddMonths(1); HttpContext.Current.Response.Cookies.Add(cookieAdmin); } } catch (Exception ex) { LogHelper.Error(ex); } }