コード例 #1
0
 public void Add(SupplyTypeModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj = new SupplyType();
         obj.Description   = model.Description;
         obj.SupplyClassID = model.SupplyClassID;
         obj.UnitPrice     = model.UnitPrice;
         uow.SupplyTypes.Add(obj);
         uow.Complete();
     }
 }
コード例 #2
0
 public void Edit(int id, SupplyTypeModel model)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj = uow.SupplyTypes.Get(id);
         obj.Description   = model.Description;
         obj.SupplyClassID = model.SupplyClassID;
         obj.UnitPrice     = model.UnitPrice;
         uow.SupplyTypes.Edit(obj);
         uow.Complete();
     }
 }
コード例 #3
0
 public SupplyTypeModel GetBy(int id)
 {
     using (var uow = new UnitOfWork(new DataContext()))
     {
         var obj   = uow.SupplyTypes.Get(id);
         var model = new SupplyTypeModel();
         if (obj != null)
         {
             model.Description   = obj.Description;
             model.UnitPrice     = obj.UnitPrice;
             model.ID            = obj.SupplyTypeID;
             model.SupplyClassID = obj.SupplyClassID;
         }
         return(model);
     }
 }
コード例 #4
0
        private void Save()
        {
            if (ValidateFields())
            {
                //id greater than zero = edit
                //id equal to zero = add
                if (supplyTypeID == 0)
                {
                    var model = new SupplyTypeModel();
                    model.Description   = txtDescription.Text;
                    model.UnitPrice     = double.Parse(txtUnitPrice.Text);
                    model.SupplyClassID = int.Parse(((ItemX)cboSupplyClass.SelectedItem).Value);
                    Factories.CreateSupplyType().Add(model);

                    MetroMessageBox.Show(this, "Record has been saved!", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadDefaultUI();
                    LoadGridList();
                }
                else
                {
                    var model = new SupplyTypeModel();
                    model.Description   = txtDescription.Text;
                    model.UnitPrice     = double.Parse(txtUnitPrice.Text);
                    model.SupplyClassID = int.Parse(((ItemX)cboSupplyClass.SelectedItem).Value);
                    Factories.CreateSupplyType().Edit(supplyTypeID, model);
                    MetroMessageBox.Show(this, "Record has been saved!", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LoadDefaultUI();
                    LoadGridList();
                }
            }
            else
            {
                // Validation error
                MetroMessageBox.Show(this, "Invalid Field(s)!", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }