public async Task <OneDayWorkout> AddOrEditOneDayWorkoutAsync(int id, OneDayWorkoutViewModel viewModel)
        {
            var oneDayWorkout = _context.OneDayWorkout.Find(id);

            if (oneDayWorkout == null)
            {
                oneDayWorkout = new OneDayWorkout {
                    AppUserID = viewModel.AppUserID, CardioID = viewModel.CardioID, Date = viewModel.Date, Duration = viewModel.Duration, WorkoutID = viewModel.WorkoutID
                };
                _context.OneDayWorkout.Add(oneDayWorkout);
                _context.SaveChanges();
                return(await _context.OneDayWorkout.Include(t => t.Cardio)
                       .Include(t => t.Workout)
                       .ThenInclude(t => t.Exercises)
                       .ThenInclude(t => t.Exercise).LastAsync());
            }

            else
            {
                oneDayWorkout.CardioID  = viewModel.CardioID;
                oneDayWorkout.Duration  = viewModel.Duration;
                oneDayWorkout.WorkoutID = viewModel.WorkoutID;
                _context.SaveChanges();
            }

            return(oneDayWorkout);
        }
Beispiel #2
0
        public async Task <NewsViewModel> SaveNewsAsync(AddNewsViewModel viewModel, int id = 0)
        {
            if (id == 0)
            {
                _context.News.Add(new News
                {
                    Name      = viewModel.Name,
                    Path      = viewModel.Path,
                    Tag       = viewModel.Tag,
                    ImagePath = viewModel.ImagePath
                });
                _context.SaveChanges();
                var n = await _context.News.LastAsync();

                string text1 = File.ReadAllText(@"../BeFit/wwwroot" + n.Path);
                return(new NewsViewModel {
                    Name = n.Name, ImagePath = n.ImagePath, Tag = n.Tag
                });
            }
            var news = await _context.News.FindAsync(id);

            if (news == null)
            {
                return(null);
            }
            news.Name      = viewModel.Name;
            news.Path      = viewModel.Path;
            news.Tag       = viewModel.Tag;
            news.ImagePath = viewModel.ImagePath;
            string text = File.ReadAllText(@"../BeFit/wwwroot" + news.Path);

            return(new NewsViewModel {
                Name = news.Name, ImagePath = news.ImagePath, Tag = news.Tag
            });
        }
Beispiel #3
0
        public bool DeleteExercise(int id)
        {
            var del = context.Exercise.Find(id);

            if (del != null)
            {
                context.Exercise.Remove(del);
                context.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #4
0
        public bool DeleteCardio(int id)
        {
            var del = context.Cardio.Find(id);

            if (del != null)
            {
                context.Cardio.Remove(del);
                context.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #5
0
        public bool DeleteWorkout(int id)
        {
            var del = _context.Workout.Find(id);

            if (del != null)
            {
                _context.Workout.Remove(del);
                _context.SaveChanges();
                return(true);
            }
            return(false);
        }
Beispiel #6
0
 public void DeleteGroupOfMuscle(ICollection <GroupsOfMuscles> groups)
 {
     if (groups.Count() != 0)
     {
         _context.GroupsOfMuscles.RemoveRange(groups);
         _context.SaveChanges();
     }
 }
Beispiel #7
0
 public void DeleteFillingWorkout(ICollection <FillingWorkout> groups)
 {
     if (groups.Count() != 0)
     {
         _context.FillingWorkout.RemoveRange(groups);
         _context.SaveChanges();
     }
 }
        public async Task <WeightOfFood> CreatetWeightOfFoodAsync(WeightOfFoodViewModel viewModel)
        {
            var newWeight = new WeightOfFood();

            newWeight.FoodID = viewModel.Food.FoodID;
            newWeight.Weight = viewModel.Weight;
            if (newWeight.WeightOfFoodID == 0)
            {
                newWeight.IngestionID = viewModel.IngestionId;
                _context.WeightOfFood.Add(newWeight);
                _context.SaveChanges();
                return
                    (await _context.WeightOfFood.SingleOrDefaultAsync(
                         t => t.FoodID == viewModel.Food.FoodID& t.IngestionID == viewModel.IngestionId));
            }
            _context.SaveChanges();
            return(newWeight);
        }
Beispiel #9
0
        public void DeleteMeasurement(int id)
        {
            var del = GetMeasurementAsync(id);

            if (del.Result != null)
            {
                _context.Measurement.Remove(del.Result);
                _context.SaveChanges();
            }
        }
Beispiel #10
0
        public void DeleteTag(int id)
        {
            var del = _context.Tag.Find(id);

            if (del != null)
            {
                _context.Tag.Remove(del);
                _context.SaveChanges();
            }
        }
Beispiel #11
0
        public void DeleteFood(int id)
        {
            var del = _context.Foodstuff.Find(id);

            if (del != null)
            {
                _context.Foodstuff.Remove(del);
                _context.SaveChanges();
            }
        }
Beispiel #12
0
        public void DeleteMuscle(int id)
        {
            var del = _context.Muscle.Find(id);

            if (del != null)
            {
                _context.Muscle.Remove(del);
                _context.SaveChanges();
            }
        }
Beispiel #13
0
        public async Task <OneDayFood> AddOrEditOneDayFoodAsync(OneDayFoodViewModel viewModel, int id)
        {
            var oneDayFood = new OneDayFood();
            var check      = await GetOneDayFoodBiIdAsync(id);

            if (check != null)
            {
                oneDayFood = check;
            }
            oneDayFood.Water = viewModel.Water;
            if (oneDayFood.OneDayFoodID == 0)
            {
                oneDayFood.Date      = viewModel.Date;
                oneDayFood.AppUserID = viewModel.AppUserID;
                _context.OneDayFood.Add(oneDayFood);
                _context.SaveChanges();
                return(await OneDayFoodByUserIdForDateAsync(viewModel.AppUserID, viewModel.Date));
            }
            _context.SaveChanges();
            return(await GetOneDayFoodBiIdAsync(id));
        }
        public void DeleteFillMeasurement(List <AddMeasurementViewModel> list)
        {
            var delList = new List <FillMeasurement>();

            foreach (var viewModel in list)
            {
                delList.Add(_context.FillMeasurement.Find(viewModel.ID));
            }
            if (delList.Any())
            {
                _context.FillMeasurement.RemoveRange(delList);
                _context.SaveChanges();
            }
        }
Beispiel #15
0
        public async Task <Ingestion> CreateIngestionsAsync(IngestionViewModel viewModel)
        {
            var newIng = new Ingestion
            {
                Name         = viewModel.Name,
                OneDayFoodID = viewModel.OneDayFoodId
            };

            _context.Ingestion.Add(newIng);
            _context.SaveChanges();
            return(await
                   _context.Ingestion.SingleOrDefaultAsync(
                       t => t.Name == viewModel.Name& t.OneDayFoodID == viewModel.OneDayFoodId));
        }