using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Web.DynamicData; using System; using System.Linq; namespace TicketCenter_Data { // Attach the TransferLogMetadata to the TransferLog class [MetadataType(typeof(TransferLogMetadata))] public partial class TransferLog { partial void OnValidate(System.Data.Linq.ChangeAction action) { if (action == System.Data.Linq.ChangeAction.Insert || action == System.Data.Linq.ChangeAction.Update) { var dc = new ITCDataContext(); var q1 = dc.TicketsAllocations.SingleOrDefault(c => c.JKID == this.JKIDFrom && c.EventID == this.EventID); q1.TicketsIssued -= this.QtyTransfer; if (q1.TicketsIssued >= 0) { dc.SubmitChanges(); } else { throw new ValidationException("Can only transfer " + (this.QtyTransfer + q1.TicketsIssued) + " tickets."); } var q2 = dc.TicketsAllocations.SingleOrDefault(c => c.JKID == this.JKIDTo && c.EventID == this.EventID); q2.TicketsIssued += this.QtyTransfer; dc.SubmitChanges(); Modified = DateTime.Now; //Update the Timestamp in Table TransferLog } } } [TableName("Transfer In Out")] public class TransferLogMetadata { [DisplayName("Transfer Date")] [DefaultValue("mm-dd-yyyy")] [DisplayFormat(DataFormatString = "{0:MM-dd-yyyy}")] [UIHint("CalendarDateTime")] public object DateTransfer { get; set; } [DisplayName("Quantity")] public object QtyTransfer { get; set; } [DisplayName("From JK")] public object JK { get; set; } [DisplayName("To JK")] public object JK1 { get; set; } // Columns I want hidden [ScaffoldColumn(false)] public object Modified { get; set; } } }