Exemplo n.º 1
0
        public ActionResult Create(user user)
        {
            if (ModelState.IsValid)
            {
                db.users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Exemplo n.º 2
0
        public ActionResult Create(task task)
        {
            if (ModelState.IsValid)
            {
                db.tasks.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.workoutName = new SelectList(db.workouts, "workoutName", "workoutName", task.workoutName);
            return(View(task));
        }
Exemplo n.º 3
0
        public ActionResult Create(workout workout)
        {
            if (ModelState.IsValid)
            {
                db.workouts.Add(workout);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.userName = new SelectList(db.users, "userName", "userName", workout.userName);
            return(View(workout));
        }
Exemplo n.º 4
0
        private static bool addTask(string workoutName, string taskName, string descriptionTask, string timeTask, string revTask)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if task exist in DB
            task newTask = findTask(taskName);

            if (newTask != null)
            {
                return(false);
            }

            newTask = new task();
            //if task not exist create new task
            newTask.workoutName = workoutName;
            newTask.taskName    = taskName;
            newTask.description = descriptionTask;
            newTask.time        = timeTask;
            newTask.rev         = revTask;
            newTask.workout     = null;

            db.tasks.Add(newTask);
            db.SaveChanges();
            return(true);
        }
Exemplo n.º 5
0
        private static bool deleteTask(string workoutName, string taskName)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if task exist in DB
            task delTask = findTask(workoutName);

            if (delTask == null)
            {
                return(false);
            }
            //if (delTask.workoutName == workoutName && delTask.taskName == taskName)
            //{
            db.tasks.Remove(delTask);
            db.SaveChanges();
            return(true);
            //}

            //return false;
        }
Exemplo n.º 6
0
        private static bool addWorkout(string userName, string workoutName)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if workout exist in DB
            workout newWorkout = findWorkout(workoutName);

            if (newWorkout != null)
            {
                return(false);
            }
            newWorkout = new workout();
            //if workout not exist create new workout
            newWorkout.userName    = userName;
            newWorkout.workoutName = workoutName;

            db.workouts.Add(newWorkout);
            db.SaveChanges();
            return(true);
        }
Exemplo n.º 7
0
        //query function to add new user to DB
        private static bool changeProfile(string firstName, string lastName, string userName, string password)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if user exist in DB
            user user = findUser(userName);

            if (user == null)
            {
                return(false);
            }
            //if user exist change user profile
            user.firstName = firstName;
            user.lastName  = lastName;
            user.password  = password; // CryptHelper.getHash(password);

            db.Entry(user).State = EntityState.Modified;

            db.SaveChanges();
            return(true);
        }
Exemplo n.º 8
0
        private static bool deleteWorkout(string userName, string workoutName)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if workout exist in DB
            workout delWorkout = findWorkoutByUsername(userName, workoutName);
            task    delTask    = findTask(workoutName);

            if (delWorkout == null) // && delTask == null)
            {
                return(false);
            }
            //if (delWorkout.userName == userName && delWorkout.workoutName == workoutName)// && delTask.workoutName == workoutName)
            //{
            db.workouts.Remove(delWorkout);
            //db.tasks.Remove(delTask);
            db.SaveChanges();
            return(true);
            //}

            //return false;
        }
Exemplo n.º 9
0
        //query function to add new user to DB
        private static bool addUser(string firstName, string lastName, string userName, string password)
        {
            //connect to db
            social_workout_app_dbEntities db = new social_workout_app_dbEntities();

            //check if user exist in DB
            user user = findUser(userName);

            if (user != null)
            {
                return(false);
            }
            user = new user();
            //if user not exist create new user
            user.firstName = firstName;
            user.lastName  = lastName;
            user.password  = password; // CryptHelper.getHash(password);
            user.userName  = userName;
            db.users.Add(user);

            db.SaveChanges();
            return(true);
        }