using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Web.DynamicData; using System; using System.Linq; using Aspnet.Samples.DynamicData; namespace TicketCenter_Data { // Attach the TransferLogMetadata to the TransferLog class [MetadataType(typeof(TransferLogMetadata))] [Security(Role = "Users", Action = "Details")] [Security(Role = "Users", Action = "Edit")] [Security(Role = "Users", Action = "Insert")] [Security(Role = "Users", Action = "List")] 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}")] 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; } } }