예제 #1
0
        public static bool updatePlaceInput(FormCollection placeUpdate)
        {
            // Valid place input
            if (!ValidationModel.LengthAndNotSpecialValidation(placeUpdate["name"]) ||
                !ValidationModel.LengthAndNotSpecialValidation(placeUpdate["address"]) ||
                !ValidationModel.LengthAndNotSpecialValidation(placeUpdate["description"]) ||
                !ValidationModel.isDouble(placeUpdate["lat"]) ||
                !ValidationModel.isDouble(placeUpdate["lng"]))
            {
                return(false);
            }

            var db      = new SqlConnectionDataContext();
            int placeID = int.Parse(placeUpdate["placeID"]);

            var placeObj =
                (from place in db.Places
                 where place.Id == placeID
                 select place).SingleOrDefault();

            // Execute the query, and change the column values
            // you want to change.

            placeObj.Name        = placeUpdate["name"];
            placeObj.Address     = placeUpdate["address"];
            placeObj.Description = placeUpdate["description"];
            placeObj.lat         = double.Parse(placeUpdate["lat"]);
            placeObj.lng         = double.Parse(placeUpdate["lng"]);

            // Insert any additional changes to column values.

            // Submit the changes to the database.
            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception e)
            {
                return(false);
                // Provide for exceptions.
            }

            return(true);
        }
예제 #2
0
        public static bool updateUserInput(FormCollection userUpdate)
        {
            // Valid user input
            if (!ValidationModel.EmailValidation(userUpdate["email"]) ||
                !ValidationModel.LengthAndNotSpecialValidation(userUpdate["name"]) ||
                !ValidationModel.LengthAndNotSpecialValidation(userUpdate["address"]) ||
                !ValidationModel.isInt(userUpdate["admin"]))
            {
                return(false);
            }

            var db     = new SqlConnectionDataContext();
            int userID = int.Parse(userUpdate["userID"]);

            var userObj =
                (from user in db.UserAccounts
                 where user.UserID == userID
                 select user).SingleOrDefault();

            // Execute the query, and change the column values
            // you want to change.

            userObj.DisplayName = userUpdate["name"];
            userObj.Address     = userUpdate["address"];
            userObj.Email       = userUpdate["email"];
            userObj.isAdmin     = Byte.Parse(userUpdate["admin"]);

            // Insert any additional changes to column values.

            // Submit the changes to the database.
            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
                return(false);
                // Provide for exceptions.
            }

            return(true);
        }
예제 #3
0
        public static void updateEventInput(FormCollection eventUpdate)
        {
            // Valid event input
            if (!ValidationModel.LengthAndNotSpecialValidationMaxOnly(eventUpdate["title"]) ||
                !ValidationModel.isDateTime(eventUpdate["date"]) ||
                !ValidationModel.ValidAttendies(eventUpdate["attendies"]) ||
                !ValidationModel.ValidDuration(eventUpdate["duration"]) ||
                !ValidationModel.LengthAndNotSpecialValidationMaxOnly(eventUpdate["notes"]))
            {
                return;
            }

            var db      = new SqlConnectionDataContext();
            int eventID = int.Parse(eventUpdate["eventID"]);

            var eventObj =
                (from e in db.SportEvents
                 where e.EventID == eventID
                 select e).SingleOrDefault();

            // Execute the query, and change the column values
            // you want to change.

            eventObj.title        = eventUpdate["title"];
            eventObj.Date         = DateTime.Parse(eventUpdate["date"]);
            eventObj.MaxAttendies = int.Parse(eventUpdate["attendies"]);
            eventObj.Duration     = int.Parse(eventUpdate["duration"]);
            eventObj.notes        = eventUpdate["notes"];

            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);

                // Provide for exceptions.
            }
        }
예제 #4
0
        public static void createEvent(FormCollection sportEventModel)
        {
            var dataContext = new SqlConnectionDataContext();
            int placeID     = getPlaceIDByName(dataContext, sportEventModel["location"]); //validate exist location

            if (placeID == 0)
            {
                return;
            }

            int catID = getCategoryID(dataContext, sportEventModel["category"]); //validate exist category

            if (catID == 0)
            {
                return;
            }


            SportEvent sportEvent = new SportEvent();
            int        userID     = ManageCookie.user.UserID;

            sportEvent.OwnerID = userID;

            sportEvent.CategoryID = catID;
            sportEvent.Date       = DateTime.Parse(sportEventModel["datetime"]);
            string duration = sportEventModel["duration"];

            if (String.IsNullOrWhiteSpace(duration))
            {
                sportEvent.Duration = 120;
            }
            else
            {
                if (!ValidationModel.ValidDuration(duration)) //validate duration
                {
                    return;
                }
                sportEvent.Duration = int.Parse(duration);
            }

            string max_attendies = sportEventModel["attendies"];

            if (String.IsNullOrWhiteSpace(max_attendies))
            {
                sportEvent.MaxAttendies = 12;
            }
            else
            {
                if (!ValidationModel.ValidAttendies(max_attendies)) // validate attendies
                {
                    return;
                }
                sportEvent.MaxAttendies = int.Parse(max_attendies);
            }
            string title = sportEventModel["title"];

            sportEvent.PlaceID = placeID;
            if (!ValidationModel.LengthAndNotSpecialValidationMaxOnly(title))
            {
                return;
            }
            sportEvent.title = title;

            string notes = sportEventModel["notes"];

            if (!ValidationModel.LengthAndNotSpecialValidationMaxOnly(notes))
            {
                return;
            }
            sportEvent.notes = notes;


            dataContext.SportEvents.InsertOnSubmit(sportEvent);
            try
            {
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            //insert to user_event table

            Users_Event uevent = new Users_Event();

            uevent.EventID = sportEvent.EventID;
            uevent.UserID  = sportEvent.OwnerID;

            dataContext.Users_Events.InsertOnSubmit(uevent);
            try
            {
                dataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            //Retrieve ML instance
            MLModel mlModel = MLModel.GetInstance();

            //Predict classification for each user - ML
            Hashtable usersPredict = mlModel.Predict(uevent.UserID, sportEvent);

            //posting to facebook asyncly
            new Task(() => { FacebookModel.PostFacebook(sportEvent.EventID, sportEvent.title, usersPredict); }).Start();
        }