public async Task CreateWorkoutAsync(string name, Difficulty difficulty, WorkoutType workoutType, string description, ApplicationUser user) { var workout = new Workout { Name = name, Difficulty = difficulty, WorkoutType = workoutType, Description = description, CreatorName = user.UserName, }; if (await this.userManager.IsInRoleAsync(user, GlobalConstants.AdministratorRoleName)) { workout.IsCustom = false; } else { workout.IsCustom = true; } workout.Users.Add(await this.usersRepository.GetByIdWithDeletedAsync(user.Id)); await this.workoutsRepository.AddAsync(workout); await this.workoutsRepository.SaveChangesAsync(); }
public AbstractWorkoutVM(AbstractWorkout model) { Id = model.Id; Name = model.Name; ActivityType = model.ActivityType; WorkoutType = model.WorkoutType; }
public IActionResult Get(string id) { WorkoutType workoutType = accessor.Get <WorkoutType>(id); return(Json(workoutType)); }
public static WorkoutType LoadById(Guid id) { try { using (AmbrosiaEntities dc = new AmbrosiaEntities()) { tblWorkoutType row = dc.tblWorkoutTypes.FirstOrDefault(g => g.Id == id); if (row != null) { WorkoutType workoutType = new WorkoutType { Id = row.Id, Name = row.Name, CaloriesPerMinute = row.CaloriesPerMinute }; return(workoutType); } else { throw new Exception("Row was not found!"); } } } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] WorkoutType workoutType) { if (id != workoutType.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(workoutType); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkoutTypeExists(workoutType.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(workoutType)); }
public ExerciseDataItem(String name, String description, WorkoutType type) { this.Name = name; this.Description = description; this.Type = type; this.LastUsed = DateTime.Today; }
public async Task <IActionResult> PutWorkoutType(int id, WorkoutType workoutType) { if (id != workoutType.Id) { return(BadRequest()); } _context.Entry(workoutType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkoutTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <WorkoutType> > PostWorkoutType(WorkoutType workoutType) { _context.WorkoutTypes.Add(workoutType); await _context.SaveChangesAsync(); return(workoutType); }
public void InsertTest() { // Arrange WorkoutTypeController controllerwt = new WorkoutTypeController(); // Act List <WorkoutType> loadAllWt = controllerwt.Get() as List <WorkoutType>; //grab first result WorkoutType wt = loadAllWt[0]; // Arrange UserController controlleru = new UserController(); // Act List <User> loadAllU = controlleru.Get() as List <User>; //grab first result User u = loadAllU[0]; Workout w = new Workout { WorkoutType = wt, StartTime = System.DateTime.Now, EndTime = new System.DateTime(2020, 11, 18), UserId = u.Id }; // Arrange WorkoutController controller = new WorkoutController(); // Act int result = controller.Post(w); // Assert Assert.IsTrue(result > 0); }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { if (logger.IsWarnEnabled) { logger.Warn(txtWorkoutName.Text); } int result = 0; workout = (WorkoutType)dgWorkouts.SelectedItem; if (workout != null) { workout.Name = txtWorkoutName.Text; workout.CaloriesPerMinute = Int32.Parse(txtWorkoutCalories.Text); result = WorkoutTypeManager.Update(workout); } Reload(); if (result == 1) { MessageBox.Show("Success!"); } else { MessageBox.Show("Failure"); } }
public void Update(int Id, Models.Requests.Workout.WorkoutCreateRequest updateRequest) { Workout dbWorkout = _context.Workouts.Find(Id); if (dbWorkout == null) { throw new ResourceNotFoundException($"Workout with id {Id} not found"); } Trainer dbTrainer = _context.Trainers.Find(updateRequest.TrainerId); if (dbTrainer == null) { throw new ResourceNotFoundException($"Trainer with id {updateRequest.TrainerId} not found"); } WorkoutType workoutType = _context.WorkoutTypes.Find(updateRequest.WorkoutTypeId); if (workoutType == null) { throw new ResourceNotFoundException($"Workout Type with id {updateRequest.TrainerId} not found"); } dbWorkout.Trainer = dbTrainer; dbWorkout.WorkoutType = workoutType; dbWorkout.Name = updateRequest.Name; dbWorkout.Description = updateRequest.Description; dbWorkout.Difficulty = updateRequest.Difficulty; dbWorkout.Duration = updateRequest.Duration; _context.Workouts.Update(dbWorkout); _context.SaveChanges(); }
public Models.Workout.Workout Create(Models.Requests.Workout.WorkoutCreateRequest createRequest) { Trainer dbTrainer = _context.Trainers.Find(createRequest.TrainerId); if (dbTrainer == null) { throw new ResourceNotFoundException($"Trainer with id {createRequest.TrainerId} not found"); } WorkoutType workoutType = _context.WorkoutTypes.Find(createRequest.WorkoutTypeId); if (workoutType == null) { throw new ResourceNotFoundException($"Workout Type with id {createRequest.TrainerId} not found"); } Workout dbWorkout = new Workout { Trainer = dbTrainer, WorkoutType = workoutType, Description = createRequest.Description, Difficulty = createRequest.Difficulty, Duration = createRequest.Duration, Name = createRequest.Name, CreatedAt = System.DateTime.Now }; _context.Workouts.Add(dbWorkout); _context.SaveChanges(); return(GetById(dbWorkout.Id)); }
public async Task GetEventsShouldReturnCorrectEventsForWorkout() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var workoutService = new WorkoutsService(dbContext); var type = new WorkoutType { Name = "testName", }; var workout = new Workout { Date = DateTime.Now.Date, Type = type, UserId = "Icaka99", }; await dbContext.AddAsync(workout); await dbContext.SaveChangesAsync(); var result = workoutService.GetEvents("Icaka99"); Assert.NotNull(result); Assert.Single(result); Assert.Equal("testName", result.FirstOrDefault().Title); Assert.Equal(DateTime.Now.Date, result.FirstOrDefault().Date); }
public WorkoutCreated(WorkoutId id, ChallengeId challengeId, WorkoutType type, int reps, DateTime eventDateTime) : base(eventDateTime) { Id = id; ChallengeId = challengeId; Type = type; Reps = reps; }
public async Task AssignWorkoutTypesShouldAssignCorrectWorkoutTypesToWorkout() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var workoutService = new WorkoutsService(dbContext); var workoutType = new WorkoutType { Name = "testName", }; await dbContext.WorkoutTypes.AddAsync(workoutType); await dbContext.SaveChangesAsync(); var workoutToAdd = new WorkoutInputModel { Date = DateTime.Now.Date, Duration = 180, TypeId = 1, UserId = "Icaka99", }; var result = workoutService.AssignWorkoutTypes(workoutToAdd); Assert.NotNull(result.Types); Assert.Equal("testName", result.Types.FirstOrDefault().Text); Assert.Equal("1", result.Types.FirstOrDefault().Value); }
private void UpdateWorkoutType(WorkoutType updatedWorkoutType) { var oldWorkoutType = FindWorkoutType(updatedWorkoutType.WorkoutTypeId); _gasContext.WorkoutTypes.Remove(oldWorkoutType); _gasContext.WorkoutTypes.Add(updatedWorkoutType); _gasContext.SaveChanges(); }
public void Create(WorkoutId id, ChallengeId challengeId, WorkoutType type, int repetitions) { if (State.Created) { throw new InvalidOperationException($"{nameof(Workout)}-{id} already created"); } Apply(new WorkoutCreated(id, challengeId, type, repetitions, DateTime.Now)); }
public void DeleteTest() { List <WorkoutType> workoutTypes = WorkoutTypeManager.Load(); WorkoutType workoutType = workoutTypes.FirstOrDefault(u => u.Name == "Running"); int results = WorkoutTypeManager.Delete(workoutType, true); Assert.IsTrue(results > 0); }
/// <summary> /// Builds the commands required for a Just Row workout /// </summary> /// <param name="splits">True if with splits, false if without</param> /// <returns>Enumerable of the required commands</returns> private static IEnumerable <ICommand> BuildJustRowWorkout(bool splits) { WorkoutType workoutType = splits ? WorkoutType.JustRowWithSplits : WorkoutType.JustRowNoSplits; return(new List <ICommand> { new SetWorkoutTypeCommand(workoutType), new SetScreenStateCommand(ScreenType.Workout, ScreenValueWorkout.PrepareToRowWorkout) }); }
public void UpdateTest() { List <WorkoutType> workoutTypes = WorkoutTypeManager.Load(); WorkoutType workoutType = workoutTypes.FirstOrDefault(u => u.Name == "Running"); workoutType.CaloriesPerMinute = 12; int results = WorkoutTypeManager.Update(workoutType, true); Assert.IsTrue(results > 0); }
public async Task <IList <Workout> > GetWorkouts(WorkoutType workoutType) { //if (_cachedWorkouts != null && (DateTime.Now - _lastUpdated).TotalHours <= 4) // return _cachedWorkouts; var targetUrl = string.Concat(RemoteUrl, workoutType.ToString().ToLower()); var remoteUri = new Uri(targetUrl, UriKind.Absolute); var workouts = new List <Workout>(); try { var httpRequest = (HttpWebRequest)WebRequest.Create(remoteUri); httpRequest.ContentType = "application/json"; httpRequest.Method = "GET"; using (var response = await httpRequest.GetResponseAsync() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Debug.WriteLine("Error fetching data from server."); return(null); } var s = response.GetResponseStream(); if (s != null) { var j = JsonObject.Load(s); // Create workouts from json data. var results = from result in j[0] as JsonArray let jresult = result as JsonObject select new Workout() { Id = jresult["id"], DisplayId = jresult["displayId"], Name = jresult["name"], ExerciseType = workoutType, Level = (WorkoutLevel)Enum.Parse(typeof(WorkoutLevel), jresult["level"]) }; _cachedWorkouts = results.ToList(); _lastUpdated = DateTime.Now; return(_cachedWorkouts); } } return(workouts); } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } }
public async Task <IActionResult> Create([Bind("Id,Name")] WorkoutType workoutType) { if (ModelState.IsValid) { _context.Add(workoutType); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(workoutType)); }
public Task AddOrUpdate(DB db) { return(db.Database.InsertOrReplaceAsync(new ScheduleDBModel_ { Id = Id, Interval = (int)Interval.TotalMinutes, IsActive = IsActive, When = (int)(When - StablePointInTime).TotalMinutes, WorkoutId = WorkoutId, WorkoutType = WorkoutType.ToString() }, typeof(ScheduleDBModel_))); }
public async Task <IWorkout> GetWorkout(int id, WorkoutType type) { switch (type) { case WorkoutType.Crossfit: return(await GetCrossfitWorkout(id)); case WorkoutType.Regular: return(await GetRegularWorkout(id)); case WorkoutType.Marathon: return(await GetMarathonWorkout(id)); } return(null); }
public void InsertTest() { WorkoutType workoutType = new WorkoutType(); workoutType.Id = Guid.NewGuid(); workoutType.Name = "Testing"; workoutType.CaloriesPerMinute = 50; int results = WorkoutTypeManager.Insert(workoutType, true); Assert.IsTrue(results > 0); }
public void UpdateIcon(WorkoutType newWorkoutType) { currentWorkoutData.workoutType = newWorkoutType; workoutIconShower.Init(newWorkoutType); if (currentWorkoutPanel != null) { currentWorkoutPanel.fitBoyIlluminator.Init(newWorkoutType); } ShowEditPage(); WorkoutManager.Instance.Save(); }
public async Task ExecuteWorkout(DB db) { var workout = await db.Database.FindAsync <MarathonDBModel>(Id); string type = WorkoutType.ToString(); var pw = await db.Database.Table <ListWorkoutDBModel>().Where(p => p.WorkoutId == Id && p.WorkoutType.Equals(type)).ToListAsync(); var playlists = await db.Database.Table <PlaylistDBModel>().ToListAsync(); App.Debug(new string(playlists.SelectMany(p => p.ToString()).ToArray())); await App.Current.MainPage.Navigation.PushAsync(new MarathonWorkouter(workout, playlists.Where(p => pw.Any(x => x.PlaylistId == p.Id)).ToList())); }
public async Task <WorkoutTypeOutputModel> Create(WorkoutTypeCreateModel model) { var workoutType = new WorkoutType { Name = model.Name, Description = model.Description }; await db.WorkoutTypes.AddAsync(workoutType); await db.SaveChangesAsync(); return(mapper.Map <WorkoutTypeOutputModel>(workoutType)); }
public ExerciseLengthPopupViewModel(Workout workout, ExerciseType type, AddWorkoutViewModel parent) { // TODO: prolly want to implement the is busy, look at AddWorkoutViewModel //AddExerciseCommand = new Command( // async () => await AddExercise() //); _exercise = new WorkoutType { Exercise = type }; _parent = parent; _type = type; _workout = workout; AddExerciseCommand = new Command(AddExercise); }
public Workout(WorkoutType type, int numberOfReps, int numberOfSets, int weight, int totalTime, int rating, string notes) { //error checking this.type = type; this.numberOfReps = numberOfReps; this.numberOfSets = numberOfSets; this.weight = weight; this.totalTime = totalTime; this.rating = rating; this.notes = notes; setTheoreticalMaximum(); setTotalWeight(); }
public Workout(WorkoutType workoutType) : this() { WorkoutType = workoutType; switch (workoutType) { case WorkoutType.KiBox: Name = string.Format(WorkoutResources.KiBoxTitle, DateTime.Now.Month >= 6 ? WorkoutResources.Spring : WorkoutResources.Autumn, DateTime.Now.Year); break; case WorkoutType.Workout: Name = string.Format(WorkoutResources.WorkoutTitle, DateTime.Now.Month >= 6 ? WorkoutResources.Spring : WorkoutResources.Autumn, DateTime.Now.Year); break; } }
protected override void ReadInternal(ResponseReader reader) { WorkoutType val = (WorkoutType)reader.ReadByte(); WorkoutType = Enum.IsDefined(typeof(WorkoutType), val) ? val : WorkoutType.Unknown; }
public async Task<Workout> GetWorkoutById(WorkoutType workoutType, int id) { var targetUrl = string.Format("{0}{1}/{2}", RemoteUrl, workoutType.ToString().ToLower(), id); var remoteUri = new Uri(targetUrl, UriKind.Absolute); if (_cachedWorkouts == null) return null; var workout = _cachedWorkouts.FirstOrDefault(w => w.Id == id); if (workout == null) return null; if (workout.Stages.Count > 0) return workout; // Populates the stages collection with new data. try { var stages = new List<Stage>(); var httpRequest = (HttpWebRequest) WebRequest.Create(remoteUri); httpRequest.ContentType = "application/json"; httpRequest.Method = "GET"; using (var response = await httpRequest.GetResponseAsync() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Debug.WriteLine("Error fetching data from server."); return null; } var s = response.GetResponseStream(); if (s != null) { var j = JsonObject.Load(s); // Create workouts from json data. var results = from result in j[0] as JsonArray let jresult = result as JsonObject select new Stage() { Id = jresult["stageId"], Duration = TimeSpan.Parse(jresult["duration"]), CrossRamp = Range<int>.Parse(jresult["crossRamp"]), Resistance = Range<int>.Parse(jresult["resistance"]), Strides = Range<int>.Parse(jresult["strides"]), Message = jresult["message"] }; stages = results.ToList(); workout.Stages = stages; } } return workout; } catch (Exception ex) { Debug.WriteLine (ex.Message); return null; } }
public async Task<IList<Workout>> GetWorkouts(WorkoutType workoutType) { //if (_cachedWorkouts != null && (DateTime.Now - _lastUpdated).TotalHours <= 4) // return _cachedWorkouts; var targetUrl = string.Concat (RemoteUrl, workoutType.ToString().ToLower()); var remoteUri = new Uri(targetUrl, UriKind.Absolute); var workouts = new List<Workout>(); try { var httpRequest = (HttpWebRequest) WebRequest.Create(remoteUri); httpRequest.ContentType = "application/json"; httpRequest.Method = "GET"; using (var response = await httpRequest.GetResponseAsync() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { Debug.WriteLine("Error fetching data from server."); return null; } var s = response.GetResponseStream(); if (s != null) { var j = JsonObject.Load(s); // Create workouts from json data. var results = from result in j[0] as JsonArray let jresult = result as JsonObject select new Workout() { Id = jresult["id"], DisplayId = jresult["displayId"], Name = jresult["name"], ExerciseType = workoutType, Level = (WorkoutLevel) Enum.Parse(typeof(WorkoutLevel), jresult["level"]) }; _cachedWorkouts = results.ToList(); _lastUpdated = DateTime.Now; return _cachedWorkouts; } } return workouts; } catch (Exception ex) { Debug.WriteLine (ex.Message); return null; } }