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); } }
public void TestCreateNewWorkout() { workout workout = new workout(); workout.id = 100; workout.name = "TestWorkoutName"; workout.description = "TestWorkoutDescription"; workout.category_id = 1; workout.created_by_user_id = 1; workout_exercise workoutExercise = new workout_exercise(); workoutExercise.id = 4; workoutExercise.exercise_id = 1; workoutExercise.workout_id = 100; workoutExercise.position = 1; workoutExercise.duration = 5; workout.workout_exercise.Add(workoutExercise); db.Setup(c => c.workouts.Add(workout)).Returns(workout); RedirectToRouteResult result = controller.New(workout) as RedirectToRouteResult; Assert.IsNotNull(result); Assert.AreEqual(100, result.RouteValues["workoutId"], "workoutId was not 100"); Assert.AreEqual("Details", result.RouteValues["action"], "action was not Details"); Assert.AreEqual("Home", result.RouteValues["controller"], "controller was not Home"); }
public ActionResult DeleteConfirmed(int id) { workout workout = db.workouts.Find(id); db.workouts.Remove(workout); db.SaveChanges(); return(RedirectToAction("Index")); }
public void TestDetailsForWorkout24() { ViewResult result = controller.Details(24) as ViewResult; Assert.IsNotNull(result); workout workout24 = (workout)result.ViewData.Model; Assert.AreEqual("desc24", workout24.description, "description was not 'desc24'"); }
public void TestDetailsForWorkout1() { ViewResult result = controller.Details(1) as ViewResult; Assert.IsNotNull(result); workout workout1 = (workout)result.ViewData.Model; Assert.AreEqual("workout1", workout1.name, "Name was not 'workout1'"); }
// // GET: /Workouts/Details/5 public ActionResult Details(string id = null) { workout workout = db.workouts.Find(id); if (workout == null) { return(HttpNotFound()); } return(View(workout)); }
public ActionResult Edit([Bind(Include = "id,name,description,category_id,created_by_user_id,created_at,timestamp")] workout workout) { if (ModelState.IsValid) { db.Entry(workout).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public ActionResult Edit(workout workout) { if (ModelState.IsValid) { db.Entry(workout).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public void Insert(string work) { dbSportzal db = new dbSportzal(); workout workouts = new workout(); workouts.workout1 = txtWorkout.Text; db.workout.Add(workouts); db.workout.ToList(); db.SaveChanges(); Table.ItemsSource = db.workout.ToList(); }
// // GET: /Workouts/Edit/5 public ActionResult Edit(string id = null) { workout workout = db.workouts.Find(id); if (workout == null) { return(HttpNotFound()); } ViewBag.userName = new SelectList(db.users, "userName", "firstName", workout.userName); return(View(workout)); }
public ActionResult Edit(workout workout) { if (ModelState.IsValid) { db.Entry(workout).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.userName = new SelectList(db.users, "userName", "firstName", workout.userName); return(View(workout)); }
public AbstractModel ListOfTaskName(WorkoutModel workoutModel) { //get workout by name workout _workout = findWorkout(workoutModel.workoutName); if (_workout == null) { return(ResultHelper.boolResult(false, "Workout not exist !!!")); } return(ResultHelper.tasksRrssult(workoutModel.workoutName)); }
public ActionResult Create([Bind(Include = "id,name,description,category_id,created_by_user_id,created_at,timestamp")] workout workout) { if (ModelState.IsValid) { db.workouts.Add(workout); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public ActionResult Create(workout workout) { if (ModelState.IsValid) { db.workouts.Add(workout); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(workout)); }
public WorkoutDetailViewModel(workout item) { itemId = item.Id; text = item.name; workoutDescription = item.workoutDescription; WorkoutExercises = item.workoutExercises; EditWorkoutCommand = new Command(EditWorkout); StartWorkoutCommand = new Command(StartWorkout); DeleteExerciseCommand = new Command(DeleteExercise); }
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)); }
public void TestAdminWorkoutsPostDeleteWithNullWorkout() { workout w = null; ViewResult result = adminCon.DeleteConfirmed(w) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("Failed to delete the workout.", model.StatusDescription); }
/// <summary> /// Gets a recommended workout in the category that the given user completes the most, with the highest rating. /// Gets a workout the user has not completed, if possible. /// </summary> /// <param name="categoryCount">A dictionary of the category names with the corresponding count of workouts /// the user has completed in that category</param> /// <param name="completedIdList">A list of the workout ids of the workouts the user has completed</param> /// <returns>The recommended workout</returns> private workout getSimilarWorkout(Dictionary <string, int> categoryCount, List <int> completedIdList) { // Calculate the most popular category for this user string favCategory = ""; int greatest = categoryCount.Values.Max(); var dictEntry = categoryCount.Where(cc => cc.Value == greatest).FirstOrDefault(); favCategory = dictEntry.Key; workout recommendation = getMatch(favCategory, completedIdList); return(recommendation); }
/// <summary> /// Gets a recommended workout in a category that the user uses the least, with the highest rating. /// Gets a workout the user has not completed, if possible. /// NOTE: categories for which the user has completed no exercises are excluded /// </summary> /// <param name="categoryCount">A dictionary of the category names with the corresponding count of workouts /// the user has completed in that category</param> /// <param name="completedIdList">A list of the workout ids of the workouts the user has completed</param> /// <returns>The recommended workout</returns> private workout getDissimilarWorkout(Dictionary <string, int> categoryCount, List <int> completedIdList) { // Calculate the least common category for this user string category = ""; int least = categoryCount.Values.Where(c => c > 0).Min(); var dictEntry = categoryCount.Where(cc => cc.Value == least).FirstOrDefault(); category = dictEntry.Key; workout recommendation = getMatch(category, completedIdList); return(recommendation); }
public void TestAdminWorkoutsPostDeleteWorkoutNotFound() { workout w = new workout(); ViewResult result = adminCon.DeleteConfirmed(w) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("The workout does not exist or has already been deleted", model.StatusDescription); }
/// <summary> /// Helper method to determine if a workout list is sorted in a certain order on a certain property /// </summary> /// <param name="workouts">The workout list to check</param> /// <param name="propName">The workout property that the list should be sorted by</param> /// <param name="order">One of "asc" or "desc". Tells the method to check if the list is in ascending or descending order</param> /// <returns>True if the list is sorted on the given property in the given order, false otherwise</returns> public static bool isSorted(PagedList <workout> workouts, string propName, string order) { int limit = (workouts.Count > 10) ? 11 : workouts.Count; for (int i = 1; i < limit; i++) { workout currentWorkout = workouts[i]; workout prevWorkout = workouts[i - 1]; int? res = null; if (propName == "name") { res = String.Compare(prevWorkout.name, currentWorkout.name); } else if (propName == "description") { res = String.Compare(prevWorkout.description, currentWorkout.description); } else if (propName == "category") { res = String.Compare(prevWorkout.category.name, currentWorkout.category.name); } else if (propName == "dateCreated") { res = DateTime.Compare(prevWorkout.created_at, currentWorkout.created_at); } else if (propName == "username") { res = String.Compare(prevWorkout.user.username, currentWorkout.user.username); } else { return(false); } if (order == "asc") { if (res > 0) { return(false); } } else if (order == "desc") { if (res < 0) { return(false); } } } return(true); }
// GET: /Workout/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } workout workout = db.workouts.Find(id); if (workout == null) { return(HttpNotFound()); } return(View(workout)); }
//query function to check if workout exist in DB private static workout findWorkoutByUsername(string _userName, string _workoutName) { db_appEntities db = new db_appEntities(); //get workout by workoutName and userName workout _workout = db.workouts.Where(x => x.workoutName == _workoutName && x.userName == _userName).SingleOrDefault(); db.Dispose(); //check if workout exist if (_workout == null) { return(null); } return(_workout); }
//query function to check if workout exist in DB private static workout findWorkout(string workoutName) { social_workout_app_dbEntities db = new social_workout_app_dbEntities(); //get workout by workoutName workout _workout = db.workouts.Where(x => x.workoutName == workoutName).SingleOrDefault(); db.Dispose(); //check if workout exist if (_workout == null) { return(null); } return(_workout); }
// GET: AdminWorkouts/Details/5 public ActionResult Details(int?id) { if (id == null) { return(View("DetailedError", new HttpStatusCodeResult(HttpStatusCode.BadRequest, "A workout to view was not specified"))); } workout workout = db.workouts.Find(id); if (workout == null) { return(View("DetailedError", new HttpStatusCodeResult(HttpStatusCode.NotFound, "That workout could not be found or does not exist"))); } return(View(workout)); }
private static workout checkWorkout(string workoutName) { //connect to db db_appEntities db = new db_appEntities(); //get workout by workoutName workout _workout = db.workouts.Where(x => x.workoutName == workoutName).SingleOrDefault(); db.Dispose(); //check if workout exist and if workoutName is correct if (_workout == null || !workout.Equals(workoutName, workoutName)) { return(null); } return(_workout); }
public void TestAdminWorkoutsNewThrowsException() { workout w = new workout(); db.Setup(c => c.SaveChanges()).Throws(new Exception()); ViewResult result = adminCon.New(w) as ViewResult; Assert.IsNotNull(result); Assert.AreEqual("DetailedError", result.ViewName); Assert.IsInstanceOfType(result.Model, typeof(HttpStatusCodeResult)); var model = result.Model as HttpStatusCodeResult; Assert.AreEqual(500, model.StatusCode); Assert.AreEqual("Failed to create the requested workout.", model.StatusDescription); }
//query function to check if workout exist in DB private static workout findWorkoutByUsername(string _userName, string _workoutName) { social_workout_app_dbEntities db = new social_workout_app_dbEntities(); //get workout by workoutName //workout _workout = db.workouts.Where(x => x.userName == userName).Select(s => s.workoutName == workoutName).SingleOrDefault(); workout _workout = db.workouts.Where(x => x.workoutName == _workoutName && x.userName == _userName).SingleOrDefault(); db.Dispose(); //check if workout exist if (_workout == null) { return(null); } return(_workout); }
private static workout checkWorkout(string workoutName) { //connect to db social_workout_app_dbEntities db = new social_workout_app_dbEntities(); //get workout by workoutName workout _workout = db.workouts.Where(x => x.workoutName == workoutName).SingleOrDefault(); db.Dispose(); //check if workout exist and if workoutName is correct //if (_user == null || !Equals(user.password, CryptHelper.getHash(password))) if (_workout == null || !workout.Equals(workoutName, workoutName)) { return(null); } return(_workout); }
public ActionResult New() { var workout = new workout(); workout.CreateWorkoutExercise(); //var query = db.exercises.Select(ex => new { ex.id, ex.name }); var query = from ex in db.exercises select new { id = ex.id, name = ex.name + " - " + ex.type.measure }; ViewBag.Exercises = new SelectList(query.AsEnumerable(), "id", "name"); query = db.categories.Select(c => new { c.id, c.name }); ViewBag.Categories = new SelectList(query.AsEnumerable(), "id", "name"); return(View(workout)); }