Example #1
0
        public ResultBM GetBranch(int branchId)
        {
            try
            {
                AddressBLL addressBll    = new AddressBLL();
                ResultBM   addressResult = null;
                BranchDAL  branchDal     = new BranchDAL();
                BranchDTO  branchDto     = branchDal.GetBranch(branchId);
                BranchBM   branchBm      = null;

                //Si la sede existe, debería existir la dirección
                if (branchDto != null)
                {
                    addressResult = addressBll.GetAddress(branchDto.addressId);

                    if (addressResult.IsValid())
                    {
                        if (addressResult.GetValue() != null)
                        {
                            branchBm = new BranchBM(branchDto, addressResult.GetValue <AddressBM>());
                        }
                        else
                        {
                            return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR")));
                        }
                    }
                    else
                    {
                        return(addressResult);
                    }
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", branchBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
Example #2
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));
            }
        }