Esempio n. 1
0
        public WorkoutMeasurementsViewModel(Window window, WorkoutResultItem workoutResultItem) : base(window)
        {
            mWindow             = window;
            WindowMinimumHeight = 350;
            WindowMinimumWidth  = 600;
            Title = $"Save Workout Plan Results:";

            WorkoutResultItem = workoutResultItem;

            BodyPartItems = Enum.GetValues(typeof(BodyPart)).Cast <BodyPart>()
                            .Select(x => new BodyPartItem()
            {
                BodyPartName = x.ToString(),
                BodyPart     = x
            }).ToList().ToObservableCollection();

            foreach (var workoutMeasurement in WorkoutResultItem.WorkoutMeasurements)
            {
                BodyPartItems.Remove(BodyPartItems.First(x => x.BodyPart == workoutMeasurement.BodyPart));
            }

            SelectedBodyPartItem = BodyPartItems.FirstOrDefault();

            AddMeasurementCommand    = new RelayCommand((p) => AddMeasurement());
            RemoveMeasurementCommand = new RelayParameterizedCommand(RemoveMeasurement);
        }
Esempio n. 2
0
        public void RemoveMeasurement(object sender)
        {
            var workoutMeasurement = (sender as Button).DataContext as WorkoutMeasurement;

            using var db = new AppDbContext();
            db.WorkoutMeasurements.Remove(workoutMeasurement);
            db.SaveChanges();

            var bodyPartItem = new BodyPartItem
            {
                BodyPart     = workoutMeasurement.BodyPart,
                BodyPartName = workoutMeasurement.BodyPart.ToString()
            };

            BodyPartItems.Insert(0, bodyPartItem);
            SelectedBodyPartItem = bodyPartItem;

            WorkoutResultItem.WorkoutMeasurements.Remove(workoutMeasurement);
        }
Esempio n. 3
0
        public void AddMeasurement()
        {
            if (Measurement <= 0)
            {
                return;
            }

            var measurement = new WorkoutMeasurement
            {
                BodyPart        = SelectedBodyPartItem.BodyPart,
                WorkoutResultId = WorkoutResultItem.WorkoutResult.Id,
                Measurement     = Measurement
            };

            using var db = new AppDbContext();
            db.WorkoutMeasurements.Add(measurement);
            db.SaveChanges();

            WorkoutResultItem.WorkoutMeasurements.Add(measurement);
            BodyPartItems.Remove(SelectedBodyPartItem);
            Measurement = 0;
        }