public UserModel GetUser(UserModel user)
        {
            try
            {
                using (FacturandoEntities context = new FacturandoEntities())
                {

                    var result = context.User
                        .Where(x => x.Login.Equals(user.Login) && x.Password.Equals(user.Password))
                        .Select(x => new UserModel
                        {
                             Id = x.Id,
                             Login = x.Login,
                             Password = x.Password,
                             DateEvent = x.DateEvent                             
                        }).FirstOrDefault();

                    if (result != null)
                    {
                        result.Roles = context.UserRol.Where(x => x.IdUser == result.Id).Select(x => new RolModel
                        {
                            Id = x.IdRol.Value,
                            RolName = x.Rol.Description
                        }).ToList();

                        if (result.Roles != null)
                        {
                            foreach (var rol in result.Roles)
                            {
                                rol.ActionList = context.RolAction.Where(x => x.IdRol == rol.Id).Select(x => x.Action.Description).ToList();
                                rol.ModuleList = context.RolModule.Where(x => x.IdRol == rol.Id).Select(x => x.Module.Description).ToList();
                            }
                        }
                    }                 
                    return result;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Encrypt encrypt = new Encrypt();
            string encText = encrypt.EncryptKey(txtContraseña.Text);
            //string decText = encrypt.DecryptKey(encText);
            _user =_userData.GetUser(new UserModel {
                 Login = txtUsuario.Text,
                 Password = encText
            });

            if (_user != null)
            {
                Hide();
                Principal principal = new Principal(SystemCompany, _user);
                principal.Show(this);
            }
            else {
                MessageBox.Show("Error en usuario o contraseña");
            }
        }