private PartsViewModel ConvertDataModel_To_ViewModel(SparePartsDataModel p) { return(new PartsViewModel() { Id = p.Id, Name = p.Name, Price = p.Price }); }
public PartsEditor(MiscController miscController, SparePartsDataModel model) { InitializeComponent(); this.MiscController = miscController; this.Model = model; LoadModel(); }
public void AddOrUpdateParts(SparePartsDataModel model) { var part = context.Spare_Parts.FirstOrDefault(s => s.Id == model.Id); if (part != null) { part.Name = model.Name; part.Price = model.Price; this.EditEntity <SparePartsDataModel>(part); } else { context.Spare_Parts.Add(model); context.SaveChanges(); } }
private void btn_OK_Click(object sender, EventArgs e) { if (decimal.TryParse(tb_Price.Text, out decimal price) && price > 0) { if (Model == null) { Model = new SparePartsDataModel(); } Model.Name = tb_Name.Text; Model.Price = price; MiscController.AddOrUpdateParts(Model); } else { MessageBox.Show("Invalid Price", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }