コード例 #1
0
        private void buttonDefineStock_Click(object sender, EventArgs e)
        {
            string code              = textBoxStockCode.Text;
            string name              = textBoxStockName.Text;
            string description       = textBoxStockDescription.Text;
            string uv                = textBoxStockUnityValue.Text;
            string actions           = textBoxStockActions.Text;
            double unityValue        = 0;
            double quantityOfActions = 0;

            try
            {
                unityValue        = Double.Parse(uv);
                quantityOfActions = Double.Parse(actions);
            }
            catch (Exception)
            {
                MessageBox.Show("El valor inicial y la cantidad de acciones deben ser números", "Error");
                return;
            }
            Stock stock = new Stock();

            stock.Code             = code;
            stock.Name             = name;
            stock.Description      = description;
            stock.QuantiyOfActions = quantityOfActions;
            stock.UnityValue       = unityValue;
            if (code == string.Empty || name == string.Empty || description == string.Empty)
            {
                MessageBox.Show("No debe dejar campos vacíos", "Error");
                return;
            }

            bool createStock = stockLogic.CreateStock(stock);

            if (createStock)
            {
                MessageBox.Show("Stock creado correctamente", "Confirmación");
                panelCreateStock.Visible = false;
                StockMaintenance();
                ClearCreateStock();
                panelModifyDeleteStock.Visible = true;
            }
            else
            {
                MessageBox.Show("El largo del código del stock debe ser menor o igual a 6", "Error");
            }
        }
コード例 #2
0
 public IHttpActionResult PostStock(Stock stock)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest(ModelState));
     }
     try
     {
         if (stockLogic.CreateStock(stock))
         {
             return(CreatedAtRoute("DefaultApi", new { id = stock.Id }, stock));
         }
         return(BadRequest());
     }
     catch (UserException ue)
     {
         return(BadRequest(ue.Message));
     }
 }