Esempio 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));
            }
        }
Esempio n. 2
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. 3
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));
            }
        }