Esempio n. 1
0
        public ActionResult <Response> Login([FromBody] User loginUser)
        {
            using (var context = new MainContext())
            {
                var sqlData  = new SqlUserData(context);
                var user     = sqlData.GetByPhone(loginUser.Phone);
                var response = new Response();
                if (user.Password == loginUser.Password)
                {
                    var sessionData = new SqlSessionData(context);
                    var session     = new Session {
                        User = user
                    };
                    sessionData.Add(session);
                    response.Success = true;
                    response.Message = "登录成功!";
                    response.Data    = new { Session = session, User = user };
                }
                else
                {
                    response.Success = false;
                    response.Message = "登录失败,手机号或者密码错误";
                }

                return(response);
            }
        }
Esempio n. 2
0
        public ActionResult <Response> Get()
        {
            var model = new UserViewModel();

            using (var context = new MainContext())
            {
                var sqlData = new SqlUserData(context);
                model.Users = sqlData.GetAll();
            }

            return(new Response(true, "获取所有用户信息", new { Users = model.Users }));
        }
Esempio n. 3
0
        public ActionResult <Response> SignUp([FromBody] User user)
        {
            if (user == null)
            {
                return new Response {
                           Message = "没有提供数据啊!", Success = false
                }
            }
            ;
            using (var context = new MainContext())
            {
                var sqlData = new SqlUserData(context);

                var result      = sqlData.Add(user);
                var sessionData = new SqlSessionData(context);
                var session     = new Session {
                    User = user
                };
                sessionData.Add(session);
                var data = new { User = user, Session = session };
                return(new Response(true, result ? "注册成功" : "注册失败", data));
            }
        }