Example #1
0
 /// <summary>
 /// Load data when the supplier ID is supplied
 /// </summary>
 private void PopulateFields()
 {
     if (IsUpdate)
     {
         var supplimentId = Request.GetQueryString(StringHelper.SupplimentID);
         if (!string.IsNullOrWhiteSpace(supplimentId))
         {
             tblSupplement tblSupplement = _repositoryWrapper.Suppliment.GetById(supplimentId);
             txtSupplementIDS.Text       = tblSupplement?.Supplement_id;
             DdlSupplierID.SelectedValue = tblSupplement?.Supplier_Id;
             txtDescription.Text         = tblSupplement?.Supplement_Description;
             txtNappiCode.Text           = tblSupplement?.Nappi_code;
             txtCostE.Text    = tblSupplement?.Cost_excl.ToString();
             txtCostI.Text    = tblSupplement?.Cost_incl.ToString();
             txtStock.Text    = tblSupplement?.Current_Stock_Levels.ToString();
             txtMinLevel.Text = tblSupplement?.Min_Level.ToString();
         }
     }
 }
Example #2
0
        /// <summary>
        /// Save user input to database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            tblSupplement supplement = new tblSupplement
            {
                Supplement_id          = txtSupplementIDS.Text,
                Supplement_Description = txtDescription.Text,
                Cost_excl            = decimal.Parse(txtCostE.Text),
                Cost_incl            = decimal.Parse(txtCostI.Text),
                Min_Level            = int.Parse(txtMinLevel.Text),
                Current_Stock_Levels = int.Parse(txtStock.Text),
                Nappi_code           = txtNappiCode.Text,
                Supplier_Id          = DdlSupplierID.SelectedValue
            };

            IsUpdate = bool.Parse(hdnIsUpdate.Value);

            var dbSupplement = _repositoryWrapper.Suppliment.GetById(supplement.Supplement_id);

            if (!IsUpdate && dbSupplement != null)
            {
                lblError.Text = "Suppliment already exists in the database";
                return;
            }
            lblError.Text = string.Empty;

            if (dbSupplement == null)
            {
                _repositoryWrapper.Suppliment.Add(supplement);
            }
            else
            {
                _repositoryWrapper.Suppliment.Update(supplement, supplement.Supplement_id);
            }

            RedirectToList();
        }