/// <summary>
 /// Loads Conference by the id parameter
 /// </summary>
 /// <param name="conferenceId">Primary Key of Conference table</param>
 /// <returns>Conference entity</returns>
 public static Conference Load(int conferenceId)
 {
     SearchConference search
         = new SearchConference
             {
                 ConferenceId = conferenceId
             };
     return Search(search).FirstOrDefault();
 }
        /// <summary>
        /// Searches for Conference
        /// </summary>
        /// <param name="item" />
        /// <returns>An IEnumerable set of Conference</returns>
        public static IEnumerable<Conference> Search(SearchConference item)
        {
            List<SqlParameter> parameters
                = new List<SqlParameter>
                    {
                        new SqlParameter("@ConferenceId", item.ConferenceId),
                        new SqlParameter("@ActivityTypeId", item.ActivityType),
                        new SqlParameter("@Name", item.Name),
                        new SqlParameter("@BaseFee", item.BaseFee),
                        new SqlParameter("@Description", item.Description),
                        new SqlParameter("@StartDate", item.StartDate),
                        new SqlParameter("@EndDate", item.EndDate)
                    };

            DataSet set = DataManager.ExecuteProcedure(ConferencePlusConnectionString, "Conference_Get", parameters);
            IEnumerable<DataRow> dataRows = set.GetRowsFromDataSet();
            return ConvertToEntityObject(dataRows);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public static IEnumerable<Conference> LoadAll()
 {
     SearchConference search = new SearchConference();
     return Search(search);
 }
 /// <summary>
 /// Searches for Conference
 /// </summary>
 /// <param name="search" />
 /// <returns>An IEnumerable set of Conference</returns>
 public static IEnumerable<Conference> Search(SearchConference search)
 {
     return ConferenceDao.Search(search);
 }
        /// <summary>
        /// Validate ConferenceFee 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(ConferenceFee item, out string errorMessage)
        {
            StringBuilder builder = new StringBuilder();

            if (item.ConferenceId == default(int))
            {
                builder.AppendHtmlLine("*Please specify the conference to assign this fee to");
            }

            if (item.FeeAdjustment == EnumFeeAdjustment.None)
            {
                builder.AppendHtmlLine("*Please specify pricing type for this conference");
            }

            if (item.FeeType == EnumFeeType.None)
            {
                builder.AppendHtmlLine("*Please specify the type of fee for this conference");
            }

            if (item.Multiplier < 0)
            {
                builder.AppendHtmlLine("*Multiplier must be greater than or equal to 0");
            }

            if (!item.EffectiveStartDate.IsValidWithSqlDateStandards())
            {
                builder.AppendHtmlLine("*EffectiveStartDate is not valid with Sql Date Standards.");
            }

            if (!item.EffectiveEndDate.IsValidWithSqlDateStandards())
            {
                builder.AppendHtmlLine("*EffectiveEndDate is not valid with Sql Date Standards.");
            }

            if (item.EffectiveEndDate <= item.EffectiveStartDate)
            {
                builder.AppendHtmlLine("*Effective End Date needs to be after the Effective Start Date");
            }

            //Validate Conference
            if (builder.ToString().IsNullOrWhiteSpace())
            {
                SearchConference search = new SearchConference { ConferenceId = item.ConferenceId };
                Conference conference = ConferenceManager.Search(search).FirstOrDefault();

                if (conference == null)
                {
                    builder.AppendHtmlLine("*Conference Does not exists.");
                }
                else
                {
                    if (item.EffectiveStartDate.OnOrAfter(conference.StartDate))
                    {
                        builder.AppendHtmlLine("*There is a conflict with the Conference Start date.");
                    }
                }
            }

            //Validate ConferenceFees
            if (builder.ToString().IsNullOrWhiteSpace())
            {
                SearchConferenceFee searchList = new SearchConferenceFee { FeeType = item.FeeType, FeeAdjustment = item.FeeAdjustment, ConferenceId = item.ConferenceId };
                List<ConferenceFee> feeList = Search(searchList).Where(t => t.ConferenceFeeId != item.ConferenceFeeId.GetValueOrDefault(0)).ToList();

                if (feeList.SafeAny())
                {
                    builder.AppendHtmlLine("*Cannot contain a duplicate Conference Fee Type Entry.");
                }
                else
                {
                    SearchConferenceFee allSearch = new SearchConferenceFee { FeeType = item.FeeType, ConferenceId = item.ConferenceId };
                    List<ConferenceFee> allList = Search(allSearch).Where(t => t.ConferenceFeeId != item.ConferenceFeeId.GetValueOrDefault(0)).ToList();

                    if (allList.SafeAny())
                    {

                        if (allList.SafeAny(t => item.EffectiveStartDate.Between(t.EffectiveStartDate, t.EffectiveEndDate) || item.EffectiveEndDate.Between(t.EffectiveStartDate, t.EffectiveEndDate)))
                        {
                            builder.AppendHtmlLine("*There is a conflict with the dates for Conference Fee.");
                        }

                        if (builder.ToString().IsNullOrWhiteSpace())
                        {
                            if (item.FeeAdjustment == EnumFeeAdjustment.Early)
                            {
                                if (allList.SafeAny(t => item.EffectiveStartDate.OnOrAfter(t.EffectiveStartDate)))
                                {
                                    builder.AppendHtmlLine("*Early Fee Type needs to be before Normal or On-Site Fee Type.");
                                }
                            }
                            else if (item.FeeAdjustment == EnumFeeAdjustment.Normal)
                            {
                                if (allList.SafeAny(t => item.EffectiveStartDate.OnOrAfter(t.EffectiveStartDate) && t.FeeAdjustment == EnumFeeAdjustment.OnSite))
                                {
                                    builder.AppendHtmlLine("*Normal Fee Type needs to be before On-Site Fee Type.");
                                }
                                else if (allList.SafeAny(t => item.EffectiveStartDate.OnOrBefore(t.EffectiveEndDate) && t.FeeAdjustment == EnumFeeAdjustment.Early))
                                {
                                    builder.AppendHtmlLine("*Normal Fee Type needs to be after Early Fee Type.");
                                }
                            }
                            else if (item.FeeAdjustment == EnumFeeAdjustment.OnSite)
                            {
                                if (allList.SafeAny(t => item.EffectiveStartDate.OnOrBefore(t.EffectiveEndDate)))
                                {
                                    builder.AppendHtmlLine("*On-Site Fee Type needs to be after Normal or Early Fee Type.");
                                }
                            }
                        }
                    }
                }
            }

            errorMessage = builder.ToString();

            return errorMessage.IsNullOrWhiteSpace();
        }