/// <summary>
        /// Calculates Fee
        /// </summary>
        /// <param name="conferenceId" />
        /// <param name="feeType" />
        /// <param name="conferenceFee" />
        /// <returns>Fee for specific FeeType</returns>
        public static decimal CalculateFee(int conferenceId, EnumFeeType feeType, out ConferenceFee conferenceFee)
        {
            decimal fee = default(decimal);
            conferenceFee = null;

            Conference conference = ConferenceManager.Load(conferenceId);
            if (conference != null)
            {
                fee = conference.BaseFee;

                List<ConferenceFee> conferenceFeeList = LoadOnConferenceId(conferenceId).Where(c => c.FeeType == feeType).ToList();
                if (conferenceFeeList.SafeAny())
                {
                    conferenceFee
                        = conferenceFeeList.FirstOrDefault(c => DateTimeMethods.DoDatesOverlap(c.EffectiveStartDate,
                                                                                               c.EffectiveEndDate,
                                                                                               DateTime.Today,
                                                                                               DateTime.Today));

                    if (conferenceFee != null)
                    {
                        fee *= conferenceFee.Multiplier;
                    }
                }
            }

            return fee;
        }
 /// <summary>
 /// Saves a ConferenceFee to the data store.
 /// </summary>
 /// <param name="item">The item to save</param>
 public static void Save(ConferenceFee item)
 {
     if (item.IsItemModified)
     {
         if (item.ConferenceFeeId == null)
         {
             item.ConferenceFeeId = Insert(item);
         }
         else
         {
             Update(item);
         }
     }
 }
        public bool SaveControl()
        {
            ConferenceFee confFeeToSave = new ConferenceFee { ConferenceId = ConferenceId };
            if (UserControlMode == EnumUserControlMode.Edit)
            {
                confFeeToSave = ConferenceFeeManager.Load(ConferenceFeeId);
            }

            confFeeToSave.FeeAdjustment = EnumerationsHelper.ConvertFromString<EnumFeeAdjustment>(ddlAdjustmentType.SelectedValue);
            confFeeToSave.FeeType = EnumerationsHelper.ConvertFromString<EnumFeeType>(ddlFeeType.SelectedValue);
            confFeeToSave.Multiplier = (decimal)txtMultiplier.Value.GetValueOrDefault();
            confFeeToSave.EffectiveStartDate = dtStartPicker.SelectedDate.GetValueOrDefault();
            confFeeToSave.EffectiveEndDate = dtEndPicker.SelectedDate.GetValueOrDefault();

            string error;
            bool isValid = ConferenceFeeManager.Save(confFeeToSave, out error);
            lblError.Text = error;

            return isValid;
        }
 /// <summary>
 /// Updates a ConferenceFee
 /// </summary>
 /// <param name="item">The ConferenceFee item to save</param>
 private static void Update(ConferenceFee item)
 {
     List<SqlParameter> parameters
         = new List<SqlParameter>
             {
                 new SqlParameter("@ConferenceFeeId", item.ConferenceFeeId),
                 new SqlParameter("@ConferenceId", item.ConferenceId),
                 new SqlParameter("@FeeAdjustmentId", item.FeeAdjustment),
                 new SqlParameter("@FeeTypeId", item.FeeType),
                 new SqlParameter("@Multiplier", item.Multiplier),
                 new SqlParameter("@EffectiveStartDate", item.EffectiveStartDate),
                 new SqlParameter("@EffectiveEndDate", item.EffectiveEndDate)
             };
     DataManager.ExecuteProcedure(ConferencePlusConnectionString, "ConferenceFee_Update", parameters);
 }
 /// <summary>
 /// Inserts a new ConferenceFee
 /// </summary>
 /// <param name="item">The ConferenceFee item to insert</param>
 /// <returns>The id of the ConferenceFee item just inserted</returns>
 private static int Insert(ConferenceFee item)
 {
     List<SqlParameter> parameters
         = new List<SqlParameter>
             {
                 new SqlParameter("@ConferenceId", item.ConferenceId),
                 new SqlParameter("@FeeAdjustmentId", item.FeeAdjustment),
                 new SqlParameter("@FeeTypeId", item.FeeType),
                 new SqlParameter("@Multiplier", item.Multiplier),
                 new SqlParameter("@EffectiveStartDate", item.EffectiveStartDate),
                 new SqlParameter("@EffectiveEndDate", item.EffectiveEndDate)
             };
     return Convert.ToInt32(DataManager.ExecuteScalarProcedure(ConferencePlusConnectionString, "ConferenceFee_Insert", parameters));
 }
        /// <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();
        }
        /// <summary>
        /// Save ConferenceFee 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(ConferenceFee item, out string errorMessage)
        {
            bool isValid = Validate(item, out errorMessage);

            if (isValid)
            {
                ConferenceFeeDao.Save(item);
            }

            return isValid;
        }