public void Edit(int id, MilkUtilizeEditModel model) { try { using (var uow = new UnitOfWork(new DataContext())) { var obj = uow.MilkUtilizeRecords.Get(id); //obj.ActualDate = model.ActualDate; obj.Analysis = model.Analysis; obj.Demo = model.Demo; obj.RawMilkProcess = model.RawMilkProcess; obj.Remarks = model.Remarks; obj.Spillage = model.Spillage; obj.SpoilageQty = model.SpoilageQty; obj.SpoilageValue = model.SpoilageValue; obj.WithdrawnByProcessor = model.WithdrawnByProcessor; obj.Remarks = model.Remarks; uow.MilkUtilizeRecords.Edit(obj); uow.Complete(); } } catch (Exception) { throw; } }
private void Save() { //id greater than zero = edit //id equal to zero = add if (milkUtilizeRecordID == 0) { // Add new record var model = new MilkUtilizeAddModel(); model.ActualDate = dtDateSelection.Value; //model.Analysis = LocalUtils.ConvertToDouble(txtAnalysis.Text); //model.Demo = LocalUtils.ConvertToInteger(txtDemo.Text); //model.Remarks = txtRemarks.Text; //model.Spillage = LocalUtils.ConvertToDouble(txtSpillage.Text); //model.SpoilageQty = LocalUtils.ConvertToDouble(txtSpoilageQty.Text); //model.SpoilageValue = LocalUtils.ConvertToDouble(txtSpoilageValue.Text); //model.WithdrawnByProcessor = txtWithdrawnByProcessor.Text; //model.Remarks = txtRemarks.Text; Factories.CreateMilkUtilize().Add(model); milkUtilizeRecordID = model.ID; } else { if (!ValidateFields()) { LocalUtils.ShowValidationFailedMessage(this); return; } // Edit record var model = new MilkUtilizeEditModel(); model.Analysis = LocalUtils.ConvertToDouble(txtAnalysis.Text); model.Demo = LocalUtils.ConvertToInteger(txtDemo.Text); model.Remarks = txtRemarks.Text; model.Spillage = LocalUtils.ConvertToDouble(txtSpillage.Text); model.SpoilageQty = LocalUtils.ConvertToDouble(txtSpoilageQty.Text); model.SpoilageValue = LocalUtils.ConvertToDouble(txtSpoilageValue.Text); model.WithdrawnByProcessor = txtWithdrawnByProcessor.Text; model.Remarks = txtRemarks.Text; Factories.CreateMilkUtilize().Edit(milkUtilizeRecordID, model); mainPage.SetPage(pageList); } LocalUtils.ShowSaveMessage(this); }