Пример #1
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));
            }
        }
Пример #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));
            }
        }
Пример #3
0
        private ResultBM IsValid(OrganizationBM organization)
        {
            if (organization == null)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("INVALID_VALUE_ERROR") + " (ALL)"));
            }

            if (organization.name == null || organization.name.Length == 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (NAME)"));
            }

            return(new ResultBM(ResultBM.Type.OK));
        }
Пример #4
0
        public ResultBM GetOrganization(int organizationId)
        {
            try
            {
                OrganizationDAL organizationDal = new OrganizationDAL();
                OrganizationDTO organizationDto = organizationDal.GetOrganization(organizationId);
                OrganizationBM  organizationBm  = null;

                if (organizationDto != null)
                {
                    organizationBm = new OrganizationBM(organizationDto);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", organizationBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
Пример #5
0
        public ResultBM SaveOrganization(OrganizationBM organizationBm)
        {
            try
            {
                OrganizationDAL organizationDal = new OrganizationDAL();
                OrganizationDTO organizationDto;
                ResultBM        resultValidation = IsValid(organizationBm);

                if (!resultValidation.IsValid())
                {
                    return(resultValidation);
                }

                organizationDto = new OrganizationDTO(organizationBm.name, organizationBm.category, organizationBm.comment, organizationBm.phone, organizationBm.email);
                organizationDal.UpdateOrganization(organizationDto);

                return(new ResultBM(ResultBM.Type.OK, "Organización actualizada.", organizationBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, "Se ha producido un error al crear la organización " + organizationBm.name + ".", exception));
            }
        }
Пример #6
0
        public ResultBM UpdateOrganization(OrganizationBM organizationBm)
        {
            try
            {
                OrganizationDAL organizationDal = new OrganizationDAL();
                OrganizationDTO organizationDto;
                ResultBM        resultValidation = IsValid(organizationBm);

                if (!resultValidation.IsValid())
                {
                    return(resultValidation);
                }

                organizationDto = new OrganizationDTO(organizationBm.name, organizationBm.category, organizationBm.comment, organizationBm.phone, organizationBm.email);
                organizationDal.SaveOrganization(organizationDto);
                organizationBm.id = organizationDto.id;

                return(new ResultBM(ResultBM.Type.OK, "Organización guardada.", organizationBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }