コード例 #1
0
        public User LoginUser(LoginUser login)
        {
            string     query = @"select * from Users where Email=@Email and Password=@Password";
            SqlCommand cmd   = new SqlCommand(query, connection);

            foreach (var p in login.GetType().GetProperties())
            {
                var pName = "@" + p.Name;
                var value = p.GetValue(login);
                cmd.Parameters.AddWithValue(pName, value);
            }

            var rdr = cmd.ExecuteReader();

            if (rdr.Read())
            {
                User result = new User();
                foreach (var p in result.GetType().GetProperties())
                {
                    var value = rdr[p.Name];
                    p.SetValue(result, value);
                }

                return(result);
            }
            else
            {
                throw new Exception("user not found.");
            }
        }
コード例 #2
0
ファイル: Validate.cs プロジェクト: tdu819/District.net.core
        public Result LoginUser(LoginUser login)
        {
            if (login == null)
            {
                return(Result.Fail());
            }

            System.Reflection.PropertyInfo[] properties =
                login.GetType().GetProperties();

            foreach (var prop in properties)
            {
                object value = prop.GetValue(login);

                if (value == null || value.ToString()?.Length < 2)
                {
                    return(Result.Fail());
                }
            }

            return(Email(login.Login));
        }