Example #1
0
        public Response <User> Add(Request <User> request)
        {
            // 对密码进行 加密
            request.Obj.Password = QSecurity.DESEncrypt(request.Obj.Password, QConst.SECURITY_KEY);

            return(new Response <User>()
            {
                Data = ownDb.Add <User>(request.Obj),
                Times = request.BeginTime.Interval()
            });
        }
Example #2
0
        public Response <ViewModel.User> Login(Request <Parameter.User.Login> request, LoginLog log)
        {
            // 1. 验证数据有效性

            // 2.0 密码加密
            request.Obj.Password = QSecurity.DESEncrypt(request.Obj.Password, QConst.SECURITY_KEY);

            // 2.1 登录
            var user = GetUserByAccountAndPassword(new Request <Parameter.User.ByAccountAndPassword>()
            {
                Obj = new Parameter.User.ByAccountAndPassword()
                {
                    Account  = request.Obj.Account,
                    Password = request.Obj.Password
                }
            });

            var response = new Response <ViewModel.User>();

            if (user == null || user.Id == 0)
            {
                response.Status  = 1;
                response.Message = QConst.LOGIN_FAIL;
            }

            if (response.Status == 0)
            {
                try
                {
                    // 3. LoginLog 记录
                    db.Add <LoginLog>(new LoginLog()
                    {
                        LoginDate = DateTime.Now,
                        UserId    = user.Id,
                        UserName  = user.UserName,
                        HostIP    = log.HostIP,
                        HostName  = log.HostName,
                        LoginMsg  = log.LoginMsg
                    });

                    db.SaveChange();
                }
                catch (Exception ex)
                {
                    response.Status  = 1;
                    response.Message = ex.Message;
                }
            }

            response.Data  = user;
            response.Times = request.BeginTime.Interval();

            return(response);
        }
Example #3
0
        static void Main(string[] args)
        {
            #region 异步
            {
                var num1  = 0.0;
                var num2  = 0.0;
                var begin = DateTime.Now;

                Action action = (() =>
                {
                    Console.WriteLine("begin action async . ");
                    begin = DateTime.Now;
                    for (int i = 0; i < 1000000; i++)
                    {
                        num1 = num1 / num2;
                    }

                    Console.WriteLine("end action async . " + begin.Interval());
                });

                Func <double> func = (() =>
                {
                    Console.WriteLine("begin func async . ");
                    begin = DateTime.Now;

                    for (int i = 0; i < 100000000; i++)
                    {
                        num1 = num1 / num2;
                    }

                    Console.WriteLine("end func async . " + begin.Interval());

                    return(num1);
                });

                action.RunAsync(() =>
                {
                    Console.WriteLine("begin callback . ");
                });

                func.RunAsync((rs) =>
                {
                    Console.WriteLine("Result: " + rs);
                });

                Console.WriteLine("begin sync . ");
            }
            #endregion

            #region 加密 解密
            {
                Guid guid = Guid.NewGuid();

                Console.WriteLine(guid.ToString());

                var s = guid.ToString();
                Console.WriteLine(s.Substring(26, 8));
                var encypt = QSecurity.DESEncrypt("Qz110", "security");
                Console.WriteLine(encypt);
                // Console.WriteLine(s.Substring(26, 8));
                try
                {
                    Console.WriteLine("解密: " + QSecurity.DESDecrypt(encypt, "security"));
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("不正确的数据"))
                    {
                        Console.WriteLine("解密密钥错误 !");
                    }
                }
            }
            #endregion

            #region JSON
            {
                var dept = new Department()
                {
                    Code           = "1000",
                    CompanyId      = 100,
                    FullName       = "信息技术部",
                    ParentId       = 100,
                    CreateUserId   = 1,
                    CreateUserName = "******",
                    CreateDate     = DateTime.Now
                };

                var serialize = JsonConvert.Serialize(dept);

                var deserialize = JsonConvert.Deserialize <Department>(serialize);

                Console.WriteLine("\n====================");
                Console.WriteLine(serialize);

                Console.WriteLine("\n====================");
                Console.WriteLine(deserialize.CreateDate);
            }
            #endregion

            Console.Read();
        }