Ejemplo n.º 1
0
        public JsonResult GetEmployeeByEmployeeNumber(string employeeNumber, string password)
        {
            Employee   obj    = null;
            JsonResult result = new JsonResult();
            string     msg    = "";
            int        code   = 0;

            try
            {
                obj = employeeService.GetEmployeeByEmployeeNumber(employeeNumber);
                if (obj == null || string.IsNullOrEmpty(obj.EmployeeNumber))
                {
                    msg  = "用户编号不存在";
                    code = 1;
                }
                else if (!MD5.VerifyMd5Hash(password, obj.Password))
                {
                    msg  = "密码不正确";
                    code = 2;
                }
                else
                {
                    Session.Add("user", obj);

                    JsonCache.SetCache("employee", obj, System.DateTime.Now.AddMinutes(10), TimeSpan.Zero);
                    msg = "登录成功";
                }
                log.Info(msg);
            }
            catch (Exception e)
            {
                log.Error(e.Message);
            }
            finally
            {
                //result = Json(new { code = code, msg = msg,  data = obj }, JsonRequestBehavior.AllowGet);
                result = Json(new{ Code = code, Msg = msg, Data = obj, SessionID = Session.SessionID }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }