Beispiel #1
0
        private void ResetPassword()
        {
            if (ValidatePassword(tbNewPwd.Password, uvm.PasswordRules))
            {
                UserOrganizationDto dto = new UserOrganizationDto();
                dto.User = User.Instance.UserDto;
                //dto.Organization = new OrganizationDto() { Id = ApplicationViewModel.Instance.EwavSelectedDatasource.OrganizationId };
                PasswordHasher ph = new PasswordHasher(ApplicationViewModel.Instance.KeyForUserPasswordSalt);

                string salt = ph.CreateSalt(User.Instance.UserDto.Email);
                User.Instance.UserDto.PasswordHash = ph.HashPassword(salt, tbNewPwd.Password);
                User.Instance.UserDto.UserEditType = UserEditType.EditingPassword;
                uvm.UpdateUser(dto);
                uvm.UserUpdated += new EventHandler(uvm_UserUpdated);
                // this.DialogResult = true;
                spMsg_Success.Visibility = System.Windows.Visibility.Visible;
                spFormatError.Visibility = System.Windows.Visibility.Collapsed;
                grdPwd.Visibility        = System.Windows.Visibility.Collapsed;
            }
            else
            {
                spFormatError.Visibility = System.Windows.Visibility.Visible;
                spMsg.Visibility         = System.Windows.Visibility.Visible;

                tbErrorMsg.Text       = "Password must match the Password Policy. Please try again.";
                tbNewPwd.Password     = "";
                tbConfirmPwd.Password = "";
            }
        }
Beispiel #2
0
        /// <summary>
        /// Adds new org and Admin User object
        /// </summary>
        /// <param name="dto"></param>
        public int AddOrganization(UserOrganizationDto userOrganizationDto)
        {
            OrganizationDto organizationDto = userOrganizationDto.Organization;
            Cryptography    Cryptography    = new Security.Cryptography();
            UserDTO         userDto         = userOrganizationDto.User;

            if (userOrganizationDto.User == null)
            {
                throw new Exception("An organization cannot be added with zero users");
            }

            int         organizationID = -1;
            SqlDatabase db             = new SqlDatabase(ConnectionString);

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                SqlCommand command = connection.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "usp_add_organization";
                command.Parameters.Add(new SqlParameter("@OrganizationName", organizationDto.Name));
                command.Parameters.Add(new SqlParameter("@OrganizationDescription", ""));
                command.Parameters.Add(new SqlParameter("@OrganizationKey", Cryptography.Encrypt(Guid.NewGuid().ToString())));
                command.Parameters.Add(new SqlParameter("@UserId", userDto.UserID));
                command.Parameters.Add(new SqlParameter("@UserNm", userDto.UserName));
                command.Parameters.Add(new SqlParameter("@FirstNm", userDto.FirstName));
                command.Parameters.Add(new SqlParameter("@LastNm", userDto.LastName));
                command.Parameters.Add(new SqlParameter("@EmailAdd", userDto.Email));
                command.Parameters.Add(new SqlParameter("@PhoneNbr", userDto.Phone));
                command.Parameters.Add(new SqlParameter("@PwdHash", userDto.PasswordHash));
                command.Parameters.Add(new SqlParameter("@IsExistingUser", userDto.IsExistingUser));

                if (userDto.IsExistingUser)
                {
                    command.Parameters.Add(new SqlParameter("@ResetPwd", userDto.ShouldResetPassword));
                }
                else
                {
                    command.Parameters.Add(new SqlParameter("@ResetPwd", true));
                }


                command.Parameters.Add(new SqlParameter("@RoleId", userOrganizationDto.RoleId));
                command.Parameters.Add(new SqlParameter("@IsActive", userOrganizationDto.Active));

                try
                {
                    db.ExecuteNonQuery(command);
                    organizationID = 1000; //success
                }
                catch (Exception Ex)
                {
                    throw new Exception(Ex.Message);
                }
            }

            return(organizationID);
        }
Beispiel #3
0
        public void UpdateUser(UserOrganizationDto dto, Action <bool, Exception> completed)
        {
            _updateCompleted = completed;
            userCtx          = new UserDomainContext();

            InvokeOperation <bool> updateResults = userCtx.EditUser(dto);

            updateResults.Completed += new EventHandler(updateResults_Completed);
        }
