public bool Update(MODEL.BrandModel model) { try { using (_context = new HSSNInventoryEntities()) { var editModel = _context.Brands.FirstOrDefault(a => a.BrandId == model.BrandId); if (editModel != null) { editModel.BrandName = model.BrandName; editModel.Description = model.Description; } _context.Entry(editModel).State = EntityState.Modified; _context.SaveChanges(); return(true); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
private void btnAdd_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtBrandName.Text)) { ClsCommon.ShowErrorToolTip(txtBrandName,"Please Enter The Brand Name"); } else { var model = new BrandModel { BrandId = _brandId, BrandName = txtBrandName.Text, Description = txtRemarks.Text }; if (_isNewMode) { _brandId = _brandService.Save(model); if (_brandId<=0) return; MessageBox.Show(@"Data Saved Successfully", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmBrand)_frmForm; frm.grdData.Rows.Add(_brandId, model.BrandName, model.Description); frm.grdData.Rows[frm.grdData.Rows.Count - 1].IsSelected = true; txtBrandName.Focus(); txtBrandName.Text = ""; txtRemarks.Text = ""; Notify(); } else { var success = _brandService.Update(model); if (!success) return; MessageBox.Show(@"Data Updated Successfully", @"Update", MessageBoxButtons.OK, MessageBoxIcon.Information); var frm = (FrmBrand)_frmForm; frm.grdData.CurrentRow.Cells["BrandName"].Value = model.BrandName; frm.grdData.CurrentRow.Cells["Description"].Value = model.Description; Notify(); Close(); } } }
public FrmBrandEntry(BrandModel model, Form frmForm) { InitializeComponent(); _frmForm = frmForm; _brandService = new BrandService(); if (model != null) { _isNewMode = false; _brandId = model.BrandId; txtBrandName.Text = model.BrandName; txtRemarks.Text = model.Description; btnAdd.Text = @"Update"; } else { _isNewMode = true; btnAdd.Text = @"Save"; } }
public int Save(MODEL.BrandModel model) { try { using (_context = new HSSNInventoryEntities()) { var addModel = new Brand() { BrandName = model.BrandName, Description = model.Description }; _context.Entry(addModel).State = EntityState.Added; _context.SaveChanges(); return(addModel.BrandId); } } catch (Exception e) { //Console.WriteLine(e); return(0); } }
private void btnEdit_Click(object sender, EventArgs e) { if (Convert.ToInt32(lblID.Text) <= 0) return; var model = new BrandModel() { BrandId = Convert.ToInt32(lblID.Text), BrandName = lblName.Text, Description = lblRemarks.Text }; var frm = new FrmBrandEntry(model, this); frm.ShowDialog(this); }