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)); } }
private ResultBM IsValid(StockBM stockBm) { if (stockBm.Name == null || stockBm.Name.Length == 0) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (NAME)")); } if (stockBm.Quantity == 0) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (ITEMS < 1)")); } if (!(stockBm.GetAmountItemsToStockWithoutThis() <= stockBm.donation.Items * 2 && stockBm.GetAmountItemsToStockWithoutThis() > 1)) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (TOO MUCH ITEMS)")); } if (stockBm.itemType.Perishable && stockBm.DueDate == null) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (DATE)")); } if (stockBm.Location == null || stockBm.Location.Length == 0) { return(new ResultBM(ResultBM.Type.INCOMPLETE_FIELDS, SessionHelper.GetTranslation("EMPTY_FIELD_ERROR") + " (LOCATION)")); } return(new ResultBM(ResultBM.Type.OK)); }
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)); } }
private void lstStock_SelectedIndexChanged(object sender, EventArgs e) { StockBM selection = (StockBM)((ListBox)sender).SelectedItem; if (selection == null) { return; } nbrQuantity.Maximum = selection.Quantity; nbrQuantity.Value = selection.Quantity; // esto debe ser disponible :D }
public void CreateStock(StockBM model) { Stock element = context.Stocks.FirstOrDefault(rec => rec.Name == model.Name); if (element != null) { throw new Exception("Уже есть stock с таким name"); } context.Stocks.Add(new Stock { Name = model.Name }); context.SaveChanges(); }
private void UpdateAvailableItemsWhenRemoving(StockBM stockToAdd) { //Cuando se agrega de lo disponible a la grilla List <StockBM> lstAux = new List <StockBM>(); for (int e = lstStock.Items.Count - 1; e > -1; --e) { if (((StockBM)lstStock.Items[e]).id != stockToAdd.id) { lstAux.Insert(0, lstStock.Items[e] as StockBM); } } lstStock.DataSource = null; lstStock.DataSource = lstAux; lstStock.DisplayMember = "Name"; }
public ResultBM Delete(object entity) { try { StockDAL stockDal = new StockDAL(); DonationBLL donationBll = new DonationBLL(); StockBM stockBm = entity as StockBM; if (!stockDal.IsInUse(stockBm.id)) { stockDal.DeleteStock(stockBm.id); donationBll.UpdateToReceivedStatus(stockBm.donation.id); return(new ResultBM(ResultBM.Type.OK, "Se ha eliminado el registro.", stockBm)); } else { return(new ResultBM(ResultBM.Type.FAIL, SessionHelper.GetTranslation("STOCK_UNDELETEABLE_ERROR"), stockBm)); } } catch (Exception exception) { return(new ResultBM(ResultBM.Type.EXCEPTION, SessionHelper.GetTranslation("DELETING_ERROR") + " " + exception.Message, exception)); } }
private void UpdateGrid(bool isAdding) { ReleaseOrderDetailBM detailToAdd = null; StockBM stockToAdd = (StockBM)lstStock.SelectedItem; if (isAdding) { bool found = false; //si existe, es necesario que se controle que no se puedan agregar más unidades que las que especifica el stock disponible for (int i = 0; i < lstAdded.Count && !found; ++i) { found = stockToAdd.id == lstAdded[i].stock.id; if (found) { int total = lstAdded[i].Quantity + int.Parse(nbrQuantity.Value.ToString()); if (total < stockToAdd.Quantity) { lstAdded[i].Quantity = total; } else { lstAdded[i].Quantity = stockToAdd.Quantity; //Si se asigna el máximo disponible, entonces ya no debe formar parte de la lista de stock disponible. //Negrada... no hay tiempo: borra el elemento del listbox UpdateAvailableItemsWhenRemoving(stockToAdd); } } } // Si el stock a agregar no existe en la lista de agregados, entonces se incorpora. if (!found) { detailToAdd = new ReleaseOrderDetailBM(); detailToAdd.stock = stockToAdd; detailToAdd.Quantity = int.Parse(nbrQuantity.Value.ToString()); lstAdded.Add(detailToAdd); //Si se agrega lo máximo, entonces se elimia de los disponibles if (stockToAdd.Quantity == detailToAdd.Quantity) { UpdateAvailableItemsWhenRemoving(stockToAdd); } } } else { // La estrategia consiste en ver si existe el elemento que quiero devolver, en la lista de disponibles para incrementar el valor de disponibilidad // o agregar el item directamente si es que no existe. ReleaseOrderDetailBM toRemove = (ReleaseOrderDetailBM)dgRelease.SelectedRows[0].DataBoundItem; bool found = false; // Como la grilla se alimenta de una lista llamada lstAdded, se debe identificar el elemento para eliminarlo de allí. for (int i = 0; i < lstAdded.Count && !found; ++i) { found = toRemove.stock.id == lstAdded[i].stock.id; if (found) { lstAdded.RemoveAt(i); } } UpdateAvailableItemsWhenAdding(toRemove); } dgRelease.DataSource = null; dgRelease.DataSource = lstAdded; }
public void UpdStock(StockBM model) { throw new NotImplementedException(); }