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));
            }
        }
        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));
            }
        }
        private ResultBM IsValid(ReleaseOrderBM releaseOrder)
        {
            if (releaseOrder.detail == null || releaseOrder.detail.Count == 0)
            {
                return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (NO ITEMS)"));
            }

            return(new ResultBM(ResultBM.Type.OK));
        }
 public ResultBM UpdateReleaseOrderDetail(ReleaseOrderBM releaseOrderBm)
 {
     try {
         ReleaseOrderDetailDAL detailDal = new ReleaseOrderDetailDAL();
         detailDal.DeleteReleaseOrderDetail(releaseOrderBm.id);
         return(SaveReleaseOrderDetail(releaseOrderBm));
     }
     catch (Exception exception) {
         return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("UPDATING_ERROR") + " " + exception.Message, exception));
     }
 }
Beispiel #5
0
        private void FrmReleaseOrder_Load(object sender, EventArgs e)
        {
            //Traducciones
            SessionHelper.RegisterForTranslation(this, Codes.MNU_GE016);
            SessionHelper.RegisterForTranslation(cmdAccept, Codes.BTN_ACCEPT);
            SessionHelper.RegisterForTranslation(cmdClose, Codes.BTN_CLOSE);

            SessionHelper.RegisterForTranslation(lblBeneficiary, Codes.LBL_BENEFICIARY);
            SessionHelper.RegisterForTranslation(lblStock, Codes.LBL_STOCK);
            SessionHelper.RegisterForTranslation(lblQuantity, Codes.LBL_QUANTITY);
            SessionHelper.RegisterForTranslation(lblComment, Codes.LBL_OBSERVATION);

            try
            {
                BeneficiaryBLL beneficiaryBll    = new BeneficiaryBLL();
                ResultBM       beneficiaryResult = beneficiaryBll.GetBeneficiaries();
                cmbBeneficiary.DataSource    = beneficiaryResult.GetValue <List <BeneficiaryBM> >();
                cmbBeneficiary.DisplayMember = "FullName";

                StockBLL stockBll    = new StockBLL();
                ResultBM stockResult = stockBll.GetAvailableStocks();
                lstStock.DataSource    = stockResult.GetValue <List <StockBM> >();
                lstStock.DisplayMember = "Name";

                if (IsUpdate)
                {
                    bool found = false;

                    for (int i = 0; i < cmbBeneficiary.Items.Count && !found; ++i)
                    {
                        found = ((BeneficiaryBM)cmbBeneficiary.Items[i]).id == this.Entity.beneficiary.id;
                        if (found)
                        {
                            cmbBeneficiary.SelectedIndex = i;
                        }
                    }
                    lstAdded             = this.Entity.detail;
                    dgRelease.DataSource = lstAdded;
                    txtComment.Text      = this.Entity.Comment;
                }
                else
                {
                    entity = new ReleaseOrderBM();
                }
            }
            catch (Exception exception) {
                MessageBox.Show("Se ha producido el siguiente error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public ResultBM GetReleaseOrder(int releaseOrderId)
        {
            try
            {
                BeneficiaryBLL        beneficiaryBll           = new BeneficiaryBLL();
                ResultBM              beneficiaryResult        = null;
                ReleaseOrderDAL       releaseOrderDal          = new ReleaseOrderDAL();
                ReleaseOrderDTO       releaseOrderDto          = releaseOrderDal.GetReleaseOrder(releaseOrderId);
                ReleaseOrderBM        releaseOrderBm           = null;
                ReleaseOrderDetailBLL releaseOrderDetailBll    = new ReleaseOrderDetailBLL();
                ResultBM              releaseOrderDetailResult = null;

                //Si la orden de salida existe, deben existir beneficiario y detalles
                if (releaseOrderDto != null)
                {
                    beneficiaryResult = beneficiaryBll.GetBeneficiary(releaseOrderDto.beneficiaryId);
                    if (!beneficiaryResult.IsValid())
                    {
                        return(beneficiaryResult);
                    }
                    if (beneficiaryResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " beneficiaryId " + releaseOrderDto.beneficiaryId);
                    }

                    releaseOrderDetailResult = releaseOrderDetailBll.GetReleaseOrderDetail(releaseOrderId);
                    if (!releaseOrderDetailResult.IsValid())
                    {
                        return(releaseOrderDetailResult);
                    }
                    if (releaseOrderDetailResult.GetValue() == null)
                    {
                        throw new Exception(SessionHelper.GetTranslation("RETRIEVING_ERROR") + " releaseOrderId " + releaseOrderId);
                    }
                }

                releaseOrderBm = new ReleaseOrderBM(releaseOrderDto, beneficiaryResult.GetValue <BeneficiaryBM>(), releaseOrderDetailResult.GetValue <List <ReleaseOrderDetailBM> >());
                return(new ResultBM(ResultBM.Type.OK, "Operación exitosa.", releaseOrderBm));
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("RETRIEVING_ERROR") + " " + exception.Message, exception));
            }
        }
        public ResultBM Delete(object entity)
        {
            try
            {
                ReleaseOrderDAL releaseOrderDal = new ReleaseOrderDAL();
                ReleaseOrderBM  releaseOrderBm  = entity as ReleaseOrderBM;

                if (releaseOrderBm.OrderStatus == ReleaseOrderBM.Status.PENDING.ToString())
                {
                    releaseOrderDal.DeleteReleaseOrder(releaseOrderBm.id);
                    return(new ResultBM(ResultBM.Type.OK, "Se ha eliminado el registro.", releaseOrderBm));
                }
                else
                {
                    return(new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("RO_UNDELETEABLE_ERROR"), releaseOrderBm));
                }
            }
            catch (Exception exception)
            {
                return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("DELETING_ERROR") + " " + exception.Message, exception));
            }
        }