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);
            }
        }
示例#4
0
 public ActionResult Edit(task task)
 {
     if (ModelState.IsValid)
     {
         db.Entry(task).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(task));
 }
        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);
            }
        }
        //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);
            }
        }