Пример #1
0
 public Activity(DBActivity dbActivity)
 {
     Id       = dbActivity.ActivityId;
     Name     = dbActivity.Name;
     HexColor = dbActivity.HexColor;
     Icon     = dbActivity.Logo;
 }
Пример #2
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                DBActivity db2         = new DBActivity();
                Activity   addActivity = new Activity();

                addActivity.Category       = collection["categoryDropdown"];
                addActivity.Venue          = collection["Venue"];
                addActivity.Link           = collection["Link"];
                addActivity.PricePerPerson = collection["PricePerPerson"];
                addActivity.StreetAddress  = collection["StreetAddress"];
                addActivity.City           = collection["City"];
                addActivity.State          = collection["State"];
                addActivity.Zip            = collection["Zip"];
                addActivity.PhoneNumber    = collection["PhoneNumber"];
                addActivity.DaysOpen       = collection["DaysOpen"];
                addActivity.TimesOpen      = collection["TimesOpen"];
                addActivity.Other          = collection["Other"];
                db2.Activities.Add(addActivity);
                db2.SaveChanges();

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.InnerException;
                return(View("AddActivityView"));
            }
        } // GET: ManageActivity
Пример #3
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                DBActivity db2           = new DBActivity();
                var        foundActivity = db2.Activities.Find(id);

                db2.Activities.Remove(foundActivity);
                db2.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.InnerException;
                return(View());
            }
        }
Пример #4
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                DBActivity db2           = new DBActivity();
                var        foundActivity = db2.Activities.Find(id);

                foundActivity.Venue          = collection["Venue"];
                foundActivity.Link           = collection["Link"];
                foundActivity.Category       = collection["Category"];
                foundActivity.StreetAddress  = collection["StreetAddress"];
                foundActivity.City           = collection["City"];
                foundActivity.State          = collection["State"];
                foundActivity.Zip            = collection["Zip"];
                foundActivity.DaysOpen       = collection["DaysOpen"];
                foundActivity.TimesOpen      = collection["TimesOpen"];
                foundActivity.PricePerPerson = collection["PricePerPerson"];
                foundActivity.PhoneNumber    = collection["PhoneNumber"];
                db2.SaveChanges();

                return(RedirectToAction("List", "ManageActivity"));
            }
            catch (DbEntityValidationException e)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    foreach (var ve in eve.ValidationErrors)
                    {
                        TempData["Error"] = string.Format("- Property: \"{0}\", Error: \"{1}\"",
                                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                return(View());
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.InnerException;
                return(View());
            }
        }
