public GestionAdministrativaIdentity(Operador operador, Sucursal sucursal) { Name = operador.Usuario; Email = string.Empty; Roles = operador.Roles.Select(r => r.Description).ToArray(); Operador = operador; Sucursal = sucursal; }
private void SeleccionarOperador() { _operador = (OperadorId.HasValue) ? Uow.Operadores.Obtener(p => p.Id == OperadorId, o => o.OperadoresSucursales) : null; OnSeleccionarSucursalFinished(_operador); }
private void OnSeleccionarSucursalFinished(Operador operador) { if (SeleccionarFinished != null) { SeleccionarFinished(this, operador); } }
private void BtnIngresar_Click(object sender, EventArgs e) { var clearTextPassword = TxtPassword.Text; var username = CbxUsuario.Usuario; this.FormErrorProvider.Clear(); if (string.IsNullOrEmpty(username)) { this.FormErrorProvider.SetError(CbxUsuario, "Debe ingresar un usuario"); this.DialogResult = DialogResult.None; return; } if (string.IsNullOrEmpty(clearTextPassword)) { this.FormErrorProvider.SetError(TxtPassword, "Debe ingresar una clave"); this.DialogResult = DialogResult.None; return; } if (UcSucursales.Sucursal == null) { this.FormErrorProvider.SetError(UcSucursales, "Debe seleccionar una sucursal"); this.DialogResult = DialogResult.None; return; } try { //Validate credentials through the authentication service Operador user = _authenticationService.AuthenticateUser(username, clearTextPassword); Sucursal sucursal = UcSucursales.Sucursal; //Get the current principal object GestionAdministrativaPrincipal laPazPrincipal = Thread.CurrentPrincipal as GestionAdministrativaPrincipal; if (laPazPrincipal == null) throw new ArgumentException("The application's default thread principal must be set to a CustomPrincipal object on startup."); var sucursalValida = user.OperadoresSucursales.Any(s => s.SucursalId == sucursal.Id); if (!sucursalValida) { this.FormErrorProvider.SetError(UcSucursales, "No esta habilitado para ingresar con esta sucursal"); this.DialogResult = DialogResult.None; return; } if (RolesAceptados != null && RolesAceptados.Any()) { if (!(user.Roles.Select(r => r.Description).Any(r => RolesAceptados.Any(ra => ra == r)))) { _messageBoxDisplayService.ShowError(Resources.ErrorMessageRolesRequeridos); this.DialogResult = DialogResult.None; return; } } if (CambiarIdentity) { //Authenticate the user laPazPrincipal.Identity = new GestionAdministrativaIdentity(user, sucursal); } UltimoOperadorIngresado = user; } catch (UnauthorizedAccessException) { _messageBoxDisplayService.ShowError("La credenciales ingresadas no son correctas"); this.DialogResult = DialogResult.None; } }
private void UsuarioSeleccionado(object sender, Operador operador) { //var operador = Uow.Operadores.Obtener(o => o.Usuario == CbxUsuario.Usuario,o => o.OperadorSucursals); if (operador != null) { var sucursal = operador.OperadoresSucursales.FirstOrDefault(); if (sucursal != null && (!UcSucursales.SucursalId.HasValue || UcSucursales.SucursalId == 0)) { UcSucursales.SucursalId = sucursal.SucursalId; } } }