Beispiel #4
0
        public void AddUser(UserOrganizationDto dto, Action <bool, Exception> completed)
        {
            _addCompleted = completed;
            userCtx       = new UserDomainContext();

            InvokeOperation <bool> addResults = userCtx.GenerateUser(dto);

            addResults.Completed += new EventHandler(addResults_Completed);
        }
Beispiel #5
0
        public void Add(UserOrganizationDto dto, Action <int, Exception> completed)
        {
            _addCompleted = completed;

            organizationCtx = new OrganizationDomainContext();

            InvokeOperation <int> addResults = organizationCtx.AddOrganization(dto);

            addResults.Completed += new EventHandler(addResults_Completed);
        }
Beispiel #6
0
        public bool UpdateUser(UserOrganizationDto dto)
        {
            UserDTO         User         = dto.User;
            OrganizationDto Organization = dto.Organization;

            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();
                MySqlCommand updUsercommand = connection.CreateCommand();

                if (User.UserEditType == UserEditType.EditingUserInfo)
                {
                    updUsercommand.CommandType = CommandType.StoredProcedure;
                    updUsercommand.CommandText = "usp_update_user";
                    updUsercommand.Parameters.Add("FirstName", User.FirstName);
                    updUsercommand.Parameters.Add("LastName", User.LastName);
                    updUsercommand.Parameters.Add("EmailAddressArg", User.Email);
                    updUsercommand.Parameters.Add("PhoneNumber", User.Phone);
                    updUsercommand.Parameters.Add("UserId", User.UserID);
                    updUsercommand.Parameters.Add("OrganizationId", dto.Organization.Id);
                    updUsercommand.Parameters.Add("IsUserOrgActive", dto.Active);
                    updUsercommand.Parameters.Add("RoleId", dto.RoleId);

                    string assocUsers       = "";
                    string assocDatasources = "";

                    foreach (DatasourceDto item in User.DatasourceList)
                    {
                        assocUsers       += string.Format("{0},", User.UserID.ToString());
                        assocDatasources += string.Format("{0},", item.DatasourceId.ToString());
                    }

                    updUsercommand.Parameters.Add("datasource_ids", assocDatasources);
                    updUsercommand.Parameters.Add("user_ids", assocUsers);
                }
                else
                {
                    updUsercommand.CommandType = CommandType.StoredProcedure;
                    updUsercommand.CommandText = "usp_update_password";
                    updUsercommand.Parameters.Add("UserId", User.UserID);
                    updUsercommand.Parameters.Add("HashedPassword", User.PasswordHash);
                }
                try
                {
                    updUsercommand.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }

                return(true);
            }
        }
Beispiel #7
0
        public bool UpdateUser(UserOrganizationDto dto)
        {
            SqlDatabase db = new SqlDatabase(ConnectionString);
            //SqlTransaction sqlTran = null;
            //int flag = -1;
            UserDTO         User         = dto.User;
            OrganizationDto Organization = dto.Organization;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                SqlCommand updUsercommand = connection.CreateCommand();

                if (User.UserEditType == UserEditType.EditingUserInfo)
                {
                    updUsercommand.CommandType = CommandType.StoredProcedure;
                    updUsercommand.CommandText = "usp_update_user";
                    updUsercommand.Parameters.Add("FirstName", User.FirstName);
                    updUsercommand.Parameters.Add("LastName", User.LastName);
                    updUsercommand.Parameters.Add("EmailAddress", User.Email);
                    updUsercommand.Parameters.Add("PhoneNumber", User.Phone);
                    updUsercommand.Parameters.Add("UserId", User.UserID);
                    updUsercommand.Parameters.Add("OrganizationId", dto.Organization.Id);
                    updUsercommand.Parameters.Add("IsUserOrgActive", dto.Active);
                    updUsercommand.Parameters.Add("RoleId", dto.RoleId);

                    updUsercommand.Parameters.Add("@DatasourceUser", SqlDbType.Structured);
                    updUsercommand.Parameters["@DatasourceUser"].Direction = ParameterDirection.Input;
                    updUsercommand.Parameters["@DatasourceUser"].TypeName  = "DatasourceUserTableType";

                    List <SqlDataRecord> sqlDrList = new List <SqlDataRecord>();

                    SqlDataRecord sqdr;



                    foreach (DatasourceDto item in User.DatasourceList)
                    {
                        sqdr = new SqlDataRecord(new SqlMetaData[]
                                                 { new SqlMetaData("DatasourceID", SqlDbType.Int),
                                                   new SqlMetaData("UserID", SqlDbType.Int) });


                        // Set the record fields.
                        sqdr.SetInt32(0, item.DatasourceId);
                        sqdr.SetInt32(1, User.UserID);

                        sqlDrList.Add(sqdr);
                    }


                    if (User.DatasourceList.Count == 0)
                    {
                        updUsercommand.Parameters["@DatasourceUser"].Value = null;
                    }
                    else
                    {
                        updUsercommand.Parameters["@DatasourceUser"].Value = sqlDrList;
                    }
                }
                else
                {
                    updUsercommand.CommandType = CommandType.StoredProcedure;
                    updUsercommand.CommandText = "usp_update_password";
                    updUsercommand.Parameters.Add("UserId", User.UserID);
                    updUsercommand.Parameters.Add("HashedPassword", User.PasswordHash);
                }
                try
                {
                    updUsercommand.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    throw;
                }

                return(true);
            }
        }
