Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                milkCollectionLogic = new MilkCollectionLogic();

                if (ValidateFields())
                {
                    //id greater than zero = edit
                    //id equal to zero = add

                    if (id == 0)
                    {
                        var model = new AddMilkCollectionModel();
                        model.ActualDate  = dtDate.Value;
                        model.FarmerID    = int.Parse(((ItemX)cboFarmer.SelectedItem).Value);
                        model.MilkClassID = int.Parse(((ItemX)cboMilkClass.SelectedItem).Value);
                        model.Volume      = double.Parse(txtVolume.Text);
                        milkCollectionLogic.Add(model);
                        MetroMessageBox.Show(this, "Record has been saved!", "Milk Collection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultUI();
                    }
                    else
                    {
                        var model = new EditMilkCollectionModel();
                        model.ActualDate  = dtDate.Value;
                        model.FarmerID    = int.Parse(((ItemX)cboFarmer.SelectedItem).Value);
                        model.MilkClassID = int.Parse(((ItemX)cboMilkClass.SelectedItem).Value);
                        model.Volume      = double.Parse(txtVolume.Text);
                        milkCollectionLogic.Edit(id, model);
                        MetroMessageBox.Show(this, "Record has been saved!", "Milk Collection", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadDefaultUI();
                    }
                }
                else
                {
                    // Validation error
                    MetroMessageBox.Show(this, "Invalid Field(s)!", "Milk Collection", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
 public void Add(AddMilkCollectionModel model)
 {
     try
     {
         using (var uow = new UnitOfWork(new DataContext()))
         {
             var obj = new MilkCollection();
             obj.ActualDate     = model.ActualDate;
             obj.CreateDateTime = DateTime.Now;
             obj.FarmerID       = model.FarmerID;
             obj.SupplyTypeID   = model.MilkClassID;
             obj.Volume         = model.Volume;
             uow.MilkCollections.Add(obj);
             uow.Complete();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }