Exemplo 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);
        }
Exemplo n.º 2
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;
        }