public async Task <FillMeasurement> CreateOrEditFillMeasurementAsync(int id, AddMeasurementViewModel viewModel)
        {
            var fill = new FillMeasurement();

            if (id != 0)
            {
                fill = await _context.FillMeasurement.FindAsync(id);
            }

            fill.PutMesurement = viewModel.PutMesurement;
            if (id == 0)
            {
                fill.AppUserID     = viewModel.AppUserID;
                fill.Date          = viewModel.Date;
                fill.MeasurementID = viewModel.MeasurementID;
                await _context.FillMeasurement.AddAsync(fill);

                await _context.SaveChangesAsync();

                return(await _context.FillMeasurement.LastAsync());
            }
            await _context.SaveChangesAsync();

            return(fill);
        }
Exemple #2
0
        public async Task <FillingWorkout> NewFillingWorkoutAsync(int workoutId, Exercise exercise, int sets, int min,
                                                                  int max)
        {
            var exerciseId = exercise.ExerciseID;

            if (exerciseId > 0)
            {
                var newFillingWorkout = new FillingWorkout
                {
                    ExerciseID = exerciseId,
                    WorkoutID  = workoutId,
                    Sets       = sets,
                    RepeatMin  = min,
                    RepeatMax  = max,
                    Exercise   = exercise
                };
                if (_context.FillingWorkout.Contains(newFillingWorkout) == false)
                {
                    await _context.FillingWorkout.AddAsync(newFillingWorkout);

                    await _context.SaveChangesAsync();

                    return(newFillingWorkout);
                }
            }


            return(null);
        }
Exemple #3
0
        public async Task <Tag> SaveTagAsync(string name, int id = 0)
        {
            if (id == 0)
            {
                await _context.Tag.AddAsync(new Tag { Name = name });

                await _context.SaveChangesAsync();

                return(await _context.Tag.SingleOrDefaultAsync(t => t.Name == name));
            }
            _context.Tag.Update(new Tag {
                TagID = id, Name = name
            });
            await _context.SaveChangesAsync();

            return(await _context.Tag.FindAsync(id));
        }
Exemple #4
0
        public async Task <Muscle> SaveMuscleAsync(string name, int id = 0)
        {
            if (id == 0)
            {
                await _context.Muscle.AddAsync(new Muscle { Name = name });

                await _context.SaveChangesAsync();

                return(await _context.Muscle.SingleOrDefaultAsync(t => t.Name == name));
            }
            _context.Muscle.Update(new Muscle {
                MuscleID = id, Name = name
            });
            await _context.SaveChangesAsync();

            return(await _context.Muscle.FindAsync(id));
        }
Exemple #5
0
        public async Task <AppUser> SaveUserProfileAsync(string key, UserProfileViewModel viewModel, int id)
        {
            if ((key == null) & (id == 0))
            {
                return(null);
            }
            if (viewModel == null)
            {
                return(null);
            }
            AppUser user = null;

            if (id != 0)
            {
                user = await GetUserProfileById(id);
            }
            if (user == null)
            {
                await _context.AppUser.AddAsync(new AppUser
                {
                    FirstName           = viewModel.FirstName,
                    SecondName          = viewModel.SecondName,
                    DateOfBirth         = viewModel.DateOfBirth,
                    DateOfRegoistration = DateTime.Now,
                    Key           = key,
                    Sex           = viewModel.Sex,
                    CurrentWeight = viewModel.CurrentWeight,
                    Goal          = viewModel.Goal,
                    WeeksForGoal  = viewModel.WeeksForGoal,
                    ImageName     = viewModel.ImageName,
                    ImagePath     = viewModel.ImagePath,
                    Height        = viewModel.Height,
                    Activity      = viewModel.Activity
                });
            }
            else
            {
                user.FirstName     = viewModel.FirstName;
                user.SecondName    = viewModel.SecondName;
                user.DateOfBirth   = viewModel.DateOfBirth;
                user.Sex           = viewModel.Sex;
                user.CurrentWeight = viewModel.CurrentWeight;
                user.Goal          = viewModel.Goal;
                user.WeeksForGoal  = viewModel.WeeksForGoal;
                user.ImageName     = viewModel.ImageName;
                user.ImagePath     = viewModel.ImagePath;
                user.Height        = viewModel.Height;
                user.Activity      = viewModel.Activity;
            }
            await _context.SaveChangesAsync();

            return(await GetUserByKeyAsync(key));
        }
Exemple #6
0
        public async Task <Measurement> SaveMeasurementAsync(MeasurementViewModel viewModel, int id = 0)
        {
            if ((id == 0) &
                (await _context.Measurement.SingleOrDefaultAsync(t => t.Name == viewModel.Name) == default(Measurement)))
            {
                await _context.Measurement.AddAsync(new Measurement
                {
                    Name = viewModel.Name,
                    UnitsOfMeasurement = viewModel.UnitsOfMeasurement
                });

                await _context.SaveChangesAsync();

                return(await GetMeasurementByNameAsync(viewModel.Name));
            }
            var measure = await GetMeasurementAsync(id);

            measure.Name = viewModel.Name;
            measure.UnitsOfMeasurement = viewModel.UnitsOfMeasurement;
            await _context.SaveChangesAsync();

            return(measure);
        }
Exemple #7
0
        public async Task <Food> SaveFoodAsync(FoodViewModel viewModel, int id = 0)
        {
            if (id == 0)
            {
                await _context.Foodstuff.AddAsync(new Food { Name = viewModel.Name });

                await _context.SaveChangesAsync();

                return(await _context.Foodstuff.SingleOrDefaultAsync(t => t.Name == viewModel.Name));
            }
            _context.Foodstuff.Update(new Food
            {
                FoodID       = id,
                Name         = viewModel.Name,
                Calories     = viewModel.Calories,
                Fat          = viewModel.Fat,
                Carbohydrate = viewModel.Carbohydrate,
                Protein      = viewModel.Protein
            });
            await _context.SaveChangesAsync();

            return(await _context.Foodstuff.FindAsync(id));
        }
Exemple #8
0
        public async Task <GroupsOfMuscles> NewGroupOfMusclesAsync(int exerciseId, Muscle muscle)
        {
            var muscleId = muscle.MuscleID;

            if (muscleId > 0)
            {
                var newGroupsOfMuscles = new GroupsOfMuscles
                {
                    ExerciseID = exerciseId,
                    MuscleID   = muscleId
                };
                if (_context.GroupsOfMuscles.Contains(newGroupsOfMuscles) == false)
                {
                    await _context.GroupsOfMuscles.AddAsync(newGroupsOfMuscles);

                    await _context.SaveChangesAsync();

                    return(newGroupsOfMuscles);
                }
            }


            return(null);
        }