public IActionResult Create(TrainingViewModel trainingVM) { if (ModelState.IsValid) { trainingManager.Add(Mapper.Map <TrainingViewModel, Training>(trainingVM)); return(RedirectToAction(nameof(Index))); } return(View(trainingVM)); }
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); } }
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); }