Esempio n. 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.");
        }
Esempio n. 2
0
        public void GetDonor()
        {
            //Crea un donador
            DonorBM  donorBm     = create_donor();
            DonorBLL donorBll    = new DonorBLL();
            ResultBM donorResult = donorBll.GetDonor(donorBm.donorId);

            Assert.IsTrue(donorResult.IsValid(), "El donador debería existir.");
        }
Esempio n. 3
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));
            }
        }
Esempio n. 4
0
 private void CompleteCompanyData(DonorBM donor)
 {
     if (donor.organization != null)
     {
         txtCompany.Text      = donor.organization.name;
         txtCategory.Text     = donor.organization.category;
         txtMailCmpny.Text    = donor.organization.email;
         txtPhoneCmpny.Text   = donor.organization.phone;
         txtCommentCmpny.Text = donor.organization.comment;
     }
 }
Esempio n. 5
0
 private void CompletePersonData(DonorBM donor)
 {
     txtName.Text          = donor.name;
     txtLastName.Text      = donor.lastName;
     dateBirthday.Value    = donor.Birthdate;
     txtMail.Text          = donor.Email;
     txtPhone.Text         = donor.phone;
     rbuttonFemale.Checked = donor.gender == 'F';
     rButtonMale.Checked   = donor.gender == 'M';
     txtDocument.Text      = donor.dni.ToString();
     chkBoxContact.Checked = donor.CanBeContacted;
 }
Esempio n. 6
0
        public void CreateDonationFailsStatus()
        {
            //Prueba la validación cuando el estado no es provisto
            DonorBM     donor       = create_donor();
            DonationBLL donationBll = new DonationBLL();
            DonationBM  donationBm  = new DonationBM(2, donor.donorId, null);

            ResultBM donationResult = donationBll.SaveDonation(donationBm);

            Assert.IsFalse(donationResult.IsValid(), "La donación no debería ser válida.");
            Assert.IsNotNull(donationResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "El error debería ser campo incompleto.");
            Assert.AreEqual(donationResult.description, "Debe selecionar un estado válido para el lote.", "El error debería coincidir.");
        }
Esempio n. 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>());
        }
Esempio n. 8
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));
            }
        }
Esempio n. 9
0
        public void CreateDonationFailsItems()
        {
            //Prueba la validación cuando la cantidad de items no es la menos 1
            DonorBM          donor       = create_donor();
            DonationStatusBM statusBm    = get_status(1);
            DonationBLL      donationBll = new DonationBLL();
            DonationBM       donationBm  = new DonationBM(0, donor.donorId, statusBm);

            ResultBM donationResult = donationBll.SaveDonation(donationBm);

            Assert.IsFalse(donationResult.IsValid(), "La donación no debería ser válida.");
            Assert.IsNotNull(donationResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "El error debería ser campo incompleto.");
            Assert.AreEqual(donationResult.description, "La cantidad de bultos debe ser de al menos una unidad.", "El error debería coincidir.");
        }
Esempio n. 10
0
        public void CreateDonationNullComment()
        {
            //Crea una donación
            DonorBM          donor       = create_donor();
            DonationStatusBM statusBm    = get_status(1);
            DonationBLL      donationBll = new DonationBLL();
            DonationBM       donationBm  = new DonationBM(21, donor.donorId, statusBm);

            ResultBM donationResult = donationBll.SaveDonation(donationBm);

            Assert.IsTrue(donationResult.IsValid(), "La donación debería ser válida.");
            Assert.IsNotNull(donationResult.GetValue(), "Debería haber devuelto la donación.");
            Assert.IsNull(donationResult.GetValue <DonationBM>().Comment, "No debería poseer comentario");
        }
Esempio n. 11
0
 public ResultBM Delete(object entity)
 {
     try
     {
         DonorDAL donodrDal = new DonorDAL();
         DonorBM  donodrBm  = entity as DonorBM;
         donodrDal.DeleteDonor(donodrBm.donorId);
         return(new ResultBM(ResultBM.Type.OK, "Se ha eliminado el registro.", donodrBm));
     }
     catch (Exception exception)
     {
         return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("DELETING_ERROR") + " " + exception.Message, exception));
     }
 }
Esempio n. 12
0
        public void CreateDonation()
        {
            //Crea una donación
            DonorBM          donor       = create_donor();
            DonationStatusBM statusBm    = get_status(1);
            DonationBLL      donationBll = new DonationBLL();
            DonationBM       donationBm  = new DonationBM(21, donor.donorId, statusBm, "Esta es una donación creada por un test.");

            ResultBM donationResult = donationBll.SaveDonation(donationBm);

            Assert.IsTrue(donationResult.IsValid(), "La donación debería ser válida.");
            Assert.IsNotNull(donationResult.GetValue(), "Deería haber devuelto una donación.");
            Assert.IsTrue(donationResult.GetValue <DonationBM>().id > 0, "El id debería ser mayor a cero.");
            Assert.AreEqual(donationResult.GetValue <DonationBM>().Comment, "Esta es una donación creada por un test.", "Debería poseer comentario");
        }
