public static bool SaveVATRevision(VATRevision vatRevision) { using (var session = NHibernateHelper.OpenSession()) { using (var tx = session.BeginTransaction()) { try { foreach (var item in vatRevision.VATList) { item.VATRevision = vatRevision; } session.SaveOrUpdate(vatRevision); tx.Commit(); log.Info("VAT Revisied"); } catch (Exception ex) { log.Error(ex); return false; } return true; } } }
public Winform_VATDetails(int _ID) { InitializeComponent(); //get VAT Percentages based on the _ID VATRevision _vatRevision = Builders.VATRevisionBuilder.GetVATRevisionInfo(_ID); //load the controls this.vatRevision = _vatRevision; dtpFromYear.Value = vatRevision.DateOfRevision; this.vatPercentList = vatRevision.VATList.ToList(); }
protected override void SaveToolStrip_Click(object sender, EventArgs e) { errorProvider1.SetError(dtpFromYear, ""); int _ID = vatRevision == null ? 0 : vatRevision.ID; if (vatPercentList.Count == 0) MessageBox.Show("VAT percentage List cannot be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //todo: Verfiy what can be the constraints on RevisionDate //else if (DateTime.Compare(dtpFromYear.Value.Date, DateTime.Today.Date) < 0) //{ // errorProvider1.SetError(dtpFromYear, "Revision Date cannot be less than today"); // return; //} else if (Savers.VATPercentSavers.IsUniqueRevisionDate(dtpFromYear.Value.Date, _ID)) { MessageBox.Show("The Date of Revision already exists. Enter a different Date and try again", "Duplicate Revision Date", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } /*Add Or Updating Existing VAT Revisions.*/ if (vatRevision == null) { vatRevision = new VATRevision(dtpFromYear.Value.Date, vatPercentList); } else { vatRevision.DateOfRevision = dtpFromYear.Value.Date; vatRevision.VATList = vatPercentList; } bool success = Savers.VATPercentSavers.SaveVATRevision(vatRevision); if (success) { UpdateStatus("VAT Revision added successfully", 100); this.Close(); } else { UpdateStatus("Error saving VAT Revision", 100); } //} }