Beispiel #1
0
        private void cmdAccept_Click(object sender, EventArgs e)
        {
            DialogResult pressed = MessageBox.Show(SessionHelper.GetTranslation("SAVE_CHANGES_QUESTION"), "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (pressed == DialogResult.No)
            {
                return;
            }

            try
            {
                UserBLL       userBll  = new UserBLL();
                LanguageBM    language = (LanguageBM)cmbLanguage.SelectedValue;
                PermissionMDL profile  = (PermissionMDL)cmbProfile.SelectedValue;
                ResultBM      saveResult;
                UserBM        userBm;

                if (txtPassword.Text != txtPasswordCheck.Text)
                {
                    MessageBox.Show("El password asignado no coincide con el de verificación.", "Validación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (isUpdate)
                {
                    this.Entity.Name         = txtName.Text;
                    this.Entity.Active       = chkIsActive.Checked;
                    this.Entity.LanguageId   = language.Id;
                    this.Entity.PermissionId = profile.Code;

                    //Hubo cambio de password
                    bool updatePassword = txtPassword.Text.Length > 0;
                    if (updatePassword)
                    {
                        this.Entity.Password = txtPassword.Text;
                    }

                    saveResult = userBll.UpdateUser(this.Entity, updatePassword);

                    if (saveResult.IsValid())
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(saveResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    userBm     = new UserBM(txtName.Text, chkIsActive.Checked, language.Id, profile.code, txtPassword.Text);
                    saveResult = userBll.SaveUser(userBm);

                    if (saveResult.IsValid())
                    {
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(saveResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "EXCEPCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Recupera un perfil en base a su id.
        /// </summary>
        /// <param name="profileId"></param>
        /// <returns></returns>
        public ResultBM GetProfile(string profileId)
        {
            try {
                List <PermissionDTO> permissions;
                ProfileDAL           profileDal = new ProfileDAL();
                ProfileBM            result;

                string fatherCode;
                string code;
                string description;
                bool   excluded;

                bool moreItemsToAdd = true;
                int  maxIterations  = 0; //Condición de corte del while en caso de una eventualidad
                log.AddLogInfo("Recuperando perfil", "Recuperando perfil " + profileId + ".", this);

                permissions = profileDal.GetProfile(profileId);

                if (permissions == null)
                {
                    throw new Exception(SessionHelper.GetTranslation("NO_PERMISSION_FOUND_ERROR"));
                }
                else if (permissions.Count == 1)
                {
                    //En caso de obtener sólo un permiso, debe crearse como hijo.
                    fatherCode  = permissions[0].fatherCode;
                    code        = permissions[0].code;
                    description = permissions[0].description;
                    excluded    = permissions[0].excluded;
                    result      = new PermissionMDL(fatherCode, code, description, excluded);
                }
                else
                {
                    //La estrategia consiste en obtener el primer elemento y considerarlo root (garantizado por la base de dato).
                    //Luego, recorrer la lista de los permisos y asignarlos al root hasta que la lista de permisos esté vacía.
                    //Para vaciar la lista, considerar la siguiente estrategia: si se agregó, se borra de la lista.
                    fatherCode  = permissions[0].fatherCode;
                    code        = permissions[0].code;
                    description = permissions[0].description;
                    excluded    = permissions[0].excluded;
                    result      = new PermissionsMDL(fatherCode, code, description, excluded);

                    while (moreItemsToAdd)
                    {
                        for (int i = permissions.Count - 1; i > 0; --i)
                        {
                            fatherCode  = permissions[i].fatherCode;
                            code        = permissions[i].code;
                            description = permissions[i].description;
                            excluded    = permissions[i].excluded;

                            if (result.AddPermissionSorted(new PermissionMDL(fatherCode, code, description, excluded)))
                            {
                                permissions.RemoveAt(i);
                            }
                        }

                        maxIterations += 1;
                        moreItemsToAdd = (permissions.Count > 0 && maxIterations < 100);
                    }
                }

                log.AddLogInfo("Recuperando perfil", "Perfil " + profileId + " recuperado.", this);
                return(new ResultBM(ResultBM.Type.OK, "Permiso recuperado.", result));
            }
            catch (Exception exception)
            {
                log.AddLogCritical("Recuperando perfil", exception.Message, this);
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }