示例#1
0
 private PartsViewModel ConvertDataModel_To_ViewModel(SparePartsDataModel p)
 {
     return(new PartsViewModel()
     {
         Id = p.Id, Name = p.Name, Price = p.Price
     });
 }
示例#2
0
 public PartsEditor(MiscController miscController, SparePartsDataModel model)
 {
     InitializeComponent();
     this.MiscController = miscController;
     this.Model          = model;
     LoadModel();
 }
示例#3
0
        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();
            }
        }
示例#4
0
        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);
            }
        }