Exemplo n.º 1
0
        private void AddOrRemoveUserToRoles(UserToRoles addOrRemove)
        {
            try
            {
                string   username           = allUsersInUserToRole_comboBox.SelectedItem.ToString();
                string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.userToRole_groupBox);
                string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.userToRole_groupBox);

                switch (addOrRemove)
                {
                case UserToRoles.Add:
                {
                    try
                    {
                        Roles.AddUserToRoles(username, checkedRolesArray);
                        SampleMessageBox.Show(String.Format("Successfully add {0} to  {1} role(s)", username, checkedRolesString));
                    }
                    catch (ProviderException)
                    {
                        if (checkedRolesArray.Length == 1)
                        {
                            SampleMessageBox.Show(String.Format("{0} is already in {1} role", username, checkedRolesString));
                        }
                        else
                        {
                            SampleMessageBox.Show(String.Format("{0} is already in some of these roles:\n{1} ", username, checkedRolesString));
                        }
                    }
                    catch (ArgumentException)
                    {
                        SampleMessageBox.Show("Please check some of roles");
                    }
                    break;
                }

                case UserToRoles.Remove:
                {
                    try
                    {
                        Roles.RemoveUserFromRoles(username, checkedRolesArray);
                        SampleMessageBox.Show(String.Format("Successfully remove {0} from {1} role(s)", username, checkedRolesString));
                    }
                    catch (ArgumentException)
                    {
                        SampleMessageBox.Show("Please check some of roles");
                    }
                    break;
                }
                }
                DisplayUsers(Display.FirstPage);
                RolesHelper.UncheckedAllCheckboxes(this.userToRole_groupBox);
                allUsersInUserToRole_comboBox.SelectedIndex = -1;
            }
            catch (NullReferenceException)
            {
                SampleMessageBox.Show("Please, select user!");
            }
        }
        private void GetCurrentUserInfo()
        {
            currentUsername_label.Text = "Hello " + Membership.GetUser().UserName;
            LastLoginDate_label.Text   = "Last login date: " + Login.currentUser.LastLoginDate.ToShortTimeString() + " " +
                                         Login.currentUser.LastLoginDate.ToShortDateString();
            NumberOfUsersOnline_label.Text = "Online users:" + Membership.GetNumberOfUsersOnline().ToString();

            roles_label.Text = "User's roles:" + RolesHelper.GetAllRolesForUserInOneString(Login.currentUser.UserName);
        }
        private void AddCheckBoxesRolesInAllContainers()
        {
            RolesHelper.AddCheckBoxForAllRoles(this.deleteRoles_groupBox, 58,
                                               this.deleteRoles_groupBox.Location.X + 2, deleteRoles_groupBox.Location.Y - 90,
                                               25, deleteRoles_btn);

            RolesHelper.AddCheckBoxForAllRoles(this.rolesToForm_groupBox, 158,
                                               this.rolesToForm_groupBox.Location.X + 2, rolesToForm_groupBox.Location.Y - 190,
                                               66, addRolesToForm_btn, removeRolesFromForm_btn, clearFormsRoles_btn);
        }