Beispiel #8
0
        public bool AddUser(UserOrganizationDto dto)
        {
            SqlDatabase db = new SqlDatabase(ConnectionString);

            UserDTO User = dto.User;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                SqlCommand addUserCommand = connection.CreateCommand();

                addUserCommand.CommandType = CommandType.StoredProcedure;
                addUserCommand.CommandText = "usp_add_user";

                addUserCommand.Parameters.Add("UserName", User.UserName);
                addUserCommand.Parameters.Add("FirstName", User.FirstName);
                addUserCommand.Parameters.Add("LastName", User.LastName);
                addUserCommand.Parameters.Add("EmailAddress", User.Email);
                addUserCommand.Parameters.Add("PhoneNumber", User.Phone);
                addUserCommand.Parameters.Add("PasswordHash", User.PasswordHash);
                addUserCommand.Parameters.Add("ResetPassword", User.ShouldResetPassword);

                if (User.IsExistingUser)
                {
                    addUserCommand.Parameters.Add("UsrId", User.UserID);
                }
                else
                {
                    addUserCommand.Parameters.Add("UsrId", -1);
                }

                addUserCommand.Parameters.Add("OrganizationId", dto.Organization.Id);
                addUserCommand.Parameters.Add("RoleId", dto.RoleId);
                addUserCommand.Parameters.Add("Active", dto.Active);

                addUserCommand.Parameters.Add("UGuid", Guid.NewGuid());

                addUserCommand.Parameters.Add("@DatasourceUser", SqlDbType.Structured);
                addUserCommand.Parameters["@DatasourceUser"].Direction = ParameterDirection.Input;
                addUserCommand.Parameters["@DatasourceUser"].TypeName  = "DatasourceUserTableType";

                List <SqlDataRecord> sqlDrList = new List <SqlDataRecord>();

                SqlDataRecord sqdr;



                foreach (DatasourceDto item in User.DatasourceList)
                {
                    sqdr = new SqlDataRecord(new SqlMetaData[]
                                             { new SqlMetaData("DatasourceID", SqlDbType.Int),
                                               new SqlMetaData("UserID", SqlDbType.Int) });


                    // Set the record fields.
                    sqdr.SetInt32(0, item.DatasourceId);
                    sqdr.SetInt32(1, 0);

                    sqlDrList.Add(sqdr);
                }


                if (User.DatasourceList.Count == 0)
                {
                    addUserCommand.Parameters["@DatasourceUser"].Value = null;
                }
                else
                {
                    addUserCommand.Parameters["@DatasourceUser"].Value = sqlDrList;
                }

                try
                {
                    addUserCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                    return(false);
                }

                //try
                //{
                //    if (!User.IsExistingUser)
                //    {
                //        addUserCommand.CommandType = CommandType.StoredProcedure;
                //        addUserCommand.CommandText = "usp_add_user";//TBD
                //        addUserCommand.Parameters.Add("UserName", User.UserName);
                //        addUserCommand.Parameters.Add("FirstName", User.FirstName);
                //        addUserCommand.Parameters.Add("LastName", User.LastName);
                //        //addUserCommand.Parameters.Add("OrganizationId", dto.OrganizationID);
                //        //addUserCommand.Parameters.Add("RoleID", dto.RoleValue);
                //        addUserCommand.Parameters.Add("EmailAddress", User.Email);
                //        addUserCommand.Parameters.Add("PhoneNumber", User.Phone);
                //        addUserCommand.Parameters.Add("PasswordHash", User.PasswordHash);
                //        addUserCommand.Parameters.Add("ResetPassword", true);
                //        //addUserCommand.Parameters.Add("Active", dto.IsActive);
                //        addUserCommand.Parameters.Add(new SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int) { Direction = ParameterDirection.Output });

                //        addUserCommand.ExecuteNonQuery();

                //        User.UserID = (int)addUserCommand.Parameters["@RETURN_VALUE"].Value;

                //        if (User.UserID < 0)
                //        {
                //            return false;
                //        }
                //    }



                //    //if (flag > -1)
                //    //{
                //    for (int i = 0; i < User.DatasourceList.Count; i++)
                //    {
                //        addDScommand = connection.CreateCommand();
                //        //addDScommand.Transaction = sqlTran;
                //        try
                //        {
                //            //flag = Convert.ToInt32(db.ExecuteScalar("usp_add_datasource", dto.UserID, dto.DatasourceList[i]));
                //            //if (flag < 0)
                //            //{
                //            //    return false;
                //            //}

                //            addDScommand.CommandType = CommandType.StoredProcedure;
                //            addDScommand.CommandText = "usp_add_user_datasource";
                //            addDScommand.Parameters.Add("UserName", User.UserName);
                //            addDScommand.Parameters.Add("DatasourceName", User.DatasourceList[i].DatasourceName);
                //            //addDScommand.Parameters.Add(new SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int) { Direction = ParameterDirection.Output });
                //            addDScommand.ExecuteNonQuery();

                //            //flag = (int)addDScommand.Parameters["@RETURN_VALUE"].Value;

                //        }
                //        catch (SqlException sqlEx)
                //        {
                //            // sqlTran.Rollback();
                //            Exception duplicateException = new Exception(string.Format("SQL Exception - {0}", sqlEx.Message));
                //            throw duplicateException;
                //        }
                //        catch (Exception ex)
                //        {
                //            //sqlTran.Rollback();
                //            throw new Exception(ex.Message);
                //        }
                //    }

                //    //if (flag > -1)
                //    //{
                //    //    // sqlTran.Commit();
                //    //    return true;
                //    //}

                //    //}

                //    addUserCommand = connection.CreateCommand();
                //    // addUserCommand.Transaction = sqlTran;

                //    //updateUserCommand.CommandType = CommandType.StoredProcedure;
                //    //updateUserCommand.CommandText = "usp_update_user";
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@FirstName", User.FirstName));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@LastName", User.LastName));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@OrganizationID", organizationID));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@RoleID", User.RoleValue));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@EmailAddress", User.Email));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@PhoneNumber", User.Phone));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@UserId", User.UserID));
                //    //updateUserCommand.Parameters.Add(new SqlParameter("@Active", User.IsActive));

                //    //updateUserCommand.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int) { Direction = ParameterDirection.Output });

                //    addUserCommand.CommandType = CommandType.StoredProcedure;
                //    addUserCommand.CommandText = "usp_add_user_organization";
                //    addUserCommand.Parameters.Add(new SqlParameter("@UserId", User.UserID));
                //    addUserCommand.Parameters.Add(new SqlParameter("@OrganizationID", dto.Organization.Id));
                //    addUserCommand.Parameters.Add(new SqlParameter("@RoleID", dto.RoleId));
                //    addUserCommand.Parameters.Add(new SqlParameter("@Active", dto.Active));

                //    //  SqlParameter retvalUser = new SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int);
                //    //  retvalUser.Direction = System.Data.ParameterDirection.ReturnValue;
                //    //  addUserCommand.Parameters.Add(retvalUser);

                //    addUserCommand.ExecuteNonQuery();
                //}
                //catch (Exception e)
                //{
                //    //  sqlTran.Rollback();
                //    throw new Exception(e.Message);
                //}
            }
            return(true);
            //return false;
        }
