Beispiel #1
0
        public ResultBM GetVolunteer(int volunteerId)
        {
            try {
                AddressBLL   addressBll    = new AddressBLL();
                ResultBM     addressResult = null;
                AddressBM    addressBm     = null;
                BranchBLL    branchBll     = new BranchBLL();
                ResultBM     branchResult  = null;
                BranchBM     branchBm      = null;
                UserBLL      userBll       = new UserBLL();
                ResultBM     userResult    = null;
                UserBM       userBm        = null;
                VolunteerDAL volunteerDal  = new VolunteerDAL();
                VolunteerBM  volunteerBm   = null;
                VolunteerDTO volunteerDto  = volunteerDal.GetVolunteer(volunteerId);

                if (volunteerDto != null)
                {
                    //Debería existir
                    addressResult = addressBll.GetAddress(volunteerDto.addressId);
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception("La dirección " + volunteerDto.addressId + " para el voluntario " + volunteerId + " no existe.");
                    }
                    addressBm = addressResult.GetValue <AddressBM>();

                    branchResult = branchBll.GetBranch(volunteerDto.branchId);
                    if (!branchResult.IsValid())
                    {
                        return(branchResult);
                    }
                    if (branchResult.GetValue() == null)
                    {
                        throw new Exception("La sede " + volunteerDto.branchId + " para el voluntario " + volunteerId + " no existe.");
                    }
                    branchBm = branchResult.GetValue <BranchBM>();

                    //El usuario podría no existir porque el voluntario no requiere necesariamente que se lo asocie
                    //con un susuario de sistema
                    userResult = userBll.GetUser(volunteerDto.userId);
                    if (!userResult.IsValid())
                    {
                        return(userResult);
                    }

                    if (userResult.GetValue() != null)
                    {
                        userBm = userResult.GetValue <UserBM>();
                    }

                    volunteerBm = new VolunteerBM(volunteerDto, addressBm, branchBm, userBm);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", volunteerBm));
            }
            catch (Exception exception) {
                return(new ResultBM(ResultBM.Type.EXCEPTION, "Se ha producido un error al recuperar el voluntario " + volunteerId + ".", exception));
            }
        }
Beispiel #2
0
        public ResultBM LogIn(string user, string password)
        {
            UserBLL userBll = new UserBLL();
            UserBM  userBm;

            LanguageBLL languageBll = new LanguageBLL();
            LanguageBM  languageBm;

            ProfileBLL profileBll = new ProfileBLL();
            ProfileBM  profileBm;

            DigitVerificatorBLL dvBll = new DigitVerificatorBLL();

            ResultBM result;

            try
            {
                //1. Validación input
                result = IsValid(user, password);

                if (result.IsValid())
                {
                    //2. Validación usuario
                    result = userBll.GetUser(user, password);

                    if (result.IsValid())
                    {
                        log.AddLogInfo("Autenticando", "Usuario " + user + " encontrado en la base de datos.", this);
                        userBm = result.GetValue <UserBM>();

                        //3. Recuperación de permisos
                        profileBm = profileBll.GetProfile(userBm.PermissionId).GetValue() as ProfileBM;

                        //4. Recuperación de idioma
                        languageBm = languageBll.GetLanguage(userBm.LanguageId);

                        //5. Armado de sesión
                        SessionHelper.StartSession(userBm, profileBm, languageBm);
                        log.AddLogDebug("Creando sesión", "Sesion para el usuario " + user + " creada.", this);

                        //6 Chequeo de consistencia horizontal
                        result = dvBll.IsHorizontallyConsistent(userBm);

                        if (!result.IsValid())
                        {
                            log.AddLogCritical("Dígito horizontal", "Falló la verificación horizontal al momento de chequear los datos del usuario " + user + ".", this);
                            //Sólo un admin puede continuar no es suficiente con que pueda restaurar
                            result = new ResultBM(ResultBM.Type.CORRUPTED_DATABASE, result.description, null, profileBm.HasPermission("GE999"));
                        }
                        else
                        {
                            //4.2 Chequeo de vertical
                            result = dvBll.IsVerticallyConsistent();

                            if (!result.IsValid())
                            {
                                log.AddLogCritical("Dígito vertical", "Falló la verificación vertical al momento de loguear al usuario " + user + ".", this);
                                //Sólo un admin puede continuar no es suficiente con que pueda restaurar
                                result = new ResultBM(ResultBM.Type.CORRUPTED_DATABASE, result.description, null, profileBm.HasPermission("GE999"));
                            }
                            else
                            {
                                log.AddLogInfo("Logueo", "El usuario " + user + " se ha logueado exitosamente.", this);
                                result = new ResultBM(ResultBM.Type.OK, "Inicio de sesión exitoso para el usuario " + user);
                            }
                        }
                    }
                    else
                    {
                        log.AddLogInfo("Autenticando", "Usuario " + user + " no ha sido encontrado en la base de datos.", this);
                    }
                }
            }
            catch (Exception exception)
            {
                result = new ResultBM(ResultBM.Type.EXCEPTION, exception.Message, exception, false);
            }

            return(result);
        }