Exemplo n.º 4
0
        protected override void GetItemsForDataGridNavigation()
        {
            string userRoles;

            foreach (MembershipUser user in Membership.GetAllUsers())
            {
                userRoles = RolesHelper.GetAllRolesForUserInOneString(user.UserName);

                FillAndAddDataRow(user.UserName, user.LastLoginDate.Date.ToString("dd-MM-yyyy"), user.LastLoginDate.ToString("t"), userRoles, user.IsOnline, user.CreationDate.Date.ToString("dd-MM-yyyy"));
            }
        }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseAuthentication();
            app.UseMvc();
            // allowing any resource to access whichever method it choses
            app.UseCors("Cors");
            RolesHelper.CreateRoles(serviceProvider);
        }
        private void listar()
        {
            try
            {
                this.roles     = new Roles();
                this.roles.opc = 1;

                this.rolH  = new RolesHelper(roles);
                this.table = new DataTable();

                this.table = rolH.ListarRol();
                if (table.Rows.Count > 0)
                {
                    this.dgvListar.DataSource = table;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void deleteRoles_btn_Click(object sender, EventArgs e)
        {
            string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.deleteRoles_groupBox);
            string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.deleteRoles_groupBox);
            int      counter            = 0;

            for (int i = 0; i < checkedRolesArray.Length; i++)
            {
                try
                {
                    string[] usersInRole = Roles.GetUsersInRole(checkedRolesArray[i]);

                    if (usersInRole.Length > 0)
                    {
                        Roles.RemoveUsersFromRole(usersInRole, checkedRolesArray[i]);
                    }

                    if (Roles.DeleteRole(checkedRolesArray[i], true))
                    {
                        counter++;
                    }
                }
                catch (Exception ex)
                {
                    SampleMessageBox.Show(ex.Message);
                }
            }

            if (counter != 0)
            {
                SampleMessageBox.Show(String.Format("Successfully deleted {0} role(s)", checkedRolesString));
                RolesHelper.UncheckedAllCheckboxes(this.deleteRoles_groupBox);
                AddCheckBoxesRolesInAllContainers();
                DisplayUsers(Display.FirstPage);
            }
            else
            {
                SampleMessageBox.Show("Please,check some of roles to delete it");
            }
        }
        private void Eliminar()
        {
            try
            {
                this.table = (DataTable)this.dgvListar.DataSource;
                if (table == null)
                {
                    MessageBox.Show("No hay Usuarios para eliminar");
                }
                else
                {
                    int     indice = dgvListar.CurrentRow.Index;
                    DataRow fila   = table.Rows[indice];
                    this.roles        = new Roles();
                    this.roles.Nombre = fila["nombre"].ToString();
                    this.roles.opc    = 3;
                    this.rolH         = new RolesHelper(roles);
///LOG PARA USUARIOS

/*
 *                  this.bitacora = new Bitacora();
 *                  this.bitacora.Usuario = this.user.Usuario;
 *                  this.bitacora.Movimiento = "Eliminar";
 *                  this.bitacora.Detalle = "Se agrego nuevoS el rol " + this.txtRol.Text;
 *                  this.bitacora.opc = 5;
 *                  this.bitH = new BitacoraHelper(bitacora);
 *                  this.bitH.LogMovimientos();*/
                    //
                    this.rolH.Eliminar();
                    MessageBox.Show("Usuario Eliminado Eliminado");
                    listar();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void cargarCombo()
        {
            try
            {
                this.roles     = new Roles();
                this.roles.opc = 5;
                this.rolH      = new RolesHelper(roles);
                this.table     = new DataTable();
                this.table     = this.rolH.ListarRol();


                if (this.table.Rows.Count > 0)
                {
                    this.cmbRol.DataSource = this.table;
                    cmbRol.ValueMember     = "nombre";
                    cmbRol.DisplayMember   = "nombre";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void validarPerfil()
        {
            roles = new Roles();

            roles.opc      = 6;
            this.roles.ID1 = user.Rol;
            rolesH         = new RolesHelper(roles);

            table = rolesH.BusquedaPermisoRol();
            DataRow fila = table.Rows[0];

            if (bool.Parse(fila["usuarios"].ToString()) == true)
            {
                usuariosToolStripMenuItem.Visible = true;
            }
            if (bool.Parse(fila["entrega"].ToString()) == true)
            {
                entregaToolStripMenuItem.Visible = true;
            }
            if (bool.Parse(fila["inventario"].ToString()) == true)
            {
                inventarioToolStripMenuItem.Visible = true;
            }
            if (bool.Parse(fila["roles"].ToString()) == true)
            {
                rolesToolStripMenuItem.Visible = true;
            }
            if (bool.Parse(fila["prestamo"].ToString()) == true)
            {
                prestamoToolStripMenuItem.Visible = true;
            }
            if (bool.Parse(fila["bitacora"].ToString()) == true)
            {
                tslBitacora.Visible = true;
            }
        }
Exemplo n.º 11
0
 internal bool CheckForPermission(string[] currentUserRoles, out string invalidAuthorizationMessage)
 {
     return(RolesHelper.CheckForPermission(currentUserRoles, this.adminFormAuthorization, out invalidAuthorizationMessage));
 }
Exemplo n.º 12
0
        public bool IsInRole(string role)
        {
            Roles roles = RolesHelper.FromString(role);

            return(IsInRole(roles));
        }
Exemplo n.º 13
0
        static string Rec_menu(int Parent_ID, Models.TrainingCentersDBEntities db, string IdTrainingCenter, string curDropdownId = null)
        {
            string     str = "";
            TagBuilder ul  = new TagBuilder("ul");

            if (curDropdownId != null)
            {
                // если этот пункт меню - dropdown
                ul.MergeAttribute("id", curDropdownId);
                ul.MergeAttribute("class", "f-dropdown");
                ul.MergeAttribute("data-dropdown-content", "");
                ul.MergeAttribute("aria-hidden", "true");
            }
            else
            {
                // если этот пункт меню - не dropdown
                ul.MergeAttribute("class", "clear-fix navigation");
            }

            IQueryable <TrainingCentersCRM.Models.Menu> SaM;

            if (IdTrainingCenter == "empty" || IdTrainingCenter == null)
            {
                SaM = db.Menu.Where(p => p.IdTrainingCenter == "empty" || p.IdTrainingCenter == "other").OrderBy(a => a.Ord_Id);
            }
            else
            {
                SaM = db.Menu.Where(p => p.IdTrainingCenter == IdTrainingCenter || p.IdTrainingCenter == "other" || p.IdTrainingCenter == "empty").OrderBy(a => a.Ord_Id);
            }
            var first_sam = SaM.Where(p => p.Parent_Id == Parent_ID).OrderBy(a => a.Ord_Id);

            foreach (var samp in first_sam)
            {
                if (((IdTrainingCenter == null || IdTrainingCenter == "empty") && samp.IdTrainingCenter == "other" && samp.NotBindInTrainingCenter) ||
                    (IdTrainingCenter != null && IdTrainingCenter != "empty" && samp.IdTrainingCenter == "empty" && !samp.NotBindInTrainingCenter))
                {
                    continue;
                }

                if (samp.Title.Equals("Администрирование")) // FIXME хардкор!
                {
                    if (!RolesHelper.IsUserHasPermission("admin"))
                    {
                        continue;
                    }
                }
                string     str_temp = "";
                TagBuilder li       = new TagBuilder("li");
                TagBuilder a        = new TagBuilder("a");
                string     icon     = "";
                if (SaM.Where(p => p.Parent_Id == samp.Id).Count() > 0)
                {
                    // текущий элемент имеет dropdown
                    icon = "<i class='fa fa-caret-down'></i>";
                    a.MergeAttribute("aria-expanded", "false");
                    var newDropdownId = "dropdown" + IdTrainingCenter + samp.Id.ToString();
                    a.MergeAttribute("data-dropdown", newDropdownId);
                    a.MergeAttribute("aria-controls", newDropdownId);
                    str_temp = Rec_menu(samp.Id, db, IdTrainingCenter, newDropdownId);
                }
                a.MergeAttribute("title", samp.Description);
                a.InnerHtml = samp.Title + icon;
                if (samp.NotBindInTrainingCenter && samp.IdTrainingCenter == "empty")
                {
                    a.MergeAttribute("href", samp.Link);
                }
                else
                {
                    a.MergeAttribute("href", "/" + IdTrainingCenter + samp.Link);
                }
                li.InnerHtml = a.ToString() + str_temp;
                str_temp     = li.ToString();
                str         += str_temp;
            }
            ul.InnerHtml += str;
            return(ul.ToString());
        }
        private void actualizar()
        {
            try
            {
                this.roles   = new Roles();
                roles.Nombre = this.txtRol.Text;
                if (chkInventario.Checked)
                {
                    roles.Inventario = true;
                }
                else
                {
                    roles.Inventario = false;
                }
                if (chckUsuarios.Checked)
                {
                    roles.Usuarios = true;
                }
                else
                {
                    roles.Usuarios = false;
                }
                if (chkPrestamo.Checked)
                {
                    roles.Prestamo = true;
                }
                else
                {
                    roles.Prestamo = false;
                }
                if (chkEntrega.Checked)
                {
                    roles.Entrega = true;
                }
                else
                {
                    roles.Entrega = false;
                }
                if (chckRoles.Checked)
                {
                    roles.Roless = true;
                }
                else
                {
                    roles.Roless = false;
                }
                if (chkBitacora.Checked)
                {
                    roles.Bitacora = true;
                }
                else
                {
                    roles.Bitacora = false;
                }
                roles.opc = 4;

                this.rolH = new RolesHelper(roles);
                ///LOG PARA ROLES
                ///

                /*
                 * this.bitacora = new Bitacora();
                 * this.bitacora.Usuario = this.user.Usuario;
                 * this.bitacora.Movimiento = "actualizo";
                 * this.bitacora.Detalle = "Se actualizo el rol " + this.txtRol.Text;
                 * this.bitacora.opc = 5;
                 * this.bitH = new BitacoraHelper(bitacora);
                 * this.bitH.LogMovimientos();
                 */
                //

                this.rolH.ActualizarRol();
                limpiar();
                MessageBox.Show("Datos del Rol actualizados");
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 15
0
 private void AddCheckBoxesRolesInAllContainers()
 {
     RolesHelper.AddCheckBoxForAllRoles(userToRole_groupBox, 158,
                                        this.allUsersInUserToRole_comboBox.Location.X - 40, this.allUsersInUserToRole_comboBox.Location.Y + this.allUsersInUserToRole_comboBox.Height + 10,
                                        66, addUserToRoles_btn, removeUserFromRoles_btn, clearUserToRole_btn);
 }
        private void guardar()
        {
            try
            {
                // inicializo Usuario
                roles        = new Roles();
                roles.Nombre = this.txtRol.Text;
                if (chkInventario.Checked)
                {
                    roles.Inventario = true;
                }
                else
                {
                    roles.Inventario = false;
                }
                if (chckUsuarios.Checked)
                {
                    roles.Usuarios = true;
                }
                else
                {
                    roles.Usuarios = false;
                }
                if (chkPrestamo.Checked)
                {
                    roles.Prestamo = true;
                }
                else
                {
                    roles.Prestamo = false;
                }
                if (chkEntrega.Checked)
                {
                    roles.Entrega = true;
                }
                else
                {
                    roles.Entrega = false;
                }
                if (chckRoles.Checked)
                {
                    roles.Roless = true;
                }
                else
                {
                    roles.Roless = false;
                }
                if (chkBitacora.Checked)
                {
                    roles.Bitacora = true;
                }
                else
                {
                    roles.Bitacora = false;
                }
                roles.opc = 2;
                //roles.id_username_bitacora = Principal.id_username_bitacora;
                if (this.txtRol.Text != "")
                {
                    this.rolH = new RolesHelper(roles);
                    ///LOG PARA ROLES
                    ///

                    /*
                     * this.bitacora = new Bitacora();
                     * this.bitacora.Usuario = this.user.Usuario;
                     * this.bitacora.Movimiento = "Agregar";
                     * this.bitacora.Detalle = "Se agrego nuevoS el rol " + this.txtRol.Text;
                     * this.bitacora.opc = 5;
                     * this.bitH = new BitacoraHelper(bitacora);
                     * this.bitH.LogMovimientos();*/
                    //

                    this.rolH.GuardarRol();
                    MessageBox.Show("Rol almacenado");
                    limpiar();
                }
                else
                {
                    MessageBox.Show("Debe indicar el nombre del rol");
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void AddOrRemoveRolesToForm(RolesToForm addOrRemove)
        {
            string[] checkedRolesArray  = RolesHelper.GetAllCheckedItemsArray(this.rolesToForm_groupBox);
            string   checkedRolesString = RolesHelper.GetAllCheckedItems(this.rolesToForm_groupBox);

            int  addCounter        = 0;
            int  removeCounter     = 0;
            bool isRoleExistToForm = false;

            try
            {
                string selectedForm = this.formsRolesCollections_comboBox.SelectedItem.ToString();

                if (checkedRolesArray.Length != 0)
                {
                    foreach (SettingsProperty currentProperty in RolesForSpecificForm.Default.Properties)
                    {
                        if (currentProperty.Name.Equals(selectedForm))
                        {
                            foreach (string role in checkedRolesArray)
                            {
                                if (currentProperty.PropertyType == typeof(StringCollection))
                                {
                                    if (RolesForSpecificForm.Default[currentProperty.Name] == null)
                                    {
                                        RolesForSpecificForm.Default[currentProperty.Name] = new StringCollection();
                                    }
                                    switch (addOrRemove)
                                    {
                                    case RolesToForm.Add:
                                    {
                                        if (!(RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Contains(role))
                                        {
                                            try
                                            {
                                                (RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Add(role);
                                                RolesForSpecificForm.Default.Save();
                                                addCounter++;
                                            }
                                            catch (Exception ex)
                                            {
                                                SampleMessageBox.Show(ex.Message);
                                            }
                                        }
                                        else
                                        {
                                            isRoleExistToForm = true;
                                        }
                                        break;
                                    }

                                    case RolesToForm.Remove:
                                    {
                                        try
                                        {
                                            (RolesForSpecificForm.Default[currentProperty.Name] as StringCollection).Remove(role);
                                            RolesForSpecificForm.Default.Save();
                                            removeCounter++;
                                        }
                                        catch (Exception ex)
                                        {
                                            SampleMessageBox.Show(ex.Message);
                                        }
                                        break;
                                    }
                                    }
                                }
                            }
                        }
                    }
                    if (isRoleExistToForm)
                    {
                        SampleMessageBox.Show(String.Format("{0} role(s) already to {1} form", checkedRolesString, selectedForm));
                    }
                    if (addCounter == checkedRolesArray.Length)
                    {
                        SampleMessageBox.Show(String.Format("Successfully add {0} role(s) to {1} form", checkedRolesString, selectedForm));
                    }
                    if (removeCounter == checkedRolesArray.Length)
                    {
                        SampleMessageBox.Show(String.Format("Successfully remove {0} role(s) from {1} form", checkedRolesString, selectedForm));
                    }
                }
                else
                {
                    SampleMessageBox.Show(String.Format("Please first check some of roles"));
                }
            }
            catch (NullReferenceException)
            {
                SampleMessageBox.Show("Please first select FormsRolesCollection");
            }

            DisplayFormsRoles(Display.FirstPage);
            RolesHelper.UncheckedAllCheckboxes(this.rolesToForm_groupBox);
            this.formsRolesCollections_comboBox.SelectedIndex = -1;
        }