Beispiel #1
0
        public ResultBM GetDepot(int depotId)
        {
            try
            {
                AddressBLL addressBll    = new AddressBLL();
                ResultBM   addressResult = null;
                DepotDAL   depotDal      = new DepotDAL();
                DepotDTO   depotDto      = depotDal.GetDepot(depotId);
                DepotBM    depotBm       = null;

                //Si existe el depósito debe existir la dirección
                if (depotDto != null)
                {
                    addressResult = addressBll.GetAddress(depotDto.addressId);
                    if (!addressResult.IsValid())
                    {
                        return(addressResult);
                    }
                    if (addressResult.GetValue() == null)
                    {
                        throw new Exception("La dirección " + depotDto.addressId + " para el depósito " + depotId + " no existe.");
                    }

                    depotBm = new DepotBM(depotDto, addressResult.GetValue <AddressBM>());
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", depotBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
        public ResultBM SaveReleaseOrderDetail(ReleaseOrderBM releaseOrderBm)
        {
            try
            {
                ReleaseOrderDetailDAL        detailDal  = new ReleaseOrderDetailDAL();
                ReleaseOrderDetailDTO        detailDto  = null;
                List <ReleaseOrderDetailDTO> listDetail = new List <ReleaseOrderDetailDTO>();
                ResultBM validResult = IsValid(releaseOrderBm.detail);

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

                foreach (ReleaseOrderDetailBM detail in releaseOrderBm.detail)
                {
                    detailDto = new ReleaseOrderDetailDTO();
                    detailDto.releaseOrderId = releaseOrderBm.id;
                    detailDto.quantity       = detail.Quantity;
                    detailDto.stockId        = detail.stock.id;
                    listDetail.Add(detailDto);
                }
                detailDal.SaveReleaseOrderDetail(listDetail);

                return(new ResultBM(ResultBM.Type.OK, "Detalle guardado para la orden " + releaseOrderBm.id + ".", releaseOrderBm.detail));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("SAVING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #3
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));
            }
        }
        /// <summary>
        /// Controla la consistencia vertical de todas las entidades críticas
        /// </summary>
        /// <returns></returns>
        public ResultBM IsVerticallyConsistent()
        {
            Dictionary <string, string> entityToCheck = new Dictionary <string, string>();
            DigitVerificatorDAL         dvDal         = new DigitVerificatorDAL();
            List <DigitVerificatorDTO>  digits;

            UserBLL  userBll              = new UserBLL();
            ResultBM usersBms             = userBll.GetUsers();
            List <DigitVeryficator> users = usersBms.GetValue <List <UserBM> >().Cast <DigitVeryficator>().ToList();

            //TODO - Evaluar la posibilidad de ir a buscar a vdv el listado de entidades, y luego ir  a buscarlas

            // La estrategia consiste en crear un diccionario que posea como key la entidad a controlar,
            //y como value un string construido en base a los dígitos horizontales de cada uno de sus registros
            entityToCheck.Add(USER_TABLE, this.GetStringToCheck(users));

            digits = dvDal.GetEntityDigits();

            // En base a las entidades que poseen integridad vertical, se recorre la lista de entidades a chequear
            foreach (DigitVerificatorDTO entityVDV in digits)
            {
                if (!SecurityHelper.IsEquivalent(entityToCheck[entityVDV.entity], entityVDV.vdv))
                {
                    return(new ResultBM(ResultBM.Type.CORRUPTED_DATABASE, SessionHelper.GetTranslation("CORRUPTED_DATABASE_ERROR") + " (VERTICAL - " + entityVDV.entity + ")"));
                }
            }

            return(new ResultBM(ResultBM.Type.OK, "Dígito vertical correcto."));
        }
Beispiel #5
0
        /// <summary>
        /// Crea un perfil en base al modelo recibido, considerando únicamente los hijos del primer nivel.
        /// </summary>
        /// <param name="profile"></param>
        /// <returns></returns>
        public ResultBM CreateProfile(ProfileBM profile)
        {
            try
            {
                log.AddLogInfo("Creando perfil", "Creando perfil.", this);
                ProfileDAL profileDal    = new ProfileDAL();
                ResultBM   isValidResult = IsValid(profile);

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

                //Se agrega el root
                PermissionDTO root = new PermissionDTO(profile.fatherCode, profile.code, profile.Description);
                profileDal.SaveProfile(root);
                CreateRelation(profile);

                log.AddLogInfo("Creando perfil", "El perfil se ha creado exitosamente.", this);
                return(new ResultBM(ResultBM.Type.OK, "Perfil creado: " + profile.Description));
            }
            catch (Exception exception)
            {
                log.AddLogCritical("Recuperando perfil", exception.Message, this);
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("SAVING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #6
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.");
        }
Beispiel #7
0
        private void LoadDonations()
        {
            cmbDonation.SelectedIndexChanged -= cmbDonation_SelectedIndexChanged;

            DonationBLL donationBll    = new DonationBLL();
            ResultBM    donationResult = donationBll.GetAvaliableDonations();

            if (!donationResult.IsValid())
            {
                MessageBox.Show(donationResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                List <DonationBM> lstDonation = donationResult.GetValue <List <DonationBM> >();
                cmbDonation.DataSource    = lstDonation;
                cmbDonation.DisplayMember = "Lot";

                if (lstDonation.Count == 0)
                {
                    MessageBox.Show("No existen donaciones que puedan ser procesadas para su loteo.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cmdAccept.Enabled = false;
                }
            }
            cmbDonation.SelectedIndexChanged += cmbDonation_SelectedIndexChanged;
        }
Beispiel #8
0
        private void BtnAccess_Click(object sender, EventArgs e)
        {
            try
            {
                LoginBLL loginBll = new LoginBLL();
                ResultBM result   = loginBll.LogIn(TxtUser.Text, TxtPassword.Text);

                if (result.IsValid())
                {
                    FrmMain frmPrincipal = new FrmMain();
                    frmPrincipal.loginReference = this;
                    frmPrincipal.Show();
                }
                else
                {
                    MessageBox.Show(result.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    if (result.IsCurrentError(ResultBM.Type.CORRUPTED_DATABASE) && result.keepGoing)
                    {
                        new FrmBackup().ShowDialog();
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #9
0
        public ResultBM UpdateStock(StockBM stockBm)
        {
            try
            {
                StockDAL stockDal         = new StockDAL();
                StockDTO stockDto         = null;
                ResultBM validationResult = IsValid(stockBm);

                if (!validationResult.IsValid())
                {
                    return(validationResult);
                }
                stockDto = new StockDTO(stockBm.id, stockBm.Name, stockBm.Quantity, stockBm.itemType.id, stockBm.donation.id, stockBm.depot.id, stockBm.DueDate, stockBm.Location);

                stockDal.UpdateStock(stockDto);

                new DonationBLL().UpdateToStoredStatusIfApply(stockBm.donation.id);

                return(new ResultBM(ResultBM.Type.OK, "Se ha creado el stock.", stockBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
        public ResultBM UpdateVerticallDigit()
        {
            try
            {
                //TODO - debería soportar varias entidades
                DigitVerificatorDAL dvDal   = new DigitVerificatorDAL();
                UserBLL             userBll = new UserBLL();

                ResultBM usersBms             = userBll.GetUsers();
                List <DigitVeryficator> users = usersBms.GetValue <List <UserBM> >().Cast <DigitVeryficator>().ToList();

                string digit = SecurityHelper.Encrypt(GetStringToCheck(users));

                DigitVerificatorDTO digitDto = new DigitVerificatorDTO(USER_TABLE, digit);
                bool result = dvDal.UpdateEntityDigit(digitDto);

                if (result)
                {
                    return(new ResultBM(ResultBM.Type.OK, "Dígito verificador vertical actualizado."));
                }
                else
                {
                    return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR")));
                }
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #11
0
        public ResultBM UpdateReleaseOrder(ReleaseOrderBM releaseOrderBm)
        {
            try
            {
                ReleaseOrderDetailBLL releaseOrderDetailBll = new ReleaseOrderDetailBLL();
                ResultBM        detailResult    = null;
                ReleaseOrderDAL releaseOrderDal = new ReleaseOrderDAL();
                ReleaseOrderDTO releaseOrderDto = null;
                ResultBM        validResult     = IsValid(releaseOrderBm);

                if (!validResult.IsValid())
                {
                    return(validResult);
                }
                releaseOrderDto = new ReleaseOrderDTO(releaseOrderBm.id, releaseOrderBm.beneficiary.beneficiaryId, releaseOrderBm.Comment, releaseOrderBm.released, releaseOrderBm.received, releaseOrderBm.OrderStatus);
                releaseOrderDal.UpdateReleaseOrder(releaseOrderDto);

                detailResult = releaseOrderDetailBll.UpdateReleaseOrderDetail(releaseOrderBm);
                if (!detailResult.IsValid())
                {
                    return(detailResult);
                }

                return(new ResultBM(ResultBM.Type.OK, "Orden de salida actualizada.", releaseOrderBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #12
0
        private void cmdFilter_Click(object sender, EventArgs e)
        {
            // la estrategia consiste en tomar todos los campos de los filtros y pasárselos a la BLL

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();

                foreach (Control control in lstControls)
                {
                    if (control.Text.Length > 0)
                    {
                        parameters.Add(control.Tag.ToString(), control.Text);
                    }
                }

                object   businessLogic = Activator.CreateInstance(this.entity);
                ResultBM result        = ((BLEntity)businessLogic).GetCollection(parameters);

                if (result.IsValid())
                {
                    dgView.DataSource = result.GetValue();
                }
                else
                {
                    MessageBox.Show(result.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                dgView.Refresh();
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #13
0
        private void cmdDelete_Click(object sender, EventArgs e)
        {
            if (dgView.SelectedRows.Count == 0)
            {
                return;
            }
            try
            {
                DialogResult answer = MessageBox.Show(
                    SessionHelper.GetTranslation("DELETE_QUESTION"), "Eliminar",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question
                    );

                if (answer == DialogResult.Yes)
                {
                    object   businessLogic = Activator.CreateInstance(this.entity);
                    ResultBM result        = ((BLEntity)businessLogic).Delete(dgView.SelectedRows[0].DataBoundItem);

                    if (result.IsValid())
                    {
                        LoadDatagrid();
                    }
                    else
                    {
                        MessageBox.Show(result.description, "Eliminar", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #14
0
        public void GetInexistentOrganization()
        {
            //Prueba el comportamiento cuando no existe organización.
            OrganizationBLL organizationBll = new OrganizationBLL();
            ResultBM        result          = organizationBll.GetOrganization(99999);

            Assert.IsNull(result.GetValue(), "No debería existir");
        }
Beispiel #15
0
        private DonationStatusBM get_status(int id)
        {
            DonationStatusBLL statusBll    = new DonationStatusBLL();
            ResultBM          statusResult = statusBll.GetDonationStatus(id);

            Assert.IsTrue(statusResult.IsValid(), "El estado debería ser válido.");
            return(statusResult.GetValue <DonationStatusBM>());
        }
Beispiel #16
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.");
        }
Beispiel #17
0
        private void FrmProfile_Load(object sender, EventArgs e)
        {
            try
            {
                //Traducciones
                SessionHelper.RegisterForTranslation(this, Codes.MNU_GE004);
                SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT);
                SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE);
                SessionHelper.RegisterForTranslation(lblPermission, Codes.LBL_PERMISSIONS);
                SessionHelper.RegisterForTranslation(lblDescription, Codes.LBL_DESCRIPTION);
                SessionHelper.RegisterForTranslation(lblProfile, Codes.LBL_PROFILE);

                // Se recuperan los permisos (root) y se llena la lista
                ProfileBLL profileBll = new ProfileBLL();
                ResultBM   result     = profileBll.GetSystemPermissions();

                if (result.IsValid())
                {
                    chkListProfile.DataSource    = result.GetValue <List <PermissionMDL> >();
                    chkListProfile.DisplayMember = "description";
                }
                else
                {
                    MessageBox.Show(result.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                //En caso de ser nuevo, se requiere contar con un permiso "nodo" que facilita su muestra por pantalla y al momento de guardarlo.
                //Si se trata de una actualización, se debe recuperar el listado con los permisos y sus exclusiones.
                if (!this.isUpdate)
                {
                    //Si se quiere dar de alta un nuevo permiso, se genera un root para mantener ordenado los permisos que se agreguen
                    this.Entity = new PermissionsMDL(null, GenCode(5), "descripcion", false);
                }
                else
                {
                    txtDescription.Text = this.entity.Description;
                    this.Entity         = GetPermissionHierarchy(this.Entity);
                    PopulateTree(treeProfile, this.Entity);
                    treeProfile.ExpandAll();

                    //No es performante, pero funciona.
                    //Recorre todos los permisos que se listan en la lista de profile y en caso de que el usuario tenga dicho privilegio, los checkea
                    chkListProfile.ItemCheck -= chkListProfile_ItemCheck;
                    for (int i = 0; i < chkListProfile.Items.Count; ++i)
                    {
                        if (this.entity.HasPermission(((PermissionMDL)chkListProfile.Items[i]).code))
                        {
                            chkListProfile.SetItemCheckState(i, CheckState.Checked);
                        }
                    }
                    chkListProfile.ItemCheck += chkListProfile_ItemCheck;
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #18
0
        public void GetInexistentCountry()
        {
            //Prueba el comportamiento cuando no existe país.
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("XX");
            CountryBM  country    = result.GetValue <CountryBM>();

            Assert.IsNull(country, "El país con iso2 XX no debería existir");
        }
Beispiel #19
0
        public void GetOrganization()
        {
            //Prueba el comportamiento cuando existe organización.
            OrganizationBLL organizationBll = new OrganizationBLL();
            ResultBM        result          = organizationBll.GetOrganization(1);

            Assert.IsNotNull(result.GetValue(), "Debería existir");
            Assert.AreEqual(result.GetValue <OrganizationBM>().name, "Organización 01", "Debería ser Organización 01");
        }
Beispiel #20
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.");
        }
Beispiel #21
0
        public void GetInexistentAddress()
        {
            //Prueba la recuperación de una dirección inexistente

            AddressBLL addressBll      = new AddressBLL();
            ResultBM   recoveredResult = addressBll.GetAddress(999);

            Assert.IsNull(recoveredResult.GetValue(), "No debería existir");
        }
Beispiel #22
0
        private void FrmItemType_Load(object sender, EventArgs e)
        {
            try
            {
                //Traducciones
                SessionHelper.RegisterForTranslation(this, Codes.MNU_GE012);
                SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT);
                SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE);

                SessionHelper.RegisterForTranslation(lblName, Codes.LBL_NAME);
                SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION);
                SessionHelper.RegisterForTranslation(grpCategory, Codes.LBL_CATEGORY);

                SessionHelper.RegisterForTranslation(rbEdible, Codes.LBL_EDIBLE);
                SessionHelper.RegisterForTranslation(rbIndumentary, Codes.LBL_INDUMENTARY);
                SessionHelper.RegisterForTranslation(rbMedicine, Codes.LBL_MEDICINE);
                SessionHelper.RegisterForTranslation(rbConstruction, Codes.LBL_CONSTRUCTION);
                SessionHelper.RegisterForTranslation(rbOther, Codes.LBL_OTHER);
                SessionHelper.RegisterForTranslation(checkPerishable, Codes.LBL_PERISHABLE);

                //No es elegante pero si es sencilla
                rbEdible.Tag       = ItemTypeBM.Category.EDIBLE;
                rbIndumentary.Tag  = ItemTypeBM.Category.INDUMENTARY;
                rbMedicine.Tag     = ItemTypeBM.Category.MEDICINE;
                rbConstruction.Tag = ItemTypeBM.Category.CONSTRUCTION;
                rbOther.Tag        = ItemTypeBM.Category.OTHER;

                if (this.IsUpdate)
                {
                    ItemTypeBLL itemTypeBll    = new ItemTypeBLL();
                    ResultBM    itemTypeResult = itemTypeBll.GetItemType(this.Entity.id);

                    if (!itemTypeResult.IsValid())
                    {
                        MessageBox.Show(itemTypeResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    this.Entity             = itemTypeResult.GetValue <ItemTypeBM>();
                    txtName.Text            = this.Entity.Name;
                    txtComment.Text         = this.Entity.Comment;
                    checkPerishable.Checked = this.Entity.Perishable;
                    rbEdible.Checked        = this.Entity.IsEdible();
                    rbIndumentary.Checked   = this.Entity.IsIndumentary();
                    rbMedicine.Checked      = this.Entity.IsMedicine();
                    rbConstruction.Checked  = this.Entity.IsConstruction();
                    rbOther.Checked         = this.Entity.IsOther();
                }
                else
                {
                    this.Entity = new ItemTypeBM();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #23
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));
            }
        }
Beispiel #24
0
        public ResultBM GetDonation(int donationId)
        {
            try
            {
                VolunteerBLL      volunteerBll      = new VolunteerBLL();
                ResultBM          volunteerResult   = null;
                VolunteerBM       volunteerBm       = null;
                DonationStatusBLL donationStatusBll = new DonationStatusBLL();
                ResultBM          statusResult      = null;
                DonorBLL          donorBll          = new DonorBLL();
                ResultBM          donorResult       = null;

                DonationDAL donationDal = new DonationDAL();
                DonationBM  donationBm  = null;
                DonationDTO donationDto = donationDal.GetDonation(donationId);

                //Si la donación existe, debería existir el estado
                if (donationDto != null)
                {
                    statusResult = donationStatusBll.GetDonationStatus(donationDto.statusId);
                    if (!statusResult.IsValid())
                    {
                        return(statusResult);
                    }
                    if (statusResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " statusId " + donationDto.statusId);
                    }

                    donorResult = donorBll.GetDonor(donationDto.donorId);
                    if (!donorResult.IsValid())
                    {
                        return(donorResult);
                    }
                    if (donorResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " donorId " + donationDto.donorId);
                    }

                    //Podría no existir voluntario, sobre todo si se consulta una donación recién creada
                    volunteerResult = volunteerBll.GetVolunteer(donationDto.volunteerId);
                    if (volunteerResult.GetValue() != null)
                    {
                        volunteerBm = volunteerResult.GetValue <VolunteerBM>();
                    }

                    donationBm = new DonationBM(donationDto, donorResult.GetValue <DonorBM>(), statusResult.GetValue <DonationStatusBM>(), volunteerBm);
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", donationBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #25
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");
        }
Beispiel #26
0
        private UserBM create_user()
        {
            string   fecha   = DateTime.Now.ToString("yyyymmddHHmm");
            UserBLL  userBll = new UserBLL();
            UserBM   newUser = new UserBM("Usuario " + fecha, true, 1, "GE999", "123");
            ResultBM result  = userBll.SaveUser(newUser);

            Assert.IsTrue(result.IsValid(), "El usuario debería haberse creado");
            return(result.GetValue <UserBM>());
        }
Beispiel #27
0
        public ResultBM GetStock(int stockId)
        {
            try {
                DonationBLL donationBll    = new DonationBLL();
                ResultBM    donationResult = null;
                DepotBLL    depotBll       = new DepotBLL();
                ResultBM    depotResult    = null;
                ItemTypeBLL itemTypeBll    = new ItemTypeBLL();
                ResultBM    itemTypeResult = null;
                StockDAL    stockDal       = new StockDAL();
                StockBM     stockBm        = null;
                StockDTO    stockDto       = stockDal.GetStock(stockId);

                //Si existe el stock, las relaciones deberían existir... TODAS
                if (stockDto != null)
                {
                    donationResult = donationBll.GetDonation(stockDto.donationId);
                    if (!donationResult.IsValid())
                    {
                        return(donationResult);
                    }
                    if (donationResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " donationId " + stockDto.donationId);
                    }

                    depotResult = depotBll.GetDepot(stockDto.depotId);
                    if (!depotResult.IsValid())
                    {
                        return(depotResult);
                    }
                    if (depotResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " depotId " + stockDto.depotId);
                    }

                    itemTypeResult = itemTypeBll.GetItemType(stockDto.itemTypeId);
                    if (!itemTypeResult.IsValid())
                    {
                        return(itemTypeResult);
                    }
                    if (itemTypeResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " itemTypeId " + stockDto.itemTypeId);
                    }

                    stockBm = new StockBM(stockDto, donationResult.GetValue <DonationBM>(), depotResult.GetValue <DepotBM>(), itemTypeResult.GetValue <ItemTypeBM>());
                }

                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", stockBm));
            }
            catch (Exception exception) {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
Beispiel #28
0
        public void CreateAddressFailsCountry()
        {
            //Prueba la validación del país
            AddressBLL addressBll = new AddressBLL();
            AddressBM  addressBm  = new AddressBM("Calle test", 999, "Departamento", "Barrio", "Esta es una dirección creada mediante test", null);

            ResultBM addressResult = addressBll.SaveAddress(addressBm);

            Assert.IsTrue(addressResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido.");
            Assert.IsTrue(addressResult.description.Contains("país"), "No debería haber sido válido.");
        }
Beispiel #29
0
        public void GetCountry()
        {
            //Prueba que pueda recuperar el país pasado por parámetro.
            CountryBLL countryBll = new CountryBLL();
            ResultBM   result     = countryBll.GetCountry("AR");
            CountryBM  country    = result.GetValue <CountryBM>();

            Assert.IsNotNull(country, "Debería haber recuperado el país argentina");
            Assert.AreEqual(country.iso2, "AR", "Debería existir AR");
            Assert.AreEqual(country.Name, "Argentina", "Debería ser Argentina");
        }
Beispiel #30
0
        /// <summary>
        /// Devuelve la jerarquía de permisos para el elemento seleccionado
        /// </summary>
        /// <param name="sender"></param>
        /// <returns></returns>
        private ProfileBM GetPermissionHierarchy(ProfileBM selection)
        {
            ProfileBLL profileBll = new ProfileBLL();
            ResultBM   result     = profileBll.GetProfile(selection.code);

            if (!result.IsValid())
            {
                MessageBox.Show(result.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            return(result.GetValue() as ProfileBM);
        }