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."); }
public ResultBM Delete(object entity) { try { DonationDAL donationDal = new DonationDAL(); DonationBM donationBm = entity as DonationBM; if (donationBm.IsReceived()) { if (!donationDal.IsInUse(donationBm.id)) { donationDal.DeleteDonation(donationBm.id); return(new ResultBM(ResultBM.Type.OK, "Se ha eliminado el registro.", donationBm)); } else { return(new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("DONATION_ASSIG_UNDELETEABLE_ERROR"), donationBm)); } } else { return(new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("DONATION_STATUS_UNDELETEABLE_ERROR"), donationBm)); } } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("DELETING_ERROR") + " " + exception.Message, exception)); } }
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)); } }
private void cmbDonation_SelectedIndexChanged(object sender, EventArgs e) { //No debería accederse en edición puesto que la edición no admite cambio de lote. if (!this.IsUpdate) { DonationBM donation = (DonationBM)((ComboBox)sender).SelectedItem; this.availableStock = donation.Items - donation.stocked; numericQuantity.Maximum = this.availableStock; numericQuantity.Value = this.availableStock; CalculateMaxStockLeft((DonationBM)((ComboBox)sender).SelectedItem, this.availableStock); } }
public void CreateDonationFailsStatus() { //Prueba la validación cuando el estado no es provisto DonorBM donor = create_donor(); DonationBLL donationBll = new DonationBLL(); DonationBM donationBm = new DonationBM(2, donor.donorId, null); ResultBM donationResult = donationBll.SaveDonation(donationBm); Assert.IsFalse(donationResult.IsValid(), "La donación no debería ser válida."); Assert.IsNotNull(donationResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "El error debería ser campo incompleto."); Assert.AreEqual(donationResult.description, "Debe selecionar un estado válido para el lote.", "El error debería coincidir."); }
public void CreateDonationFailsDonor() { //Prueba la validación cuando no se provee donador válido DonationStatusBM statusBm = get_status(1); DonationBLL donationBll = new DonationBLL(); DonationBM donationBm = new DonationBM(21, 0, statusBm); ResultBM donationResult = donationBll.SaveDonation(donationBm); Assert.IsFalse(donationResult.IsValid(), "La donación no debería ser válida."); Assert.IsNotNull(donationResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "El error debería ser campo incompleto."); Assert.AreEqual(donationResult.description, "Debe asignarse donador.", "El error debería coincidir."); }
public void CreateDonationFailsItems() { //Prueba la validación cuando la cantidad de items no es la menos 1 DonorBM donor = create_donor(); DonationStatusBM statusBm = get_status(1); DonationBLL donationBll = new DonationBLL(); DonationBM donationBm = new DonationBM(0, donor.donorId, statusBm); ResultBM donationResult = donationBll.SaveDonation(donationBm); Assert.IsFalse(donationResult.IsValid(), "La donación no debería ser válida."); Assert.IsNotNull(donationResult.IsCurrentError(ResultBM.Type.INCOMPLETE_FIELDS), "El error debería ser campo incompleto."); Assert.AreEqual(donationResult.description, "La cantidad de bultos debe ser de al menos una unidad.", "El error debería coincidir."); }
public void CreateDonationNullComment() { //Crea una donación DonorBM donor = create_donor(); DonationStatusBM statusBm = get_status(1); DonationBLL donationBll = new DonationBLL(); DonationBM donationBm = new DonationBM(21, donor.donorId, statusBm); ResultBM donationResult = donationBll.SaveDonation(donationBm); Assert.IsTrue(donationResult.IsValid(), "La donación debería ser válida."); Assert.IsNotNull(donationResult.GetValue(), "Debería haber devuelto la donación."); Assert.IsNull(donationResult.GetValue <DonationBM>().Comment, "No debería poseer comentario"); }
public void CreateDonation() { //Crea una donación DonorBM donor = create_donor(); DonationStatusBM statusBm = get_status(1); DonationBLL donationBll = new DonationBLL(); DonationBM donationBm = new DonationBM(21, donor.donorId, statusBm, "Esta es una donación creada por un test."); ResultBM donationResult = donationBll.SaveDonation(donationBm); Assert.IsTrue(donationResult.IsValid(), "La donación debería ser válida."); Assert.IsNotNull(donationResult.GetValue(), "Deería haber devuelto una donación."); Assert.IsTrue(donationResult.GetValue <DonationBM>().id > 0, "El id debería ser mayor a cero."); Assert.AreEqual(donationResult.GetValue <DonationBM>().Comment, "Esta es una donación creada por un test.", "Debería poseer comentario"); }
private ResultBM IsValid(DonationBM donationBm) { if (donationBm.Items < 1) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("INVALID_VALUE_ERROR") + " (<1)")); } if (donationBm.donationStatus == null) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (STATUS)")); } if (donationBm.donor == null || donationBm.donor.donorId == 0) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (DONOR)")); } return(new ResultBM(ResultBM.Type.OK)); }
public ResultBM UpdateDonation(DonationBM donationBm) { try { DonationDAL donationDal = new DonationDAL(); DonationDTO donationDto; ResultBM validationResult = IsValid(donationBm); if (!validationResult.IsValid()) { return(validationResult); } donationDto = new DonationDTO(donationBm.Items, donationBm.Arrival, donationBm.donationStatus.id, donationBm.donor.donorId, donationBm.Comment, donationBm.volunteer == null ? 0 : donationBm.volunteer.volunteerId, donationBm.id); donationDal.UpdateDonation(donationDto); return(new ResultBM(ResultBM.Type.OK, "Se ha actualizado la donación.", donationBm)); } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception)); } }
private void FrmStock_Load(object sender, EventArgs e) { try { if (this.Entity != null && this.Entity.donation != null && this.Entity.donation.IsStored()) { MessageBox.Show("El ítem que está intentando editar pertenece a una donación ya almacenada.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); groupBox1.Enabled = false; cmdAccept.Enabled = false; } //Traducciones SessionHelper.RegisterForTranslation(this, Codes.MNU_GE013); SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT); SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE); SessionHelper.RegisterForTranslation(lblLot, Codes.LBL_LOT); SessionHelper.RegisterForTranslation(lblDepot, Codes.LBL_DEPOT); SessionHelper.RegisterForTranslation(lblDescription, Codes.LBL_DESCRIPTION); SessionHelper.RegisterForTranslation(lblType, Codes.LBL_ITEM_TYPE); SessionHelper.RegisterForTranslation(lblItemQuantity, Codes.LBL_QUANTITY); SessionHelper.RegisterForTranslation(lblDuedate, Codes.LBL_DUEDATE); SessionHelper.RegisterForTranslation(lblLocation, Codes.LBL_LOCATION); LoadDonations(); LoadDepots(); LoadItemTypes(); if (this.IsUpdate) { cmbDonation.Enabled = false; StockBLL stockBll = new StockBLL(); ResultBM stockResult = stockBll.GetStock(this.Entity.id); if (!stockResult.IsValid()) { MessageBox.Show(stockResult.description, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } this.Entity = stockResult.GetValue <StockBM>(); this.availableStock = this.Entity.GetAmountItemsToStockWithoutThis(); numericQuantity.Maximum = this.availableStock; numericQuantity.Value = this.Entity.Quantity; txtName.Text = this.Entity.Name; dtDueDate.Value = this.Entity.DueDate; txtLocation.Text = this.Entity.Location; //Posicionar donador bool found = false; for (int i = 0; i < cmbItemType.Items.Count && !found; ++i) { found = ((ItemTypeBM)cmbItemType.Items[i]).id == this.Entity.itemType.id; if (found) { cmbItemType.SelectedIndex = i; } } found = false; for (int i = 0; i < cmbDonation.Items.Count && !found; ++i) { found = ((DonationBM)cmbDonation.Items[i]).id == this.Entity.donation.id; if (found) { cmbDonation.SelectedIndex = i; } } found = false; for (int i = 0; i < cmbDepot.Items.Count && !found; ++i) { found = ((DepotBM)cmbDepot.Items[i]).id == this.Entity.depot.id; if (found) { cmbDepot.SelectedIndex = i; } } } else { this.Entity = new StockBM(); //Cuando es nuevo, se toma el valor del elemento seleccionado del combo de donación como valores inicializadores. //En dicho caso, el máximo disponible es el máximo asignable y el número que se sugiere stockear DonationBM donationBm = (DonationBM)cmbDonation.SelectedItem; if (donationBm != null) { this.availableStock = donationBm.Items - donationBm.stocked; numericQuantity.Maximum = this.availableStock; numericQuantity.Value = this.availableStock; } } CalculateMaxStockLeft((DonationBM)cmbDonation.SelectedItem, (int)numericQuantity.Value); } catch (Exception exception) { MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "EXCEPCIÓN", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void CalculateMaxStockLeft(DonationBM donation, int toStock) { int left = this.availableStock - toStock; lblLeft.Text = "(" + left + ")"; }