Example #1
0
        public void UpdateResponsible()
        {
            //Prueba la asigna un responsable a la donación

            //Creación del donador, un empleado (persona), la donación y el voluntario
            DonorBM  donor    = create_donor();
            PersonBM personBm = create_person();

            DonationStatusBM statusBm       = get_status(1);
            DonationBLL      donationBll    = new DonationBLL();
            DonationBM       donationBm     = new DonationBM(3, donor.donorId, statusBm, "Esta es una donación creada por un test.");
            ResultBM         donationResult = donationBll.SaveDonation(donationBm);

            BranchBLL branchBll    = new BranchBLL();
            ResultBM  branchResult = branchBll.GetBranch(1);

            VolunteerBLL volunteerBll   = new VolunteerBLL();
            VolunteerBM  volunteerBm    = new VolunteerBM(personBm, branchResult.GetValue <BranchBM>());
            ResultBM     volunterResult = volunteerBll.SaveVolunteer(volunteerBm);

            donationBm.volunteer = volunterResult.GetValue <VolunteerBM>();
            ResultBM updateResult = donationBll.UpdateDonation(donationBm);

            Assert.IsTrue(updateResult.IsValid(), "La operación debería ser válida.");

            donationResult = donationBll.GetDonation(updateResult.GetValue <DonationBM>().id);
            Assert.IsTrue(donationResult.IsValid(), "La operación debería ser válida.");
            Assert.IsNotNull(donationResult.GetValue(), "Deería haber devuelto una donación.");
            Assert.IsNotNull(donationResult.GetValue <DonationBM>().volunteer, "Deería haber devuelto un voluntario.");
            Assert.AreEqual(donationResult.GetValue <DonationBM>().volunteer.volunteerId, volunterResult.GetValue <VolunteerBM>().volunteerId, "Debería ser el mismo voluntario.");
        }
Example #2
0
        /// <summary>
        /// Crea un beneficiario.
        /// </summary>
        /// <param name="beneficieryBm"></param>
        /// <returns></returns>
        public ResultBM SaveBeneficiary(BeneficiaryBM beneficieryBm)
        {
            try
            {
                BeneficiaryDAL beneficiaryDal = new BeneficiaryDAL();
                PersonBLL      personBll      = new PersonBLL();
                PersonBM       personBm       = null;
                ResultBM       validationResult; //agregar validación
                ResultBM       personResult;
                BeneficiaryDTO beneficiaryDto;

                // El validador no es necesario porque los datos sustanciales pertenecen a la persona
                personResult = personBll.SavePerson(beneficieryBm);
                if (!personResult.IsValid())
                {
                    return(personResult);
                }

                personBm       = personResult.GetValue() as PersonBM;
                beneficiaryDto = new BeneficiaryDTO(personBm.id, beneficieryBm.beneficiaryId, beneficieryBm.destination, beneficieryBm.ages, beneficieryBm.health, beneficieryBm.accessibility, beneficieryBm.majorProblem);

                beneficiaryDal.SaveBeneficiary(beneficiaryDto);
                beneficieryBm.beneficiaryId = beneficiaryDto.beneficiaryId;

                return(new ResultBM(ResultBM.Type.OK, "Se ha creado el beneficiario " + beneficieryBm.name + " " + beneficieryBm.lastName + ".", beneficieryBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("SAVING_ERROR") + " " + exception.Message, exception));
            }
        }
Example #3
0
        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));
            }
        }
Example #4
0
        public void CreatePersonInvalidDNI()
        {
            PersonBM personBm = new PersonBM("name test", "lastname test", DateTime.Now, "mail", "1553489636", 'M', 0, null);
            ResultBM result   = create_invalid_person(personBm);

            Assert.IsTrue(result.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido.");
            Assert.IsTrue(result.description.Contains("dni"), "No debería haber sido válido.");
        }
Example #5
0
        public void GetPerson()
        {
            PersonBM  personBm     = create_person();
            PersonBLL personBll    = new PersonBLL();
            ResultBM  personResult = personBll.GetPerson(personBm.id);

            Assert.IsTrue(personResult.IsValid(), "La persona debería haberse recuperado");
            Assert.AreEqual(personResult.GetValue <PersonBM>().id, personBm.id, "Los ids deberían coincidir.");
            Assert.AreEqual(personResult.GetValue <PersonBM>().Name, personBm.Name, "Los nombres deberían coincidir");
        }
Example #6
0
        private ResultBM create_invalid_person(PersonBM personBm)
        {
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            PersonBLL personBll = new PersonBLL();

            return(personBll.SavePerson(personBm));
        }
Example #7
0
        private DonorBM create_donor()
        {
            //Crea un donador
            OrganizationBLL organizationBll = new OrganizationBLL();
            ResultBM        result          = organizationBll.GetOrganization(1);
            PersonBM        personBm        = create_person();
            DonorBM         donorBm         = new DonorBM(true, personBm, result.GetValue <OrganizationBM>());
            DonorBLL        donorBll        = new DonorBLL();
            ResultBM        saveResult      = donorBll.SaveDonor(donorBm);

            Assert.IsTrue(saveResult.IsValid(), "El donador debería haberse creado.");
            return(saveResult.GetValue <DonorBM>());
        }
Example #8
0
        public void CreateVolunteerFailsBranch()
        {
            //Crea un donador
            PersonBM personBm = create_person();

            VolunteerBLL volunteerBll   = new VolunteerBLL();
            VolunteerBM  volunteerBm    = new VolunteerBM(personBm, null);
            ResultBM     volunterResult = volunteerBll.SaveVolunteer(volunteerBm);

            Assert.IsFalse(volunterResult.IsValid(), "El voluntario debería existir.");
            Assert.IsTrue(volunterResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido.");
            Assert.IsNull(volunterResult.GetValue(), "No debería existir el voluntario.");
        }
Example #9
0
        /// <summary>
        /// Crea un nuevo donador.
        /// </summary>
        /// <param name="donorBm"></param>
        /// <returns></returns>
        public ResultBM SaveDonor(DonorBM donorBm)
        {
            try
            {
                OrganizationBLL organizationBll    = new OrganizationBLL();
                ResultBM        resultOrganization = null;
                OrganizationBM  organizationBm     = null;
                DonorDAL        donorDal           = new DonorDAL();
                PersonBLL       personBll          = new PersonBLL();
                PersonBM        personBm           = null;
                ResultBM        validationResult;
                ResultBM        personResult;
                DonorDTO        donorDto;

                // El validador no es necesario porque el donador es una combinación de otras entidades que ya poseen validadores.
                validationResult = IsValid(donorBm);
                if (!validationResult.IsValid())
                {
                    return(validationResult);
                }

                personResult = personBll.SavePerson(donorBm);
                if (!personResult.IsValid())
                {
                    return(personResult);
                }

                if (donorBm.organization != null)
                {
                    resultOrganization = organizationBll.SaveOrganization(donorBm.organization);
                    if (!resultOrganization.IsValid())
                    {
                        return(resultOrganization);
                    }
                    //if (resultOrganization.GetValue() == null) return new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("SAVING_ERROR"), resultOrganization);

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

                personBm = personResult.GetValue() as PersonBM;
                donorDto = new DonorDTO(personBm.id, donorBm.donorId, organizationBm == null ? 0 : organizationBm.id, donorBm.CanBeContacted);
                donorDal.SaveDonor(donorDto);
                donorBm.donorId = donorDto.donorId;

                return(new ResultBM(ResultBM.Type.OK, "Se ha creado el donador " + donorBm.name + " " + donorBm.lastName + ".", donorBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("SAVING_ERROR") + " " + exception.Message, exception));
            }
        }
Example #10
0
        private PersonBM create_person()
        {
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  countryBm  = result.GetValue <CountryBM>();
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", countryBm);

            PersonBLL personBll  = new PersonBLL();
            PersonBM  personBm   = new PersonBM("Name test", "lastname test", DateTime.Now, "mail", "1553489636", 'M', 29192646, addressBm);
            ResultBM  saveResult = personBll.SavePerson(personBm);

            Assert.IsTrue(saveResult.IsValid(), "La persona debería haberse creado");
            return(saveResult.GetValue <PersonBM>());
        }
Example #11
0
        public void CreateVolunteer()
        {
            //Crea un donador
            PersonBM personBm = create_person();

            BranchBLL branchBll   = new BranchBLL();
            ResultBM  brancResult = branchBll.GetBranch(1);

            Assert.IsTrue(brancResult.IsValid(), "El donador debería existir.");

            VolunteerBLL volunteerBll   = new VolunteerBLL();
            VolunteerBM  volunteerBm    = new VolunteerBM(personBm, brancResult.GetValue <BranchBM>());
            ResultBM     volunterResult = volunteerBll.SaveVolunteer(volunteerBm);

            Assert.IsTrue(volunterResult.IsValid(), "El donador debería existir.");
            Assert.IsNotNull(volunterResult.GetValue(), "Debería existir el voluntario.");
            Assert.IsTrue(volunterResult.GetValue <VolunteerBM>().id > 0, "Debería existir el voluntario.");
        }
Example #12
0
        private ResultBM IsValid(PersonBM personBm)
        {
            if (personBm.name == null || personBm.name.Length == 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (NAME)"));
            }

            if (personBm.lastName == null || personBm.lastName.Length == 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (LASTNAME)"));
            }

            if (personBm.dni < 1 || personBm.dni.ToString().Length < 8)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("INVALID_VALUE_ERROR") + " (DNI)"));
            }

            return(new ResultBM(ResultBM.Type.OK));
        }
Example #13
0
        public ResultBM SaveVolunteer(VolunteerBM volunteerBm)
        {
            try
            {
                PersonBLL    personBll = new PersonBLL();
                PersonBM     personBm  = null;
                ResultBM     personResult;
                VolunteerDAL volunteerDal = new VolunteerDAL();
                VolunteerDTO volunteerDto = null;

                ResultBM validResult = IsValid(volunteerBm);

                if (validResult.IsValid())
                {
                    personResult = personBll.SavePerson(volunteerBm);

                    if (personResult.IsValid())
                    {
                        personBm     = personResult.GetValue() as PersonBM;
                        volunteerDto = new VolunteerDTO(personBm.id, volunteerBm.branch.id, volunteerBm.user == null ? 0 : volunteerBm.user.Id);
                        volunteerDal.SaveVolunteer(volunteerDto);
                        volunteerBm.volunteerId = volunteerDto.volunteerId;

                        return(new ResultBM(ResultBM.Type.OK, "Voluntario guardado.", volunteerBm));
                    }
                    else
                    {
                        return(personResult);
                    }
                }
                else
                {
                    return(validResult);
                }
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, "Se ha producido un error al guardar el volunatio.", exception));
            }
        }
Example #14
0
        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));
            }
        }