Esempio n. 1
0
        public static List <ProductFeed> GetProductFeed(DateTime?startdate, DateTime?enddate)
        {
            try
            {
                List <ProductFeed> returnValues = null;

                using (TransactionScope scope = new TransactionScope())
                {
                    using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["WebModules"].ConnectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("hcc_ProductFeed", conn))
                        {
                            conn.Open();

                            SqlParameter prm1 = new SqlParameter("@start", SqlDbType.DateTime);
                            prm1.Value = startdate;
                            SqlParameter prm2 = new SqlParameter("@end", SqlDbType.DateTime);
                            prm2.Value      = enddate;
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.Add(prm1);
                            cmd.Parameters.Add(prm2);

                            SqlDataReader t = cmd.ExecuteReader();

                            if (t != null)
                            {
                                returnValues = ProductFeed.GetFromReader(t);
                            }
                            else
                            {
                                returnValues = null;
                            }
                            cmd.Dispose();
                            conn.Close();
                            conn.Dispose();
                        }
                    }
                    scope.Complete();
                }
                if (returnValues != null)
                {
                    return(returnValues);
                }
                else
                {
                    throw new Exception("GetMenuItemsByDateRange could not be returned.");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public static List <ProductFeed> GetFromReader(SqlDataReader reader)
        {
            try
            {
                var Host = "https://www.healthychefcreations.com";
                //var Host = "dev.healthychefcreations.com";
                var HostAdmin = "https://admin.healthychefcreations.com";
                //var HostAdmin = "devadmin.healthychefcreations.com";
                List <ProductFeed> retVals = new List <ProductFeed>();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ProductFeed retVal = new ProductFeed();
                        retVal.TypeId = int.Parse(reader["TypeId"].ToString());
                        if (int.Parse(reader["TypeId"].ToString()) == 1)
                        {
                            retVal.MenuItemId = reader["ItemId"].ToString();
                        }
                        else
                        {
                            retVal.MenuItemId = "PR-" + reader["ItemId"].ToString();
                        }
                        if (int.Parse(reader["TypeId"].ToString()) != 1)
                        {
                            retVal.MenuId = int.Parse(reader["MenuId"].ToString());
                        }
                        if (int.Parse(reader["TypeId"].ToString()) != 2)
                        {
                            retVal.MealTypeId = int.Parse(reader["MealTypeId"].ToString());
                        }
                        retVal.ItemTitle       = reader["ItemName"].ToString();
                        retVal.ItemDescription = reader["ItemDescription"].ToString();
                        retVal.ItemLink        = Host + "/browse-menu.aspx";
                        retVal.ItemCondition   = "new";
                        retVal.Price           = Math.Round(decimal.Parse(reader["ItemPrice"].ToString()), 2);
                        retVal.ItemPrice       = "$" + retVal.Price;
                        if (Boolean.Parse(reader["ItemAvailability"].ToString()))
                        {
                            retVal.ItemAvailability = "In Stock";
                        }
                        else
                        {
                            retVal.ItemAvailability = "Out Of Stock";
                        }
                        if (reader["ItemImagePath"].ToString() == "" || reader["ItemImagePath"].ToString() == null && int.Parse(reader["TypeId"].ToString()) == 1)
                        {
                            retVal.ItemImageLink = Host + "/userfiles/images/genericMenu.jpg";
                        }
                        else if (reader["ItemImagePath"].ToString() == "" || reader["ItemImagePath"].ToString() == null && int.Parse(reader["TypeId"].ToString()) == 2)
                        {
                            retVal.ItemImageLink = "N/A";
                        }
                        else
                        {
                            retVal.ItemImageLink = HostAdmin + reader["ItemImagePath"].ToString();
                        }
                        retVal.ItemMPN = retVal.MenuItemId;
                        retVal.Brand   = "Healthy Chef Creations";
                        retVal.GoogleProductCategory = "Food, Beverages & Tobacco > Food Items > Prepared Foods > Prepared Meals & Entrees";
                        if (retVals.Count(x => x.MenuItemId == retVal.MenuItemId && x.TypeId == retVal.TypeId) == 0)
                        {
                            retVals.Add(retVal);
                        }
                    }

                    reader.Close();
                }

                foreach (var item in retVals.Where(x => x.TypeId == 2)) //updating URL's for programs
                {
                    switch (item.MenuId)
                    {
                    case 33:
                        item.ItemLink = Host + "/weight-loss-programs/healthy-weight-loss.aspx";
                        break;

                    case 34:
                        item.ItemLink = Host + "/meal-programs/healthy-mommy.aspx";
                        break;

                    case 49:
                        item.ItemLink = Host + "/meal-programs/healthy-living.aspx";
                        break;

                    case 59:
                        item.ItemLink = Host + "/weight-loss-programs/low-carb.aspx";
                        break;

                    case 61:
                        item.ItemLink = Host + "/weight-loss-programs/hcg-diet.aspx";
                        break;

                    case 50:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/50/HealthyLivingDinner";
                        break;

                    case 51:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/51/HealthyLivingDinner";
                        break;

                    case 53:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/53/HealthyLivingDinner";
                        break;

                    case 54:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/54/HealthyLivingBreakfastLunch";
                        break;

                    case 63:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/63/HealthyLivingBreakfast";
                        break;

                    case 64:
                        item.ItemLink = Host + "/Programs/DetailsbyCheckbox/64/HealthyLivingLunch";
                        break;
                    }
                }

                foreach (var item in retVals.Where(x => x.TypeId == 1))
                {
                    item.ItemLink = Host + "/ProductDescription?ItemName=" + item.ItemTitle;
                    //item.ItemLink = "http://localhost:49883//ProductDescription?ItemName=" + item.ItemTitle;
                }
                return(retVals);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }