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."); }
private ResultBM IsValid(VolunteerBM volunteerBm) { if (volunteerBm.branch == null) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, "Debe especificar sede.")); } return(new ResultBM(ResultBM.Type.OK)); }
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)); } }
public void CreateVolunteerFailsBranch() { //Crea un donador PersonBM personBm = create_person(); VolunteerBLL volunteerBll = new VolunteerBLL(); VolunteerBM volunteerBm = new VolunteerBM(personBm, null); ResultBM volunterResult = volunteerBll.SaveVolunteer(volunteerBm); Assert.IsFalse(volunterResult.IsValid(), "El voluntario debería existir."); Assert.IsTrue(volunterResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "No debería haber sido válido."); Assert.IsNull(volunterResult.GetValue(), "No debería existir el voluntario."); }
public void CreateVolunteer() { //Crea un donador PersonBM personBm = create_person(); BranchBLL branchBll = new BranchBLL(); ResultBM brancResult = branchBll.GetBranch(1); Assert.IsTrue(brancResult.IsValid(), "El donador debería existir."); VolunteerBLL volunteerBll = new VolunteerBLL(); VolunteerBM volunteerBm = new VolunteerBM(personBm, brancResult.GetValue <BranchBM>()); ResultBM volunterResult = volunteerBll.SaveVolunteer(volunteerBm); Assert.IsTrue(volunterResult.IsValid(), "El donador debería existir."); Assert.IsNotNull(volunterResult.GetValue(), "Debería existir el voluntario."); Assert.IsTrue(volunterResult.GetValue <VolunteerBM>().id > 0, "Debería existir el voluntario."); }
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)); } }
public ResultBM GetVolunteer(int volunteerId) { try { AddressBLL addressBll = new AddressBLL(); ResultBM addressResult = null; AddressBM addressBm = null; BranchBLL branchBll = new BranchBLL(); ResultBM branchResult = null; BranchBM branchBm = null; UserBLL userBll = new UserBLL(); ResultBM userResult = null; UserBM userBm = null; VolunteerDAL volunteerDal = new VolunteerDAL(); VolunteerBM volunteerBm = null; VolunteerDTO volunteerDto = volunteerDal.GetVolunteer(volunteerId); if (volunteerDto != null) { //Debería existir addressResult = addressBll.GetAddress(volunteerDto.addressId); if (!addressResult.IsValid()) { return(addressResult); } if (addressResult.GetValue() == null) { throw new Exception("La dirección " + volunteerDto.addressId + " para el voluntario " + volunteerId + " no existe."); } addressBm = addressResult.GetValue <AddressBM>(); branchResult = branchBll.GetBranch(volunteerDto.branchId); if (!branchResult.IsValid()) { return(branchResult); } if (branchResult.GetValue() == null) { throw new Exception("La sede " + volunteerDto.branchId + " para el voluntario " + volunteerId + " no existe."); } branchBm = branchResult.GetValue <BranchBM>(); //El usuario podría no existir porque el voluntario no requiere necesariamente que se lo asocie //con un susuario de sistema userResult = userBll.GetUser(volunteerDto.userId); if (!userResult.IsValid()) { return(userResult); } if (userResult.GetValue() != null) { userBm = userResult.GetValue <UserBM>(); } volunteerBm = new VolunteerBM(volunteerDto, addressBm, branchBm, userBm); } return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", volunteerBm)); } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, "Se ha producido un error al recuperar el voluntario " + volunteerId + ".", exception)); } }
private void DonationFrm_Load(object sender, EventArgs e) { try { dateArrival.CustomFormat = "dd/MM/yyyy hh:mm"; ChangeSize(); if (this.Entity != null && this.Entity.IsStored()) { MessageBox.Show("Está intentando editar una donación ya almacenada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); groupBox1.Enabled = false; cmdAccept.Enabled = false; } //Traducciones SessionHelper.RegisterForTranslation(this, Codes.MNU_GE011); SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT); SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE); SessionHelper.RegisterForTranslation(lblLot, Codes.LBL_LOT); SessionHelper.RegisterForTranslation(lblArrival, Codes.LBL_ARRIVAL); SessionHelper.RegisterForTranslation(lblResponsible, Codes.LBL_RESPONSIBLE); SessionHelper.RegisterForTranslation(lblDonor, Codes.LBL_DONOR); SessionHelper.RegisterForTranslation(lblItems, Codes.LBL_ITEMS); SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION); SessionHelper.RegisterForTranslation(lblContact, Codes.LBL_CONTACT_INFO); SessionHelper.RegisterForTranslation(chkPickup, Codes.LBL_PICKUP); DonorBLL donorBll = new DonorBLL(); ResultBM donorResult = donorBll.GetDonors(); VolunteerBLL volunteerBll = new VolunteerBLL(); ResultBM volunteerResult = volunteerBll.GetVolunteers(); if (donorResult.IsValid()) { cmbDonor.SelectedIndexChanged -= cmbDonor_SelectedIndexChanged; cmbDonor.DataSource = donorResult.GetValue <List <DonorBM> >(); cmbDonor.DisplayMember = "FullName"; cmbDonor.SelectedIndexChanged += cmbDonor_SelectedIndexChanged; } else { MessageBox.Show(donorResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (volunteerResult.IsValid()) { //Se debe agregar un voluntario "Sin voluntario". List <VolunteerBM> volunteers = new List <VolunteerBM>(); VolunteerBM noVolunteer = new VolunteerBM(); noVolunteer.name = "-------------"; volunteers.Add(noVolunteer); volunteers.AddRange(volunteerResult.GetValue <List <VolunteerBM> >()); cmbVolunteer.DataSource = volunteers; cmbVolunteer.DisplayMember = "FullName"; } else { MessageBox.Show(volunteerResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (this.IsUpdate) { DonationBLL donationBll = new DonationBLL(); ResultBM donationResult = donationBll.GetDonation(this.Entity.id); if (donationResult.IsValid()) { //Estoy asumiento que se recuperó algo, más alla de que la operación fue exitosa this.Entity = donationResult.GetValue <DonationBM>(); lblLotId.Text = this.Entity.Lot.ToString(); dateArrival.Value = this.Entity.Arrival; chkPickup.Checked = this.Entity.IsToBeRetrieved(); numericItems.Value = this.Entity.Items; txtComment.Text = this.Entity.Comment; txtContact.Text = this.Entity.donor.GetContectInfo(); //Posicionar donador bool found = false; for (int i = 0; i < cmbDonor.Items.Count && !found; ++i) { found = ((DonorBM)cmbDonor.Items[i]).donorId == this.Entity.donor.donorId; if (found) { cmbDonor.SelectedIndex = i; } } found = false; for (int i = 0; i < cmbVolunteer.Items.Count && !found; ++i) { int id = this.Entity.volunteer == null ? 0 : this.Entity.volunteer.volunteerId; found = ((VolunteerBM)cmbVolunteer.Items[i]).volunteerId == id; if (found) { cmbVolunteer.SelectedIndex = i; } } } else { MessageBox.Show(donationResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { this.Entity = new DonationBM(); } } catch (Exception exception) { MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }