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

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

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

            return(View(user));
        }
        private static bool deleteTask(string workoutName, string taskName)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

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

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

            try
            {
                db.Entry(delTask).State = EntityState.Deleted;
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool deleteWorkoutFromList(string _mastersUerName, string _userName, string _workoutName)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();
            //check if workout exist in DB
            favorite delWorkout = checkFavoriteWorkout(_mastersUerName, _userName, _workoutName);

            if (delWorkout == null)
            {
                return(false);
            }
            try
            {
                db.Entry(delWorkout).State = EntityState.Deleted;
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            { }
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool addToStorage(string _userName, string _workoutName, bool _inStorage)
        {
            bool flag = false;
            //connect to db
            db_appEntities db             = new db_appEntities();
            workout        workoutToUpade = findWorkoutByUsername(_userName, _workoutName);

            if (workoutToUpade == null)
            {
                return(false);
            }
            try
            {
                workoutToUpade.inStorage = true;

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

                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            { }
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool deleteWorkout(string userName, string workoutName)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();
            //check if workout exist in DB
            workout delWorkout = findWorkoutByUsername(userName, workoutName);

            List <task> delTaskList = findAllTasks(workoutName);

            if (delWorkout == null && delTaskList == null)
            {
                return(false);
            }
            try
            {
                db.Entry(delWorkout).State = EntityState.Deleted;
                db.SaveChanges();
                foreach (task element in delTaskList)
                {
                    db.Entry(element).State = EntityState.Deleted;
                }
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool addTask(string workoutName, string taskName, string descriptionTask, string timeTask, string revTask)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

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

            if (newTask != null)
            {
                return(false);
            }
            try
            {
                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;

                db.tasks.Add(newTask);
                //db.Entry(newTask).State = EntityState.Added;
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        //query function to add new user to DB
        private static bool addUser(string firstName, string lastName, string userName, string password)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

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

            if (user != null)
            {
                return(false);
            }
            try
            {
                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();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        //query function to add new user to DB
        private static bool changeProfile(string firstName, string lastName, string userName, string password)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

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

            if (user == null)
            {
                return(false);
            }
            try
            {
                //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();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool addWorkout(string userName, string workoutName)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

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

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

                db.workouts.Add(newWorkout);
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            {}
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }
        private static bool addWorkoutToTableFavorites(string masterUserName, string userName, string workoutName)
        {
            bool flag = false;
            //connect to db
            db_appEntities db = new db_appEntities();

            ////check if workout exist in DB
            //favorite newWorkout = findWorkout(workoutName);
            //if (newWorkout != null)
            //{
            //    return false;
            //}
            try
            {
                favorite newWorkout = new favorite();
                //if workout not exist create new workout
                newWorkout.masterUser  = masterUserName;
                newWorkout.userName    = userName;
                newWorkout.workoutName = workoutName;

                db.favorites.Add(newWorkout);
                db.SaveChanges();
                flag = true;
            }
            catch (Exception e)
            { }
            if (flag == true)
            {
                return(true);
            }
            else
            {
                db.Dispose();
                return(false);
            }
        }