public static bool IsEventPaperValidForConference(Event ev) { List<Event> eventsForConferenceExceptThisOne = LoadByConferenceId(ev.ConferenceId).Where(dd => dd.EventId != ev.EventId.GetValueOrDefault()).ToList(); Paper paperForThisEvent = PaperManager.Load(ev.PaperId); return !eventsForConferenceExceptThisOne.SafeAny( dd => PaperManager.Load(dd.PaperId).PaperCategory == paperForThisEvent.PaperCategory); }
/// <summary> /// Saves a Event to the data store. /// </summary> /// <param name="item">The item to save</param> public static void Save(Event item) { if (item.IsItemModified) { if (item.EventId == null) { item.EventId = Insert(item); } else { Update(item); } } }
public bool Save(out string errorMessage) { Event eventEntity = new Event(); Transaction transaction = new Transaction(); if (UserControlMode == EnumUserControlMode.Edit && EventId.HasValue) { eventEntity = EventManager.Load(EventId.Value); transaction = TransactionManager.LoadByEvent(EventId.Value); } LoadEventFromForm(eventEntity); LoadTransactionFromForm(transaction); string eventError, transactionError = string.Empty; if (EventManager.Validate(eventEntity, out eventError) && TransactionManager.Validate(transaction, out transactionError)) { EventManager.Save(eventEntity, out errorMessage); if (eventEntity.EventId.HasValue) { transaction.EventId = eventEntity.EventId.Value; TransactionManager.Save(transaction, out errorMessage); TransactionId = transaction.TransactionId; } } else { errorMessage = string.Format("{0}{1}{2}", eventError, StringMethods.BreakTag, transactionError); } return errorMessage.IsNullOrWhiteSpace(); }
/// <summary> /// Updates a Event /// </summary> /// <param name="item">The Event item to save</param> private static void Update(Event item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@EventId", item.EventId), new SqlParameter("@ConferenceId", item.ConferenceId), new SqlParameter("@PaperId", item.PaperId), new SqlParameter("@FoodPreferenceId", item.FoodPreference), new SqlParameter("@Comments", item.Comments), new SqlParameter("@StartDate", item.StartDate), new SqlParameter("@EndDate", item.EndDate) }; DataManager.ExecuteProcedure(ConferencePlusConnectionString, "Event_Update", parameters); }
/// <summary> /// Inserts a new Event /// </summary> /// <param name="item">The Event item to insert</param> /// <returns>The id of the Event item just inserted</returns> private static int Insert(Event item) { List<SqlParameter> parameters = new List<SqlParameter> { new SqlParameter("@ConferenceId", item.ConferenceId), new SqlParameter("@PaperId", item.PaperId), new SqlParameter("@FoodPreferenceId", item.FoodPreference), new SqlParameter("@Comments", item.Comments), new SqlParameter("@StartDate", item.StartDate), new SqlParameter("@EndDate", item.EndDate) }; return Convert.ToInt32(DataManager.ExecuteScalarProcedure(ConferencePlusConnectionString, "Event_Insert", parameters)); }
/// <summary> /// Save Event Entity /// </summary> /// <param name="item">Entity to save</param> /// <param name="errorMessage">Error Message</param> /// <returns>return true if save successfully, else return false</returns> public static bool Save(Event item, out string errorMessage) { bool isValid = Validate(item, out errorMessage); if (isValid) { EventDao.Save(item); } return isValid; }
public static bool IsEventValidForConference(Event ev) { Conference conference = ConferenceManager.Load(ev.ConferenceId); return DateTimeMethods.DoDatesOverlap(conference.StartDate, conference.EndDate, ev.StartDate, ev.EndDate); }
/// <summary> /// Validate Event Entity /// </summary> /// <param name="item">Entity to validate</param> /// <param name="errorMessage">error message if vlidation failed</param> /// <returns>return true if entity passes validation logic, else return false</returns> public static bool Validate(Event item, out string errorMessage) { StringBuilder builder = new StringBuilder(); if (!item.EndDate.IsValidWithSqlDateStandards()) { builder.AppendHtmlLine("*End date is required"); } if (!item.StartDate.IsValidWithSqlDateStandards()) { builder.AppendHtmlLine("*Start date is required"); } if (item.EndDate.OnOrBefore(item.StartDate)) { builder.AppendHtmlLine("*End date must be after start date"); } if (item.ConferenceId == default(int)) { builder.AppendHtmlLine("*Conference is required"); } if (!IsEventValidForConference(item)) { builder.AppendHtmlLine("*Event is not valid for the selected conference"); } if (item.FoodPreference == EnumFoodPreference.None) { builder.AppendHtmlLine("*Food preference is required"); } if (item.PaperId == default(int)) { builder.AppendHtmlLine("*Paper is required"); } if (!IsEventPaperValidForConference(item)) { builder.AppendHtmlLine("*A paper of this topic is already registered for this conference"); } errorMessage = builder.ToString(); return errorMessage.IsNullOrWhiteSpace(); }
private void LoadEventFromForm(Event eventEntity) { eventEntity.Comments = txtComments.Text.TrimSafely(); eventEntity.ConferenceId = ConferenceId; eventEntity.EndDate = rdtpEndDate.SelectedDate.GetValueOrDefault(); eventEntity.FoodPreference = EnumerationsHelper.ConvertFromString<EnumFoodPreference>(rcbFoodPreference.SelectedValue); eventEntity.PaperId = int.Parse(rcbPaper.SelectedValue); eventEntity.StartDate = rdtpStartDate.SelectedDate.GetValueOrDefault(); }