Пример #1
0
        public static bool deleteEvent(int eventID)
        {
            var db     = new SqlConnectionDataContext();
            var result =
                (from esport in db.SportEvents
                 where esport.EventID == eventID
                 select esport).FirstOrDefault();

            if (result == null)
            {
                return(false);
            }

            db.SportEvents.DeleteOnSubmit(result);
            foreach (Users_Event uevent in db.Users_Events.Where(p => p.EventID == eventID))
            {
                db.Users_Events.DeleteOnSubmit(uevent);
            }

            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
                // Provide for exceptions.
            }
        }
Пример #2
0
        public static bool cancelEvent(int eventID, int userID)
        {
            var db     = new SqlConnectionDataContext();
            var result =
                (from uevent in db.Users_Events
                 where uevent.EventID == eventID && uevent.UserID == userID
                 select uevent).FirstOrDefault();

            if (result == null)
            {
                return(false);
            }
            db.Users_Events.DeleteOnSubmit(result);
            try
            {
                db.SubmitChanges();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(false);
                // Provide for exceptions.
            }
        }
Пример #3
0
 //update all facebook details
 private static void updateUser(SqlConnectionDataContext db, UserAccount u, string displayName, string Email, string photoURL, string accessToken)
 {
     u.DisplayName = displayName;
     u.Email       = Email;
     u.PhotoURL    = photoURL;
     u.LastLogon   = DateTime.Now;
     u.accessToken = accessToken;
     db.SubmitChanges();
 }
Пример #4
0
        public static void removeUserByID(int userID)
        {
            var db = new SqlConnectionDataContext();

            var user = db.UserAccounts.Where(u => u.UserID == userID).SingleOrDefault();

            if (user != null)
            {
                db.UserAccounts.DeleteOnSubmit(user);
                db.SubmitChanges();
            }
        }
Пример #5
0
        private static void addUserToEvent(SqlConnectionDataContext db, int eventID, int userID)
        {
            Users_Event ue = new Users_Event();

            ue.EventID = eventID;
            ue.UserID  = userID;
            db.Users_Events.InsertOnSubmit(ue);
            try
            {
                db.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #6
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);
        }
Пример #7
0
        //create user from facebook
        private static void createUser(SqlConnectionDataContext db, string fid, string displayName, string Email, string photoURL, string Hash, string accessToken)
        {
            //creating instance user
            UserAccount u = new UserAccount();

            u.DisplayName = displayName;
            u.FacebookID  = fid;
            u.Email       = Email;
            u.PhotoURL    = photoURL;
            u.isAdmin     = 0;
            u.LastLogon   = DateTime.Now;
            u.Hash        = Hash;
            u.accessToken = accessToken;

            //update database
            db.UserAccounts.InsertOnSubmit(u);
            db.SubmitChanges();
        }
Пример #8
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);
        }
Пример #9
0
        public static void removePlaceByID(int placeID)
        {
            var db = new SqlConnectionDataContext();

            //delete dependencies events
            var events = db.SportEvents.Where(s => s.PlaceID == placeID).ToList();

            foreach (var sevent in  events)
            {
                SportEventModel.deleteEventLocal(sevent.EventID);
            }

            //delete place
            var place = db.Places.Where(p => p.Id == placeID).SingleOrDefault();

            if (place != null)
            {
                db.Places.DeleteOnSubmit(place);
                db.SubmitChanges();
            }
        }
Пример #10
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.
            }
        }
Пример #11
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();
        }