public void AddCompletedWorkout(string userId, CreateCompletedWorkoutViewModel vm)
        {
            var completedWorkout = new CompletedWorkout()
            {
                ApplicationUserId = userId,
                Comments          = vm.Comments,
                DateCreated       = DateTime.Now,
                WorkoutId         = vm.WorkoutId
            };

            completedWorkoutsRepo.Add(completedWorkout);

            completedExcercisesRepo.AddRange(vm.DetailedExercises.Select(de => new CompletedExercise()
            {
                ApplicationUserId = userId,
                DateCreated       = DateTime.Now,
                Comments          = de.Comments,
                ExerciseId        = de.ExerciseId,
                CompletedWorkout  = completedWorkout,
                Mins   = de.Mins,
                Weight = de.Weight,
                Sets   = de.Sets,
                Reps   = de.Reps
            }).ToList());

            completedWorkoutsRepo.SaveChanges();
            completedExcercisesRepo.SaveChanges();
        }
示例#2
0
        public async Task <IActionResult> Create(CreateWorkoutViewModel vm)
        {
            if (ModelState.IsValid)
            {
                using (exercisesRepo)
                    using (workoutsRepo)
                        using (weRepo)
                            using (userManager)
                            {
                                var user = await userManager.GetUserAsync(HttpContext.User);

                                var exercises          = exercisesRepo.All().Where(e => e.ApplicationUserId == user.Id).ToList();
                                var selectedExercises  = vm.Exercises.Select(e => Int32.Parse(e));
                                var filteredExcercises = exercises.Where(e => selectedExercises.Contains(e.ExerciseId));

                                Workout workout = new Workout()
                                {
                                    WorkoutName       = vm.WorkoutName,
                                    WorkoutDetails    = vm.WorkoutDetails,
                                    DateCreated       = DateTime.Now,
                                    ApplicationUserId = user.Id
                                };
                                workoutsRepo.Add(workout);

                                foreach (var e in filteredExcercises)
                                {
                                    weRepo.Add(new WorkoutExercise()
                                    {
                                        Exercise = e, Workout = workout
                                    });
                                }


                                workoutsRepo.SaveChanges();
                                weRepo.SaveChanges();
                                return(RedirectToAction(nameof(Index)));
                            }
            }
            return(View(vm));
        }
示例#3
0
        /// <summary>
        /// Create new ToDo
        /// </summary>
        /// <param name="model">Information about ToDo</param>
        public void CreateItem(ToDoItemViewModel model)
        {
            ToDoItem item = new ToDoItem()
            {
                Id          = model.Id,
                Name        = model.Name,
                Description = model.Description,
                Completed   = model.Completed
            };

            itemsRepo.Add(item);
            itemsRepo.SaveChanges();
        }
示例#4
0
        public void Update()
        {
            var sensors = this.sensorRepository.All();

            foreach (var sensor in sensors)
            {
                if (DateTime.Now - sensor.LastUpdated >= TimeSpan.FromSeconds(sensor.RefreshRate))
                {
                    var newState = GetRealTimeValue(sensor.Url);

                    newState.SensorId = sensor.Id;
                    newState.Sensor   = sensor;
                    sensor.History.Add(newState);
                    sensor.LastUpdated  = newState.UpdateDate;
                    sensor.CurrentValue = newState.Value;
                }
            }

            sensorRepository.SaveChanges();
        }