Пример #5
0
        public override void WriteLine(string value)
        {
            //string temp = System.Text.RegularExpressions.Regex.Match(value, @"\[([^)]*)\]").Groups[1].Value;
            if (IsInIgnoreList(value))
            {
                return;
            }

            if (IgnoreFlagChecked(value))
            {
                return;
            }


            string sessionID = HttpContext.Current.Session.SessionID;
            int    userID    = Convert.ToInt32(HttpContext.Current.Session["UserID"]);

            using (Broker.LoggingDataAccess.LoggingDataContext dc = new LoggingDataContext())
            {
                if (userID > 0)
                {
                    int activityTypeID   = 0;
                    int dBUpdatedTableID = 0;

                    int start  = 0;
                    var match2 = string.Empty;

                    if (value.StartsWith("SELECT"))
                    {
                        if (value.StartsWith("SELECT COUNT"))
                        {
                            return;
                        }
                        activityTypeID = 3;
                        start          = value.IndexOf("FROM") + 4;
                        match2         = value.Substring(start, value.IndexOf("AS") - start);
                    }
                    else
                    {
                        if (value.StartsWith("INSERT"))
                        {
                            activityTypeID   = 1;
                            dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                            start            = value.IndexOf("INTO") + 4;
                            match2           = value.Substring(start, value.IndexOf("(") - start);
                        }
                        else
                        {
                            if (value.StartsWith("DELETE"))
                            {
                                activityTypeID   = 2;
                                dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                                start            = value.IndexOf("FROM") + 4;
                                match2           = value.Substring(start, value.IndexOf("AS") - start);
                            }
                            else
                            {
                                if (value.StartsWith("UPDATE"))
                                {
                                    activityTypeID = 4;

                                    dBUpdatedTableID = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().ID;
                                    start            = value.IndexOf("FROM") + 4;
                                    match2           = dc.DBUpdatedTables.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.TimeOfUpdate).FirstOrDefault().TableName;
                                }
                                else
                                {
                                    if (value.StartsWith("-- @p"))
                                    {
                                        activityTypeID = 5;
                                        //start = string.Empty;
                                        //match2 = string.Empty;
                                    }
                                }
                            }
                        }
                    }


                    if (activityTypeID > 0)
                    {
                        if (activityTypeID < 5)
                        {
                            DBActivity activity = new DBActivity();

                            activity.ActivityTypeID = activityTypeID;
                            activity.Query          = value;
                            activity.UserID         = userID;
                            activity.SessionID      = sessionID;
                            activity.Date           = DateTime.Now;
                            activity.TableName      = match2.ToString();
                            if (dBUpdatedTableID > 0)
                            {
                                activity.DBUpdatedTableID = dBUpdatedTableID;
                            }

                            try
                            {
                                dc.DBActivities.InsertOnSubmit(activity);
                                dc.SubmitChanges();
                            }
                            catch { }
                        }
                        else
                        {
                            if (activityTypeID == 5)
                            {
                                DBActivityParameter activityParameter = new DBActivityParameter();
                                DBActivity          tempActivity      = dc.DBActivities.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(c => c.Date).FirstOrDefault();
                                //DBActivity tempActivity = DBActivity.Table.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(c => c.Date).FirstOrDefault();
                                if (tempActivity != null)
                                {
                                    int activityID = tempActivity.ID;

                                    string substring      = value.Substring(3);
                                    string parameterName  = substring.Split(':').First();
                                    int    startIndex     = value.IndexOf("[") + 1;
                                    string parameterValue = value.Substring(startIndex, value.IndexOf("]") - startIndex);

                                    int    startIndex2   = value.IndexOf("Input") + 6;
                                    string parameterType = value.Substring(startIndex2, (value.IndexOf("(") - 1) - startIndex2);

                                    string tempQuery = tempActivity.Query;
                                    if (parameterType.Contains("nvarchar"))
                                    {
                                        tempQuery = tempQuery.Replace(parameterName, "'" + parameterValue + "'");
                                    }
                                    else
                                    {
                                        tempQuery = tempQuery.Replace(parameterName, parameterValue);
                                    }

                                    tempActivity.Query = tempQuery;
                                    dc.SubmitChanges();

                                    activityParameter.DBActivityID = activityID;
                                    activityParameter.Value        = value;

                                    dc.DBActivityParameters.InsertOnSubmit(activityParameter);
                                    dc.SubmitChanges();
                                }
                            }
                        }
                    }
                }
            }
        }
        public ActionResult Index(FormCollection form)
        {
            ViewBag.Message = "Results page.";
            //Variables assigned values based on user values entered in the form (# of people, Budget, and Cuisine Type)
            Request dataRequest = new Request();

            dataRequest.numPeople   = int.Parse(form["numPeople"]);
            dataRequest.Budget      = int.Parse(form["Budget"]);
            dataRequest.CuisineType = form["foodDropdown"];
            dataRequest.Category    = form["categoryDropdown"];
            dataRequest.Zipcode     = form["Zipcode"];


            //'price' variable is assigned to 1,2,3, 4, or 5 . This value is created by methods in the QueryHelper class
            string price = QueryHelper.RestaurantPrice(dataRequest.Budget, dataRequest.numPeople);

            //New FactualDriver object being created using the variable names previously assigned to keys
            Factual Factual = new Factual(OATHKEY, OATHSECRET);
            string  data    = null;

            try
            {
                data = Factual.Fetch("restaurants",
                                     new Query()
                                     .Field("price")
                                     .Equal(price)
                                     .Field("cuisine")
                                     .Equal(dataRequest.CuisineType.ToLower())
                                     .Field("postcode")
                                     .Equal(dataRequest.Zipcode)
                                     .Offset(0)
                                     .Limit(20));
            }
            catch
            {
                data = "{Error: 'Please try again'}";
            }

            var jData = JObject.Parse(data);                         //'data' is being Parsed from string to JObject type

            List <Restaurant> restaurants = new List <Restaurant>(); //Initializing a new list of resaurants

            //Each item in 'restaurants' list is initialized as a new 'restaurant'

            if (jData["Error"] == null)
            {
                foreach (var gcVar in jData["response"]["data"].ToList())
                {
                    Restaurant restaurant = new Restaurant();
                    dynamic    restVar    = JObject.Parse(gcVar.ToString());
                    //'restVar' is created and holds the properties of a Resaurant object (these properties are from the Restaurant class: name, address, etc...)

                    //'timeString' variable assigned value based on day of the week
                    //Used for finding hours of operation for restaurants for the current day of the week

                    string timeString = System.DateTime.Now.DayOfWeek.ToString().ToLower();

                    if (restVar["hours"] != null)
                    {
                        var hours = restVar["hours"][timeString];
                        if (hours != null)
                        {
                            restaurant.Hours = hours.ToString();
                        }
                    }
                    //The new Restaurant object named 'restaurant' has its properties assigned values. These values are taken from the 'restVar' variable
                    restaurant.Name       = restVar.name;
                    restaurant.PriceRange = (PriceRange)restVar.price;
                    //'PriceRange' is an enum found in the Restaurant class
                    restaurant.Address = restVar.address;
                    restaurant.ZipCode = restVar.postcode;
                    restaurant.Website = restVar.website;

                    restaurant.CuisineTypes = new List <string>();
                    //Many restaurants serve multiple cuisine types so a list is created to display these types
                    foreach (var cuisineVar in restVar.cuisine)
                    {
                        restaurant.CuisineTypes.Add(cuisineVar.ToString());
                        //The foreach loop iterates through the multiple types and adds them to the 'restaurant.CuisineTypes' list
                    }

                    restaurant.Description = new List <string>();
                    //Just like the CuisineTypes list foreach loop, but for restaurant description
                    foreach (var desVar in restVar.category_labels)
                    {
                        restaurant.Description.Add(desVar.ToString());
                    }

                    restaurant.Id = restaurants.Count;
                    restaurants.Add(restaurant);
                    //Now the 'restaurant' is added to the list named 'restaurants' and the foreach loop repeats this process
                }
            }

            string activityCategory = form["categoryDropdown"];
            string zipcode          = form["Zipcode"];
            string qString          = TMQueryString(zipcode, activityCategory, "10");

            List <Activity> activities   = new List <Activity>();
            List <Activity> tempActivity = ActivitiesRequest(qString);


            foreach (Activity activity in tempActivity)
            {
                if (activity.PricePerPerson != null)
                {
                    if (decimal.Parse(activity.PricePerPerson) <= (((decimal)dataRequest.Budget / 2) / (decimal)dataRequest.numPeople))
                    {
                        activities.Add(activity);
                    }
                }
                else
                {
                    activities.Add(activity);
                }
            }

            if (zipcode.Substring(0, 3) == "495")
            {
                using (DBActivity db = new DBActivity())
                {
                    foreach (var activity in db.Activities)
                    {
                        if (activity.DaysOpen != null && !string.IsNullOrWhiteSpace(activity.PricePerPerson))
                        {
                            if (double.Parse(activity.PricePerPerson) <=
                                (dataRequest.Budget * .5 / dataRequest.numPeople))
                            {
                                Activity newActivity = new Activity();

                                newActivity.Category       = activity.Category;
                                newActivity.City           = activity.City;
                                newActivity.DaysOpen       = activity.DaysOpen;
                                newActivity.Id             = activity.Id;
                                newActivity.Link           = activity.Link;
                                newActivity.PhoneNumber    = activity.PhoneNumber;
                                newActivity.PricePerPerson = activity.PricePerPerson;
                                newActivity.State          = activity.State;
                                newActivity.StreetAddress  = activity.StreetAddress;
                                newActivity.TimesOpen      = activity.TimesOpen;
                                newActivity.Venue          = activity.Venue;
                                newActivity.Zip            = activity.Zip;

                                decimal activityBudget = (((decimal)dataRequest.Budget / 2) / (decimal)dataRequest.numPeople);
                                if (decimal.Parse(newActivity.PricePerPerson) <= activityBudget)
                                {
                                    activities.Add(newActivity);
                                }
                            }
                        }
                    }
                }
            }


            ResultViewModel result = new ResultViewModel();

            result.Restuarants = restaurants;
            result.SetRandomRestaurant();

            result.Activities = activities;
            result.SetRandomActivity();


            return(View("ResultTemp", result));
        }
Пример #7
0
        public ActionResult Edit(int id)
        {
            DBActivity db2 = new DBActivity();

            return(View(db2.Activities.Find(id)));
        }
Пример #8
0
        public ActionResult List()
        {
            DBActivity db2 = new DBActivity();

            return(View(db2.Activities.ToList()));
        }