Exemplo n.º 1
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));
            }
        }