示例#1
0
        /// <summary>
        /// Get the hours for a business
        /// </summary>
        /// <param name="business"></param>
        /// <returns></returns>
        public static List <BaseInfo> BusinessHours(Business business)
        {
            Select data = new Select();

            data.AddColumns("day, business.businessid, opentime, closetime");
            data.AddFrom($"business left outer join businesshours on business.businessid = businesshours.businessid ");
            data.AddFilter($"business.businessid = '{business.Businessid}'");

            return(CreateList(typeof(BusinessHours), RunQuery(data)));
        }
示例#2
0
        /// <summary>
        /// Gets the Attributes, Categories, and Hours for the selected business
        /// </summary>
        /// <param name="business">Selected business</param>
        /// <returns>Dictionary of all the information</returns>
        public static Dictionary <string, string> BusinessInformation(Business business)
        {
            Dictionary <string, string> queryDictionary = new Dictionary <string, string>();
            StringBuilder sb = new StringBuilder();

            Select attributes = new Select("businessattributes");

            attributes.AddColumns("attributename, value");
            attributes.AddFilter($"businessid = '{business.Businessid}'");
            attributes.AddFilter("value <> 'False'");
            attributes.SetOrderBy("attributename");
            DataTable queryResults = RunQuery(attributes);

            // Attributes
            foreach (DataRow row in queryResults.Rows)
            {
                object[] element = row.ItemArray;
                if (element[1].ToString().Trim().ToLower() == "true")
                {
                    sb.AppendLine(element[0].ToString() + ", ");
                }
                else
                {
                    sb.AppendLine(element[0].ToString() + "(" + element[1].ToString() + "), ");
                }
            }

            // Remove the final appendline and comma
            if (sb.Length > 4)
            {
                sb.Remove(sb.Length - 4, 4);
            }

            queryDictionary.Add("attributes", sb.ToString());
            queryResults.Clear();
            sb.Clear();

            Select categories = new Select("businesscategories");

            categories.AddColumns("categoryname");
            categories.AddFilter($"businessid = '{business.Businessid}'");
            categories.SetOrderBy("categoryname");
            queryResults = RunQuery(categories);

            // Categories
            foreach (DataRow row in queryResults.Rows)
            {
                object[] element = row.ItemArray;
                sb.AppendLine(element[0].ToString());
            }
            queryDictionary.Add("categories", sb.ToString());

            queryResults.Clear();
            sb.Clear();

            Select innerHours = new Select("business");

            innerHours.AddColumns("to_char(current_timestamp, 'FMDay'::text) as today, business.businessid");

            Select hours = new Select();

            hours.AddColumns("today, opentime, closetime");
            hours.AddFrom($"({Build(innerHours)}) as tempquery left outer join businesshours on tempquery.businessid = businesshours.businessid and tempquery.today = businesshours.day ");
            hours.AddFilter($"tempquery.businessid = '{business.Businessid}'");

            queryResults = RunQuery(hours);

            // Hours
            foreach (DataRow row in queryResults.Rows)
            {
                object[] element = row.ItemArray;
                sb.AppendLine("Today (" + element[0].ToString() + ")");
                sb.AppendLine($"  Opens: {ConvertTimeSpan(element[1])}");
                sb.AppendLine($"  Closes: {ConvertTimeSpan(element[2])}");
            }
            queryDictionary.Add("hours", sb.ToString());

            return(queryDictionary);
        }