public void Edit(int id, EditMilkClassModel model) { try { using (var uow = new UnitOfWork(new DataContext())) { var obj = uow.MilkClasses.Get(id); obj.Cost = model.Cost; obj.Description = model.Description; uow.MilkClasses.Edit(obj); uow.Complete(); } } catch (Exception) { throw; } }
private void btnSave_Click(object sender, EventArgs e) { try { if (ValidateFields()) { //id greater than zero = edit //id equal to zero = add if (id == 0) { var model = new AddMilkClassModel(); model.Description = txtDescription.Text; model.Cost = double.Parse(txtCost.Text); logic.Add(model); MetroMessageBox.Show(this, "Record has been saved!", messageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); LoadDefaultUI(); LoadGridList(); } else { var model = new EditMilkClassModel(); model.Description = txtDescription.Text; model.Cost = double.Parse(txtCost.Text); logic.Edit(id, 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); } } catch (Exception) { throw; } }