Пример #1
0
        void AddWorkoutInputMenu(User user)
        {
            DateTime      whenWorkedOut;
            double        distance = 0;
            int           minutesWorkedOut;
            bool          happyWithChoice;
            double        points = 0;
            TypeOfWorkout workoutChoice;

            Console.Clear();//RENSAR FÖREGÅENDE MENY FÖR LÄTTARE LÄSNING.

            Console.WriteLine("När tränade du? (åååå-mm-dd)");
            Console.Write("Datum: ");
            whenWorkedOut = error.TryTime();

            Console.Clear();
            while (true)
            {
                Console.WriteLine("Vilken typ av träning önskar du registrera?");
                Console.WriteLine($"{Convert.ToInt32(TypeOfWorkout.Walking)}. Gång");
                Console.WriteLine($"{Convert.ToInt32(TypeOfWorkout.Running)}. Löpning");
                Console.WriteLine($"{Convert.ToInt32(TypeOfWorkout.Swimming)}. Simning");
                Console.WriteLine($"{Convert.ToInt32(TypeOfWorkout.Strength)}. Styrketräning");
                workoutChoice = GetChoiceFromUser();
                Console.Clear();

                if (workoutChoice == TypeOfWorkout.Walking ||
                    workoutChoice == TypeOfWorkout.Running ||
                    workoutChoice == TypeOfWorkout.Swimming)
                {
                    Console.Write("Distans i KM: ");
                    distance = error.TryDouble();
                    Console.Clear();
                    break;
                }
                else if (workoutChoice == TypeOfWorkout.Strength)
                {
                    break;
                }

                Console.Clear();
                error.ErrorMessage();
                Console.Write("\nTryck valfri tangent för att fortsätta.");
                Console.ReadKey();
            }
            Console.Write("Träningstid i minuter: ");
            minutesWorkedOut = error.TryInt();
            Console.Clear();

            Console.Write("Är du nöjd med träningen (J/N)?");
            happyWithChoice = error.TryYesOrNo();
            Console.Clear();

            if (happyWithChoice == true)
            {
                var db = new Database("Server=40.85.84.155;Database=Student5;User=Student5;Password=YH-student@2019;");
                if (workoutChoice == TypeOfWorkout.Walking)
                {
                    points = pointsCalculator.PointsForWalking(minutesWorkedOut, distance);
                    var workout = new Walking(TypeOfWorkout.Walking, whenWorkedOut,
                                              minutesWorkedOut, points, distance);
                    db.AddWorkouts(workout, user);
                }
                else if (workoutChoice == TypeOfWorkout.Running)
                {
                    points = pointsCalculator.PointsForRunning(minutesWorkedOut, distance);
                    var workout = new Running(TypeOfWorkout.Running, whenWorkedOut,
                                              minutesWorkedOut, points, distance);
                    db.AddWorkouts(workout, user);
                }
                else if (workoutChoice == TypeOfWorkout.Swimming)
                {
                    points = pointsCalculator.PointsForSwimming(minutesWorkedOut, distance);
                    var workout = new Swimming(TypeOfWorkout.Swimming, whenWorkedOut,
                                               minutesWorkedOut, points, distance);
                    db.AddWorkouts(workout, user);
                }
                else if (workoutChoice == TypeOfWorkout.Strength)
                {
                    points = pointsCalculator.PointsForStength(minutesWorkedOut);
                    var workout = new Strength(TypeOfWorkout.Strength, whenWorkedOut,
                                               minutesWorkedOut, points);
                    db.AddWorkouts(workout, user);
                }
            }
            else
            {
                Console.WriteLine("Du kommer nu att returneras till huvudmenyn.");
            }
            if (happyWithChoice == true)
            {
                Comments comment = new Comments();
                Console.WriteLine($"Ditt träningspass har nu registrerats. Du fick {points} poäng!");
                if (points >= 80)
                {
                    Console.WriteLine(comment.PositiveComment());
                }
                else
                {
                    Console.Write(comment.NegativeComment());
                }
            }
            Console.Write("\nKlicka på valfri tangent för att fortsätta.");
            Console.ReadKey();
        }