Beispiel #9
0
        public bool AddUser(UserOrganizationDto dto)
        {
            //      SqlDatabase db = new SqlDatabase(ConnectionString);
            UserDTO User = dto.User;

            using (MySqlConnection connection = new MySqlConnection(ConnectionString))
            {
                connection.Open();

                MySqlCommand addUserCommand = connection.CreateCommand();

                addUserCommand.CommandType = CommandType.StoredProcedure;
                addUserCommand.CommandText = "usp_add_user";

                addUserCommand.Parameters.Add("UserNameArg", User.UserName);
                addUserCommand.Parameters.Add("FirstName", User.FirstName);
                addUserCommand.Parameters.Add("LastName", User.LastName);
                addUserCommand.Parameters.Add("EmailAddressArg", User.Email);
                addUserCommand.Parameters.Add("PhoneNumber", User.Phone);
                addUserCommand.Parameters.Add("PasswordHash", User.PasswordHash);
                addUserCommand.Parameters.Add("ResetPassword", User.ShouldResetPassword);
                //addUserCommand.Parameters.Add("IsExistingUser", User.IsExistingUser);

                if (User.IsExistingUser)
                {
                    addUserCommand.Parameters.Add("UsrId", User.UserID);
                }
                else
                {
                    addUserCommand.Parameters.Add("UsrId", -1);
                }

                addUserCommand.Parameters.Add("OrganizationId", dto.Organization.Id);
                addUserCommand.Parameters.Add("RoleId", dto.RoleId);
                addUserCommand.Parameters.Add("Active", dto.Active);

                addUserCommand.Parameters.Add("@DatasourceUser", SqlDbType.Structured);
                addUserCommand.Parameters["@DatasourceUser"].Direction = ParameterDirection.Input;

                try
                {
                    addUserCommand.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                    return(false);
                }

                int defaultUserId = 0;


                try
                {
                    foreach (DatasourceDto item in User.DatasourceList)
                    {
                        MySqlHelper.ExecuteNonQuery(ConnectionString, "call usp_add_datasourceuser ",
                                                    new MySqlParameter[]
                        {
                            new MySqlParameter("DatasourceId", item.DatasourceId),
                            new MySqlParameter("UserId", defaultUserId)
                        });
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                    return(false);
                }


                return(true);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Adds new org and Admin User object
        /// </summary>
        /// <param name="dto"></param>
        public int AddOrganization(UserOrganizationDto userOrganizationDto)
        {
            OrganizationDto organizationDto = userOrganizationDto.Organization;

            UserDTO userDto = userOrganizationDto.User;

            if (userOrganizationDto.User == null)
            {
                throw new Exception("An organization cannot be added with zero users");
            }

            int          organizationID = -1;
            PostgreSQLDB db             = new PostgreSQLDB(ConnectionString);

            NpgsqlCommand Command = new NpgsqlCommand();

            Command.CommandType = CommandType.StoredProcedure;
            Command.CommandText = "add_organization";

            NpgsqlParameter parameter = new NpgsqlParameter("orgname", NpgsqlTypes.NpgsqlDbType.Varchar);

            parameter.Value     = organizationDto.Name;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("orgdescription", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = organizationDto.Description;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("Usid", NpgsqlTypes.NpgsqlDbType.Integer);
            parameter.Value     = userDto.UserID;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("UserNm", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.UserName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("FirstNm", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.FirstName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("LastNm", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.LastName;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("EmailAdd", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.Email;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("phonenbr", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.Phone;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("PwdHash", NpgsqlTypes.NpgsqlDbType.Varchar);
            parameter.Value     = userDto.PasswordHash;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("IsExistingUser", NpgsqlTypes.NpgsqlDbType.Boolean);
            parameter.Value     = userDto.IsExistingUser;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);



            if (userDto.IsExistingUser)
            {
                parameter           = new NpgsqlParameter("ResetPwd", NpgsqlTypes.NpgsqlDbType.Boolean);
                parameter.Value     = userDto.ShouldResetPassword;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);
            }
            else
            {
                parameter           = new NpgsqlParameter("ResetPwd", NpgsqlTypes.NpgsqlDbType.Boolean);
                parameter.Value     = true;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);
            }

            parameter           = new NpgsqlParameter("RId", NpgsqlTypes.NpgsqlDbType.Integer);
            parameter.Value     = userOrganizationDto.RoleId;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            parameter           = new NpgsqlParameter("IsActive", NpgsqlTypes.NpgsqlDbType.Boolean);
            parameter.Value     = userOrganizationDto.Active;
            parameter.Direction = ParameterDirection.Input;
            Command.Parameters.Add(parameter);

            try
            {
                db.ExecuteNonQuery(Command);
                organizationID = 1000;     //success
            }
            catch (Exception Ex)
            {
                throw new Exception(Ex.Message);
            }


            return(organizationID);
        }
Beispiel #11
0
        /// <summary>
        /// Handles the Click event of the btnFinish control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void btnFinish_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (ApplicationViewModel.Instance.DemoMode)
            {
                DemoMode dm = new DemoMode();
                dm.Show();
                return;
            }


            Storyboard2.Begin();
            tbStep1.Foreground = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0));
            rectStep1.Fill     = new SolidColorBrush(Color.FromArgb(255, 38, 198, 48));
            tbStep2.Foreground = new SolidColorBrush(Color.FromArgb(255, 122, 122, 122));
            rectStep2.Fill     = new SolidColorBrush(Color.FromArgb(255, 122, 122, 122));

            //userDto = userDtoCopy;
            //this.SelectedUserDto = new UserDTO();
            if (this.SelectedUserDto == null)
            {
                this.SelectedUserDto = new UserDTO();
            }
            this.SelectedUserDto.FirstName = tbFirstName.Text;
            this.SelectedUserDto.LastName  = tbLastName.Text;
            if (ApplicationViewModel.Instance.AuthenticationMode.ToString().ToLower() == "windows")
            {
                this.SelectedUserDto.Email    = tbEmailAddress.Text.ToString().ToLower();
                this.SelectedUserDto.UserName = tbUserID.Text.ToString().ToLower();
            }
            else
            {
                this.SelectedUserDto.Email    = autoEmail.Text.ToString().ToLower();
                this.SelectedUserDto.UserName = autoEmail.Text.ToLower();
            }

            this.SelectedUserDto.Phone = tbPhone.Text;
            //this.SelectedUserDto.RoleValue = Convert.ToInt32(Enum.Parse(typeof(RolesEnum), ((ComboBoxItem)cmbRole.SelectedValue).Content.ToString(), false));
            this.SelectedUserDto.UserRoleInOrganization = ((ComboBoxItem)cmbRole.SelectedItem).Content.ToString(); // cmbRole.SelectedValue.ToString();

            //this.SelectedUserDto.OrganizationID = User.Instance.UserDto.OrganizationID;
            this.SelectedUserDto.DatasourceList = ReadDatasourceList(this.SelectedUserDto.UserRoleInOrganization);

            UserOrganizationDto dto = new UserOrganizationDto();


            dto.Organization = new OrganizationDto();

            dto.Organization.Active           = this.SelectedOrg.Active;
            dto.Organization.AdminCount       = this.SelectedOrg.AdminCount;
            dto.Organization.AnalystCount     = this.SelectedOrg.AnalystCount;
            dto.Organization.DatasourceCount  = this.SelectedOrg.DatasourceCount;
            dto.Organization.DatasourcesCount = this.SelectedOrg.DatasourcesCount;
            dto.Organization.Description      = "";
            dto.Organization.Id              = this.SelectedOrg.Id;
            dto.Organization.Name            = this.SelectedOrg.Name;
            dto.Organization.SuperAdminCount = this.SelectedOrg.SuperAdminCount;
            dto.Organization.TotalUserCount  = this.SelectedOrg.TotalUserCount;


            dto.RoleId = Convert.ToInt32(Enum.Parse(typeof(RolesEnum), ((ComboBoxItem)cmbRole.SelectedValue).Content.ToString(), false));
            dto.Active = (cmbActive.SelectionBoxItem.ToString() == "Yes") ? true : false;


            switch (Mode)
            {
            case ModeType.Add:
                dto.User = this.SelectedUserDto;
                uvm.AddUser(dto);
                uvm.UserAdded       += new EventHandler(uvm_UserAdded);
                uvm.UserAddedFailed += new EventHandler(uvm_UserAddedFailed);
                break;

            case ModeType.Edit:
                this.SelectedUserDto.UserID       = this.SelectedUserDto.UserID;
                this.SelectedUserDto.PasswordHash = this.SelectedUserDto.PasswordHash;
                this.SelectedUserDto.UserEditType = UserEditType.EditingUserInfo;
                dto.User = this.SelectedUserDto;
                uvm.UpdateUser(dto);
                uvm.UserUpdated += new EventHandler(uvm_UserUpdated);
                break;

            default:
                break;
            }

            btnFinish.IsEnabled = false;
            this.DialogResult   = true;
        }
Beispiel #12
0
        // TODO: Add properties using the mvvmprop code snippet

        #endregion

        #region Methods

        public void Add(UserOrganizationDto dto)
        {
            OrganizationServiceAgent osa = new OrganizationServiceAgent();

            osa.Add(dto, AddCompleted);
        }
Beispiel #13
0
        public void AddUser(UserOrganizationDto dto)
        {
            UserServiceAgent usa = new UserServiceAgent();

            usa.AddUser(dto, AddUserCompleted);
        }
Beispiel #14
0
        public void UpdateUser(UserOrganizationDto dto)
        {
            UserServiceAgent usa = new UserServiceAgent();

            usa.UpdateUser(dto, UpdateUserCompleted);
        }
Beispiel #15
0
        /// <summary>
        /// Handles the Click event of the btnSaveOrgDetails control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs" /> instance containing the event data.</param>
        private void btnSaveOrgDetails_Click(object sender, RoutedEventArgs e)
        {
            if (ApplicationViewModel.Instance.DemoMode)
            {
                DemoMode dm = new DemoMode();
                dm.Show();
                return;
            }

            if (addEditMode == Organizations.AddEditMode.Edit)
            {
                if (ValidateForm())
                {
                    organizationViewModel = new OrganizationViewModel();

                    organizationViewModel.DtoUpdated += new EventHandler <NotificationEventArgs <Exception> >(organizationViewModel_DtoUpdated);
                    //   OrganizationDto modelODto = organizationViewModel.OrganizationDtoList.Single(x => x.Id ==  this.selectedOrgID);
                    modelODto        = this.DataContext as OrganizationDto;
                    modelODto.Name   = tbOrganizationName.Text;
                    modelODto.Active = (((ComboBoxItem)cboActive.SelectedItem).Content.ToString() == "Yes") ? true : false;
                    organizationViewModel.Update(modelODto);
                    //Code to show success message on edit organization
                    //SucessMsg.Text = "Organization " + tbOrganizationName.Text + " has been updated.";
                    //imgSMsg.Visibility = System.Windows.Visibility.Visible;
                    //spMsg.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else
            {
                if (ValidateForm())
                {
                    //string s = ((ComboBoxItem)cboActive.SelectedItem).Content.ToString();
                    bool IsActive = false;

                    if (((ComboBoxItem)cboActive.SelectedItem).Content.ToString() == "Yes")
                    {
                        IsActive = true;
                    }

                    userOrgDto = new UserOrganizationDto();

                    newOrganizationDto = new OrganizationDto()
                    {
                        Active           = true,
                        Id               = -1,
                        Name             = tbOrganizationName.Text,
                        AdminCount       = 0,
                        AnalystCount     = 0,
                        DatasourceCount  = 0,
                        DatasourcesCount = 0,
                        Description      = null,
                        SuperAdminCount  = 0,
                        TotalUserCount   = 0
                    };

                    if (userDto != null)
                    {
                        newAdminDto = userDto;
                    }
                    else
                    {
                        newAdminDto = new UserDTO()
                        {
                            FirstName = tbFirstName.Text,
                            LastName  = tbLastName.Text,
                            //OrganizationID = -1,
                            Phone  = tbPhone.Text,
                            UserID = -1,
                            //UserName = autoEmail.Text, //"default user name",
                            //Email = autoEmail.Text,
                            //RoleValue = 2,
                            IsActive       = true,
                            IsExistingUser = false
                        };
                    }

                    //newOrganizationDto.AdminList = new List<UserDTO>();
                    //newOrganizationDto.AdminList.Add(newAdminDto);

                    if (ApplicationViewModel.Instance.AuthenticationMode.ToString().ToLower() == "windows")
                    {
                        newAdminDto.Email    = tbEmailAddress.Text.ToString().ToLower();
                        newAdminDto.UserName = tbUserId.Text.ToString().ToLower();
                    }
                    else
                    {
                        newAdminDto.Email    = autoEmail.Text.ToString().ToLower();
                        newAdminDto.UserName = autoEmail.Text;
                    }


                    userOrgDto.Organization = newOrganizationDto;
                    userOrgDto.User         = newAdminDto;
                    userOrgDto.RoleId       = 2;
                    userOrgDto.Active       = IsActive;

                    organizationViewModel           = new OrganizationViewModel();
                    organizationViewModel.DtoAdded += new EventHandler <NotificationEventArgs <Exception> >(organizationViewModel_DtoAdded);
                    organizationViewModel.Add(userOrgDto);

                    //Code to show success message on add organization
                    //SucessMsg.Text = "Organization " + tbOrganizationName.Text + " has been added.";
                    //imgSMsg.Visibility = System.Windows.Visibility.Visible;
                    //spMsg.Visibility = System.Windows.Visibility.Visible;
                    //spMsg.Background = new SolidColorBrush(Color.FromArgb(255, 241, 202, 194)); //pink BK to use in case of error
                    //errMsg.Foreground = new SolidColorBrush(Color.FromArgb(255, 96, 25, 25)); //dark pink text color to use in case of error.
                    //imgerrMsg.Visibility = System.Windows.Visibility.Collapsed; // error icon
                }
            }
        }
Beispiel #16
0
        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="dto">The dto.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception"></exception>
        public bool UpdateUser(UserOrganizationDto dto)
        {
            PostgreSQLDB db = new PostgreSQLDB(ConnectionString);

            UserDTO User = dto.User;

            NpgsqlCommand Command = new NpgsqlCommand();

            NpgsqlParameter parameter = null;


            if (User.UserEditType == UserEditType.EditingUserInfo)
            {
                Command.CommandType = CommandType.StoredProcedure;
                Command.CommandText = "update_user";

                parameter           = new NpgsqlParameter("fname", NpgsqlTypes.NpgsqlDbType.Varchar);
                parameter.Value     = User.FirstName;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("lname", NpgsqlTypes.NpgsqlDbType.Varchar);
                parameter.Value     = User.LastName;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("emailadd", NpgsqlTypes.NpgsqlDbType.Varchar);
                parameter.Value     = User.Email;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("pnumber", NpgsqlTypes.NpgsqlDbType.Varchar);
                parameter.Value     = User.Phone;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("usid", NpgsqlTypes.NpgsqlDbType.Integer);
                parameter.Value     = User.UserID;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);
                //addUserCommand.Parameters.Add("UsrId", User.UserID);

                parameter           = new NpgsqlParameter("orid", NpgsqlTypes.NpgsqlDbType.Integer);
                parameter.Value     = dto.Organization.Id;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("active", NpgsqlTypes.NpgsqlDbType.Boolean);
                parameter.Value     = dto.Active;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("roleid", NpgsqlTypes.NpgsqlDbType.Integer);
                parameter.Value     = dto.RoleId;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);



                StringBuilder DSIds = new StringBuilder();

                foreach (DatasourceDto item in User.DatasourceList)
                {
                    DSIds.Append(item.DatasourceId);
                    DSIds.Append(",");
                }

                parameter = new NpgsqlParameter("dsids", NpgsqlTypes.NpgsqlDbType.Varchar);
                if (DSIds.ToString().Contains(","))
                {
                    parameter.Value = DSIds.ToString().Substring(0, DSIds.ToString().Length - 1);
                }
                else
                {
                    parameter.Value = "";
                }
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);
            }
            else
            {
                Command.CommandType = CommandType.StoredProcedure;
                Command.CommandText = "update_password";

                parameter           = new NpgsqlParameter("uid", NpgsqlTypes.NpgsqlDbType.Integer);
                parameter.Value     = User.UserID;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);

                parameter           = new NpgsqlParameter("hpassword", NpgsqlTypes.NpgsqlDbType.Varchar);
                parameter.Value     = User.PasswordHash;
                parameter.Direction = ParameterDirection.Input;
                Command.Parameters.Add(parameter);
            }
            try
            {
                db.ExecuteNonQuery(Command);
            }
            catch (Exception ex)
            {
                //throw new Exception(ex.Message);
                return(false);
            }

            return(true);
        }
Beispiel #17
0
 /// <summary>
 /// Generates/Adds the organization
 /// </summary>
 /// <param name="dto"></param>
 public int AddOrganization(UserOrganizationDto dto)
 {
     //return em.AddOrganization(organizationDto, userDTO);
     return(em.AddOrganization(dto));
 }
Beispiel #18
0
 /// <summary>
 /// Edits the user.
 /// </summary>
 /// <param name="dto">The dto.</param>
 /// <returns></returns>
 public bool EditUser(UserOrganizationDto dto)
 {
     return(em.EditUser(dto));
 }
Beispiel #19
0
 /// <summary>
 /// Generates the user.
 /// </summary>
 /// <param name="dto">The dto.</param>
 /// <returns></returns>
 public bool GenerateUser(UserOrganizationDto dto)
 {
     return(em.GenerateUser(dto));
 }