Beispiel #1
0
        public async Task <bool> ChangePassword(UserModel user)
        {
            using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString()))
            {
                var param = new DynamicParameters();
                param.Add("@Id", user.Id);
                param.Add("@Password", EncryptionData.EncryptData(user.Password));
                var result = await connection.ExecuteAsync("spUser_ChangePassword", param, commandType : CommandType.StoredProcedure);

                return(result > 0);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Insert the license into the database
        /// </summary>
        /// <param name="license"></param>
        /// <returns></returns>
        public async Task <LicenseModel> InsertLicense(LicenseModel license)
        {
            string path = keySettings + "reg.csv";
            var    data = await ReadLicense();

            if (data != null)
            {
                //Try to insert the applied license
                if (await ConfirmLicense(license))
                {
                    //Insert the license key
                    //Insert license for the user. at programming level
                    using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString()))
                    {
                        license.Licensed   = true;
                        license.AppliedKey = license.LicenseKey;

                        var param = new DynamicParameters();
                        param.Add("@Licensed", license.Licensed);
                        param.Add("@AppliedKey", EncryptionData.EncryptData(license.AppliedKey));
                        var result = await connection.ExecuteAsync("spLicense_Update", param, commandType : CommandType.StoredProcedure);

                        CreateDirectory();
                        File.WriteAllText(path, false.ToString());
                        return(license);
                    }
                }
                else
                {
                    throw new Exception("Invalid Licensed Key. Please Insert the Right Key");
                }
            }
            else
            {
                //Insert license for the user. at programming level
                using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString()))
                {
                    license.Licensed = false;
                    var param = new DynamicParameters();
                    param.Add("@LicenseKey", EncryptionData.EncryptData(license.LicenseKey));
                    param.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
                    var result = await connection.ExecuteAsync("spLicense_InsertFirstUse", param, commandType : CommandType.StoredProcedure);

                    license.Id = param.Get <int>("@Id");
                    return(license);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update a user in the database
        /// </summary>
        /// <param name="user">The user you want to update</param>

        public async Task <bool> UpdateUser(UserModel user)
        {
            using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString()))
            {
                var param = new DynamicParameters();
                param.Add("@Name", user.Name);
                param.Add("@Password", EncryptionData.EncryptData(user.Password));
                param.Add("@Question", user.Question);
                param.Add("@Answer", EncryptionData.EncryptData(user.Answer));
                param.Add("@AccessType", user.AccessType);
                param.Add("@Id", user.Id);

                var result = await connection.ExecuteAsync("spUsers_Update", param, commandType : CommandType.StoredProcedure);

                return(result > 0);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Creates a new user
        /// </summary>
        /// <param name="user">The user you want to create</param>
        /// <returns>The newly created user.</returns>
        public async Task <UserModel> CreateUser(UserModel user)
        {
            using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnString()))
            {
                var param = new DynamicParameters();
                param.Add("@Name", user.Name);
                param.Add("@FullName", user.FullName);
                param.Add("@Password", EncryptionData.EncryptData(user.Password));
                param.Add("@Question", user.Question);
                param.Add("@Answer", EncryptionData.EncryptData(user.Answer));
                param.Add("@AccessType", user.AccessType);
                param.Add("@Id", 0, DbType.Int32, ParameterDirection.Output);

                await connection.ExecuteAsync("spUsers_Insert", param, commandType : CommandType.StoredProcedure);

                user.Id = param.Get <int>("@Id");
                return(user);
            }
        }