示例#1
0
    public void SaveInventory()
    {
        try
        {
            if (Session["CompanyId"] == null)
            {
                Response.Redirect("~/Login.aspx");
            }
            int companyId   = int.Parse(Session["CompanyId"].ToString());
            int stockId     = int.Parse(ddlStock.SelectedValue);
            var inventories = _db.Inventories.Where(m => m.StockId == stockId);


            if (inventories.Any())
            {
                ErrorControl1.ShowError("Stock with the same name already exist");
                return;
            }
            var inventObj = new Inventory
            {
                StockId      = stockId,
                CostPrice    = decimal.Parse(txtCostPrice.Text),
                CompanyId    = companyId,
                DateCreated  = DateTime.Now,
                ReorderLevel = int.Parse(txtReoderLevel.Text)
            };

            _db.Inventories.Add(inventObj);
            _db.SaveChanges();
            ErrorControl1.ShowSuccess("Inventory saved successfully");
            ErrorControl1.ClearControls(divForm);
        }
        catch (Exception ex)
        {
            ErrorControl1.ShowError("An error occurred, Please contact administrator");
        }
    }
示例#2
0
 protected void BtnCancel_Click(object sender, EventArgs e)
 {
     ErrorControl1.ClearControls(divForm);
 }