/// <summary> /// Create a new Meeting object. /// </summary> /// <param name="meetingId">Initial value of the MeetingId property.</param> /// <param name="start">Initial value of the Start property.</param> /// <param name="end">Initial value of the End property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="location">Initial value of the Location property.</param> /// <param name="minimumAttendees">Initial value of the MinimumAttendees property.</param> /// <param name="maximumAttendees">Initial value of the MaximumAttendees property.</param> public static Meeting CreateMeeting(global::System.Int32 meetingId, global::System.DateTime start, global::System.DateTime end, global::System.String title, global::System.String location, global::System.Int16 minimumAttendees, global::System.Int16 maximumAttendees) { Meeting meeting = new Meeting(); meeting.MeetingId = meetingId; meeting.Start = start; meeting.End = end; meeting.Title = title; meeting.Location = location; meeting.MinimumAttendees = minimumAttendees; meeting.MaximumAttendees = maximumAttendees; return meeting; }
public static ValidationResult PreventDoubleBooking(Meeting meeting, ValidationContext validationContext) { if (validationContext.Items.ContainsKey("AllowOverBooking")) { bool allowOverBooking = (bool)validationContext.Items["AllowOverBooking"]; if (!allowOverBooking) { var meetingData = validationContext.GetService(typeof(IMeetingDataProvider)) as IMeetingDataProvider; if (meetingData != null) { var conflicts = from other in meetingData.Meetings.Except(new[] { meeting }) where other.Location == meeting.Location // Check for conflicts by seeing if the times overlap in any way && ( (other.Start >= meeting.Start && other.Start <= meeting.End) || (meeting.Start >= other.Start && meeting.Start <= other.End) || (other.End >= meeting.Start && other.End <= meeting.End) || (meeting.End >= other.Start && meeting.End <= other.End) ) select other; if (conflicts.Any()) { return new ValidationResult( "The location selected is already booked at this time.", new[] { "Location", "Start", "End" }); } } } } return ValidationResult.Success; }
/// <summary> /// Deprecated Method for adding a new object to the Meetings EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToMeetings(Meeting meeting) { base.AddObject("Meetings", meeting); }
/// <summary> /// Ensure that long meetings don't include too many attendees. /// </summary> /// <param name="meeting">The meeting to validate.</param> /// <returns> /// A <see cref="ValidationResult"/> with an error or <see cref="ValidationResult.Success"/>. /// </returns> public static ValidationResult PreventExpensiveMeetings(Meeting meeting) { TimeSpan duration = meeting.End - meeting.Start; int attendees = (meeting.MaximumAttendees + meeting.MinimumAttendees) / 2; int cost = attendees * 50 * duration.Hours; if (cost > 10000) { return new ValidationResult("Meetings cannot cost the company more than $10,000."); } return ValidationResult.Success; }