Ejemplo n.º 1
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));
            }
        }
Ejemplo n.º 2
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));
            }
        }
Ejemplo n.º 3
0
 private void FillGauges(BeneficiaryBM beneficiaryBm)
 {
     beneficiaryBm.destination   = trkDestination.Value;
     beneficiaryBm.ages          = trkAges.Value;
     beneficiaryBm.health        = trkHealth.Value;
     beneficiaryBm.accessibility = trkAccessibility.Value;
     beneficiaryBm.majorProblem  = trkMajor.Value;
 }
Ejemplo n.º 4
0
 private void SetGauges(BeneficiaryBM beneficiaryBm)
 {
     trkDestination.Value   = beneficiaryBm.destination;
     trkAges.Value          = beneficiaryBm.ages;
     trkHealth.Value        = beneficiaryBm.health;
     trkAccessibility.Value = beneficiaryBm.accessibility;
     trkMajor.Value         = beneficiaryBm.majorProblem;
 }
Ejemplo n.º 5
0
 private void CompletePersonData(BeneficiaryBM beneficiaryBm)
 {
     txtName.Text          = beneficiaryBm.name;
     txtLastName.Text      = beneficiaryBm.lastName;
     dateBirthday.Value    = beneficiaryBm.Birthdate;
     txtMail.Text          = beneficiaryBm.Email;
     txtPhone.Text         = beneficiaryBm.phone;
     rbuttonFemale.Checked = beneficiaryBm.gender == 'F';
     rButtonMale.Checked   = beneficiaryBm.gender == 'M';
     txtDocument.Text      = beneficiaryBm.dni.ToString();
 }
Ejemplo n.º 6
0
 public ResultBM Delete(object entity)
 {
     try
     {
         BeneficiaryDAL beneficiaryDal = new BeneficiaryDAL();
         BeneficiaryBM  beneficiaryBm  = entity as BeneficiaryBM;
         beneficiaryDal.DeleteBeneficiary(beneficiaryBm.beneficiaryId);
         return(new ResultBM(ResultBM.Type.OK, "Se ha eliminado el registro.", beneficiaryBm));
     }
     catch (Exception exception)
     {
         return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("DELETING_ERROR") + " " + exception.Message, exception));
     }
 }
Ejemplo n.º 7
0
 private void FillPersonData(BeneficiaryBM beneficiaryBm)
 {
     //Completa los datos básicos del beneficiario
     beneficiaryBm.name      = txtName.Text;
     beneficiaryBm.lastName  = txtLastName.Text;
     beneficiaryBm.Birthdate = dateBirthday.Value;
     beneficiaryBm.Email     = txtMail.Text;
     beneficiaryBm.phone     = txtPhone.Text;
     beneficiaryBm.gender    = rbuttonFemale.Checked ? 'F' : 'M';
     if (txtDocument.Text.Length == 0)
     {
         txtDocument.Text = "0";
     }
     beneficiaryBm.dni = int.Parse(txtDocument.Text);
 }
Ejemplo n.º 8
0
 private void FillAddressData(BeneficiaryBM beneficiaryBm)
 {
     //Completa los datos catastrales del beneficiario
     if (beneficiaryBm.address == null)
     {
         beneficiaryBm.address = new AddressBM();
     }
     beneficiaryBm.address.street = txtStreet.Text;
     if (txtNumber.Text.Length == 0)
     {
         txtNumber.Text = "0";
     }
     beneficiaryBm.address.number    = int.Parse(txtNumber.Text);
     beneficiaryBm.address.apartment = txtApartment.Text;
     beneficiaryBm.address.comment   = txtComment.Text;
     beneficiaryBm.address.country   = cmbCountry.SelectedItem as CountryBM;
 }
Ejemplo n.º 9
0
        private void CompleteAddressData(BeneficiaryBM beneficiaryBm)
        {
            txtStreet.Text    = beneficiaryBm.address.street;
            txtNumber.Text    = beneficiaryBm.address.number.ToString();
            txtApartment.Text = beneficiaryBm.address.apartment;
            txtComment.Text   = beneficiaryBm.address.comment;

            bool found = false;

            for (int i = 0; i < cmbCountry.Items.Count && !found; ++i)
            {
                found = ((CountryBM)cmbCountry.Items[i]).iso2 == beneficiaryBm.address.country.iso2;
                if (found)
                {
                    cmbCountry.SelectedIndex = i;
                }
            }
        }
Ejemplo n.º 10
0
        private void FrmBeneficiary_Load(object sender, EventArgs e)
        {
            try {
                //Traducciones
                SessionHelper.RegisterForTranslation(this, Codes.MNU_GE014);
                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(lblDestination, Codes.LBL_DESTINATARY);
                SessionHelper.RegisterForTranslation(lblAges, Codes.LBL_AGE_RANGE);
                SessionHelper.RegisterForTranslation(lblHealth, Codes.LBL_SALUBRITY);
                SessionHelper.RegisterForTranslation(lblAccesibility, Codes.LBL_ACCESSIBILITY);
                SessionHelper.RegisterForTranslation(lblMajor, Codes.LBL_MAJOR_PROBLEM);

                SessionHelper.RegisterForTranslation(lblDescDestinatary, Codes.LBL_DESC_DESTINATARY);
                SessionHelper.RegisterForTranslation(lblDescAges, Codes.LBL_DESC_AGE_RANGE);
                SessionHelper.RegisterForTranslation(lblDescHealth, Codes.LBL_DESC_SALUBRITY);
                SessionHelper.RegisterForTranslation(lblDescAccessibility, Codes.LBL_DESC_ACCESSIBILITY);
                SessionHelper.RegisterForTranslation(lblDescMajor, Codes.LBL_DESC_MAJOR_PROBLEM);

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

                if (IsUpdate)
                {
                    BeneficiaryBLL beneficiaryBll    = new BeneficiaryBLL();
                    ResultBM       resultBeneficiary = beneficiaryBll.GetBeneficiary(this.Entity.beneficiaryId);

                    if (resultBeneficiary.IsValid())
                    {
                        this.Entity = resultBeneficiary.GetValue <BeneficiaryBM>();

                        CompletePersonData(this.Entity);
                        CompleteAddressData(this.Entity);
                        SetGauges(this.Entity);
                    }
                    else
                    {
                        MessageBox.Show(resultBeneficiary.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    entity = new BeneficiaryBM();
                }
            }
            catch (Exception exception) {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }