예제 #1
0
 public IActionResult Create(TrainingViewModel trainingVM)
 {
     if (ModelState.IsValid)
     {
         trainingManager.Add(Mapper.Map <TrainingViewModel, Training>(trainingVM));
         return(RedirectToAction(nameof(Index)));
     }
     return(View(trainingVM));
 }
예제 #2
0
        public void AddTraining()
        {
            int tryint;

            Console.Write("Enter Swimmer Id:");
            string swimmertrainingId = Console.ReadLine();

            while (!int.TryParse(swimmertrainingId, out tryint))
            {
                Console.WriteLine("Incorrect Id! Try again ");
                swimmertrainingId = Console.ReadLine();
            }

            Console.Write("Enter Swim Style Id:");
            string swimStyleId = Console.ReadLine();

            while (!int.TryParse(swimStyleId, out tryint))
            {
                Console.WriteLine("Incorrect Id! Try again ");
                swimStyleId = Console.ReadLine();
            }

            string   trainingDate = Console.ReadLine();
            DateTime temp;

            while (!DateTime.TryParse(trainingDate, out temp))
            {
                Console.WriteLine("Incorrect Date! Try again ");
                trainingDate = Console.ReadLine();
            }

            string distance = Console.ReadLine();

            while (!int.TryParse(distance, out tryint))
            {
                Console.WriteLine("Incorrect Distance! Try again ");
                distance = Console.ReadLine();
            }

            try
            {
                Training training = new Training
                {
                    SwimmerId    = Convert.ToInt32(swimmertrainingId),
                    SwimStyleId  = Convert.ToInt32(swimStyleId),
                    TrainingDate = Convert.ToDateTime(trainingDate),
                    Distance     = Convert.ToInt32(distance)
                };

                _trainingManager.Add(training);
                Console.WriteLine("Training is added");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
예제 #3
0
        public void AddTraining(TrainingDTO training)
        {
            Training newTraining = new Training
            {
                SwimmerId    = Convert.ToInt32(training.SwimmerId),
                SwimStyleId  = Convert.ToInt32(training.SwimStyleId),
                TrainingDate = Convert.ToDateTime(training.TrainingDate),
                Distance     = Convert.ToInt32(training.Distance)
            };

            _trainingManager.Add(newTraining);
        }