Пример #1
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult Editor(int id)
        {
            Sys_userEntity sys_userEntity = new Sys_userEntity();

            if (id > 0)
            {
                sys_userEntity = DalHelper.Instance.Get <Sys_userEntity>(id);
            }
            return(View(sys_userEntity));
        }
Пример #2
0
 public ActionResult Add(Sys_userEntity newsEntity)
 {
     if (ModelState.IsValid)
     {
         newsEntity.CreateDate = DateTime.Now;
         newsEntity.UpdateDate = DateTime.Now;
         bool editFlag = false;
         newsEntity.SetDefaultValue();
         editFlag = DalHelper.Instance.Insert <Sys_userEntity>(newsEntity) > 0;
     }
     return(View(newsEntity));
 }
Пример #3
0
        public ActionResult Del(long id)
        {
            bool   result  = false;
            string message = "删除失败!";

            if (id > 0)
            {
                Sys_userEntity sys_userEntity = new Sys_userEntity();
                sys_userEntity.SysUserID = id;
                result  = DalHelper.Instance.Delete <Sys_userEntity>(sys_userEntity);
                message = "删除成功!";
            }
            return(Json(new { result = result, message = message }, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        public ActionResult Login(LoginEntity loginer)
        {
            ModelState.Clear();

            if (string.IsNullOrEmpty(loginer.UserName) || string.IsNullOrEmpty(loginer.PassWord))
            {
                ModelState.AddModelError("Account", "请完善账户名和密码。");
                return(View());
            }
            SystemUser     sysUser       = new SystemUser();
            Sys_userEntity sysUserEntity = sysUser.GetLoginMember(loginer.UserName, loginer.PassWord);

            if (sysUserEntity != null)
            {
                string userData = loginer.UserName + "#" + loginer.PassWord;
                //数据放入ticket
                var ticket = new FormsAuthenticationTicket(1, loginer.UserName, DateTime.Now, DateTime.Now.AddMinutes(60), false, userData);
                //数据加密
                string     enyTicket = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, enyTicket)
                {
                    HttpOnly = true,
                    Secure   = FormsAuthentication.RequireSSL,
                    Domain   = FormsAuthentication.CookieDomain,
                    Path     = FormsAuthentication.FormsCookiePath
                };
                cookie.Expires = DateTime.Now.AddMinutes(4000);
                var context = System.Web.HttpContext.Current;
                if (context == null)
                {
                    throw new InvalidOperationException();
                }
                context.Response.Cookies.Remove(cookie.Name);
                context.Response.Cookies.Add(cookie);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("Account", "账户名和密码错误!");
                return(View());
            }
        }
Пример #5
0
        public ActionResult Editor(Sys_userEntity newsEntity)
        {
            newsEntity.CreateDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                bool editFlag = false;
                newsEntity.SetDefaultValue();
                if (newsEntity.SysUserID > 0)
                {
                    editFlag = DalHelper.Instance.Edit <Sys_userEntity>(newsEntity);
                }
                else
                {
                    editFlag = DalHelper.Instance.Insert <Sys_userEntity>(newsEntity) > 0;
                }
                //MessageShow();
            }
            return(View(newsEntity));
        }
Пример #6
0
        public Sys_userEntity GetLoginMember(string userName, string pwd)
        {
            Sys_userEntity member = new Sys_userEntity();

            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(pwd))
            {
                return(member);
            }

            member = DalHelper.Instance.GetSqlDefaultEntity <Sys_userEntity>(
                string.Format("{0} and @{1}={1} and @{2}={2}",
                              Sys_userEntity.Sql.SqlDetail,
                              Sys_userEntity.Fields.UserName,
                              Sys_userEntity.Fields.Password),
                new
            {
                UserName = userName,
                Password = pwd,
            });

            return(member ?? new Sys_userEntity());
        }