Esempio n. 13
0
 private void FillPersonData(DonorBM donor)
 {
     //Completa los datos básicos del donador
     donor.name      = txtName.Text;
     donor.lastName  = txtLastName.Text;
     donor.Birthdate = dateBirthday.Value;
     donor.Email     = txtMail.Text;
     donor.phone     = txtPhone.Text;
     donor.gender    = rbuttonFemale.Checked? 'F' : 'M';
     if (txtDocument.Text.Length == 0)
     {
         txtDocument.Text = "0";
     }
     donor.dni            = int.Parse(txtDocument.Text);
     donor.CanBeContacted = chkBoxContact.Checked;
 }
Esempio n. 14
0
 private void FillAddressData(DonorBM donor)
 {
     //Completa los datos catastrales del donador
     if (donor.address == null)
     {
         donor.address = new AddressBM();
     }
     donor.address.street = txtStreet.Text;
     if (txtNumber.Text.Length == 0)
     {
         txtNumber.Text = "0";
     }
     donor.address.number    = int.Parse(txtNumber.Text);
     donor.address.apartment = txtApartment.Text;
     donor.address.comment   = txtComment.Text;
     donor.address.country   = cmbCountry.SelectedItem as CountryBM;
 }
Esempio n. 15
0
        private void CompleteAddressData(DonorBM donor)
        {
            txtStreet.Text    = donor.address.street;
            txtNumber.Text    = donor.address.number.ToString();
            txtApartment.Text = donor.address.apartment;
            txtComment.Text   = donor.address.comment;

            bool found = false;

            for (int i = 0; i < cmbCountry.Items.Count && !found; ++i)
            {
                found = ((CountryBM)cmbCountry.Items[i]).iso2 == donor.address.country.iso2;
                if (found)
                {
                    cmbCountry.SelectedIndex = i;
                }
            }
        }
Esempio n. 16
0
        private void FillCompanyData(DonorBM donor)
        {
            // Si se imputó algo, entonces se crea el objeto compañía
            int input = txtCompany.Text.Length + txtCategory.Text.Length + txtMailCmpny.Text.Length + txtPhoneCmpny.Text.Length + txtCommentCmpny.Text.Length;

            if (input > 0 && donor.organization == null)
            {
                donor.organization = new OrganizationBM();
            }

            if (donor.organization != null)
            {
                donor.organization.name     = txtCompany.Text;
                donor.organization.category = txtCategory.Text;
                donor.organization.email    = txtMailCmpny.Text;
                donor.organization.phone    = txtPhoneCmpny.Text;
                donor.organization.comment  = txtCommentCmpny.Text;
            }
        }
Esempio n. 17
0
        private void FrmDonor_Load(object sender, EventArgs e)
        {
            try
            {
                //Traducciones
                SessionHelper.RegisterForTranslation(this, Codes.MNU_GE009);
                SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT);
                SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE);

                SessionHelper.RegisterForTranslation(lblName, Codes.LBL_NAME);
                SessionHelper.RegisterForTranslation(lblLastName, Codes.LBL_LAST_NAME);
                SessionHelper.RegisterForTranslation(lblBirthday, Codes.LBL_BIRTHDAY);
                SessionHelper.RegisterForTranslation(lblMail, Codes.LBL_EMAIL);
                SessionHelper.RegisterForTranslation(lblPhone, Codes.LBL_PHONE);
                SessionHelper.RegisterForTranslation(rbuttonFemale, Codes.LBL_FEMALE);
                SessionHelper.RegisterForTranslation(rButtonMale, Codes.LBL_MALE);
                SessionHelper.RegisterForTranslation(lblDocument, Codes.LBL_UID);

                SessionHelper.RegisterForTranslation(lblStreet, Codes.LBL_STREET);
                SessionHelper.RegisterForTranslation(lblNumber, Codes.LBL_NUMBER);
                SessionHelper.RegisterForTranslation(lblApartment, Codes.LBL_APARTMENT);
                SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION);

                SessionHelper.RegisterForTranslation(lblCountry, Codes.LBL_COUNTRY);
                SessionHelper.RegisterForTranslation(lblCompany, Codes.LBL_COMPANY);
                SessionHelper.RegisterForTranslation(lblCategory, Codes.LBL_CATEGORY);
                SessionHelper.RegisterForTranslation(lblCommentCpny, Codes.LBL_OBSERVATION);
                SessionHelper.RegisterForTranslation(lblMailCmpny, Codes.LBL_EMAIL);
                SessionHelper.RegisterForTranslation(lblPhoneCmpny, Codes.LBL_PHONE);
                SessionHelper.RegisterForTranslation(chkBoxContact, Codes.LBL_CAN_CONTACT);

                ResultBM countryResult = new CountryBLL().GetCountries();
                cmbCountry.DataSource    = countryResult.GetValue <List <CountryBM> >();
                cmbCountry.DisplayMember = "Name";

                if (IsUpdate)
                {
                    DonorBLL donorBll    = new DonorBLL();
                    ResultBM resultDonor = donorBll.GetDonor(entity.donorId);

                    if (resultDonor.IsValid())
                    {
                        this.Entity = resultDonor.GetValue <DonorBM>();

                        CompletePersonData(this.Entity);
                        CompleteAddressData(this.Entity);
                        CompleteCompanyData(this.Entity);
                    }
                    else
                    {
                        MessageBox.Show(resultDonor.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    entity = new DonorBM();
                }
            }
            catch (Exception exception) {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 18
0
 public ResultBM IsValid(DonorBM donorBm)
 {
     //Un donador es una persona con un conjunto de valores cuyas entidades base se encargan de validar lo que haga falta
     return(new ResultBM(ResultBM.Type.OK));
 }