コード例 #1
0
        /// <summary>
        /// Recupera los datos de un beneficiario.
        /// </summary>
        /// <param name="beneficiaryId"></param>
        /// <returns></returns>
        public ResultBM GetBeneficiary(int beneficiaryId)
        {
            try
            {
                AddressBLL     addressBll     = new AddressBLL();
                ResultBM       addressResult  = null;
                BeneficiaryDAL beneficiaryDal = new BeneficiaryDAL();
                BeneficiaryBM  beneficiaryBm  = null;
                BeneficiaryDTO beneficiaryDto = beneficiaryDal.GetBeneficiary(beneficiaryId);

                if (beneficiaryDto != null)
                {
                    addressResult = addressBll.GetAddress(beneficiaryDto.addressId);

                    //Si hubo algún problema o la dirección no existe, entonces hay que devolver el resultado o lanzar una excepción (debería eixstir)
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " addressId " + beneficiaryDto.addressId);
                    }

                    beneficiaryBm = new BeneficiaryBM(beneficiaryDto, addressResult.GetValue <AddressBM>());
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", beneficiaryBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
コード例 #2
0
        public ResultBM GetDepot(int depotId)
        {
            try
            {
                AddressBLL addressBll    = new AddressBLL();
                ResultBM   addressResult = null;
                DepotDAL   depotDal      = new DepotDAL();
                DepotDTO   depotDto      = depotDal.GetDepot(depotId);
                DepotBM    depotBm       = null;

                //Si existe el depósito debe existir la dirección
                if (depotDto != null)
                {
                    addressResult = addressBll.GetAddress(depotDto.addressId);
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception("La dirección " + depotDto.addressId + " para el depósito " + depotId + " no existe.");
                    }

                    depotBm = new DepotBM(depotDto, addressResult.GetValue <AddressBM>());
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", depotBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
コード例 #3
0
ファイル: PersonBLL.cs プロジェクト: mkaimakamian/TDC2017
        public ResultBM UpdatePerson(PersonBM personBm)
        {
            try {
                AddressBLL addressBll = new AddressBLL();
                ResultBM   addressResult;
                PersonDAL  personDal = new PersonDAL();
                PersonDTO  personDto;
                ResultBM   validationResult;

                validationResult = IsValid(personBm);
                if (!validationResult.IsValid())
                {
                    return(validationResult);
                }

                addressResult = addressBll.UpdateAddress(personBm.address);
                if (!addressResult.IsValid())
                {
                    return(addressResult);
                }

                personDto = new PersonDTO(personBm.id, personBm.name, personBm.lastName, personBm.Birthdate, personBm.Email, personBm.phone, personBm.gender, personBm.dni, personBm.address.id);
                personDal.UpdatePerson(personDto);

                return(new ResultBM(ResultBM.Type.OK, "Se ha actualizado la persona con el nombre " + personBm.name + " " + personBm.lastName + ".", personBm));
            }
            catch (Exception exception) {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
コード例 #4
0
        public ResultBM GetDonor(int donorId)
        {
            try
            {
                AddressBLL      addressBll         = new AddressBLL();
                ResultBM        addressResult      = null;
                OrganizationBLL organizationBll    = new OrganizationBLL();
                OrganizationBM  organizationBm     = null;
                ResultBM        resultOrganization = null;
                DonorDAL        donorDal           = new DonorDAL();
                DonorBM         donorBm            = null;

                DonorDTO donorDto = donorDal.GetDonor(donorId);

                // Si el donador existe, deb existir la persona
                if (donorDto != null)
                {
                    addressResult = addressBll.GetAddress(donorDto.addressId);

                    //Si hubo algún problema o la dirección no existe, entonces hay que devolver el resultado o lanzar una excepción (debería eixstir)
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " addressId " + donorDto.addressId);
                    }

                    // Podría no pertenecer a una organización, de modo tal que si no posee relación, está bien
                    if (donorDto.organizationId != 0)
                    {
                        resultOrganization = organizationBll.GetOrganization(donorDto.organizationId);

                        if (!resultOrganization.IsValid())
                        {
                            return(resultOrganization);
                        }
                        if (resultOrganization.GetValue() == null)
                        {
                            throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " organizationId " + donorDto.organizationId);
                        }

                        organizationBm = resultOrganization.GetValue <OrganizationBM>();
                    }

                    donorBm = new DonorBM(donorDto, addressResult.GetValue <AddressBM>(), organizationBm);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", donorBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
コード例 #5
0
ファイル: BranchBLL.cs プロジェクト: mkaimakamian/TDC2017
        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));
            }
        }
コード例 #6
0
ファイル: PersonBLL.cs プロジェクト: mkaimakamian/TDC2017
        public ResultBM GetPerson(int personId)
        {
            try
            {
                AddressBLL addressBll    = new AddressBLL();
                ResultBM   resultAddress = null;
                PersonDAL  personDal     = new PersonDAL();
                PersonBM   personBm      = null;
                PersonDTO  personDto     = personDal.GetPerson(personId);

                // Si la persona existe, debería existir la dirección.
                if (personDto != null)
                {
                    resultAddress = addressBll.GetAddress(personDto.addressId);
                    if (!resultAddress.IsValid())
                    {
                        return(resultAddress);
                    }

                    if (resultAddress.GetValue() != null)
                    {
                        personBm = new PersonBM(personDto, resultAddress.GetValue <AddressBM>());
                    }
                    else
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " addressId " + personDto.addressId);
                    }
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", personBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
コード例 #7
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));
            }
        }
コード例 #8
0
        //No está bueno esto, pero me permite recuperar las direcciones. Poco performante... pero no hay tiempo.
        private AddressBM GetAddress(BeneficiaryDTO beneficiary)
        {
            ResultBM addressResult = new AddressBLL().GetAddress(beneficiary.addressId);

            return(addressResult.GetValue <AddressBM>());
        }
コード例 #9
0
        //No está bueno esto, pero me permite recuperar las direcciones. Poco performante... pero no hay tiempo.
        private AddressBM GetAddress(DonorDTO donorDto)
        {
            ResultBM addressResult = new AddressBLL().GetAddress(donorDto.addressId);

            return(addressResult.GetValue <AddressBM>());
        }