public IActionResult Appointments(AppointmentsViewModel viewModel, int?id) { if (ModelState.IsValid) { if (id.HasValue) { Dogs dogs = adminRepository.GetDogs(id.Value); { viewModel.DogId = dogs.DogId; } } if (!personRepository.CheckIfUserExists(_userManager.GetUserId(User).ToString())) { personRepository.AddUser(_userManager.GetUserId(User).ToString()); } string UserId = _userManager.GetUserId(User).ToString(); if (!appoinmentRepository.CheckUniqueDateByDogId(viewModel.Date, viewModel.DogId)) { appoinmentRepository.Add(new AppointmentsModel() { AppointmentId = viewModel.AppointmentId, FirstName = viewModel.FirstName, LastName = viewModel.LastName, Date = viewModel.Date, DogId = viewModel.DogId, UserId = UserId }); ViewBag.message = "Your appointment was successful! See you soon!"; } else { ViewBag.message = "There already exists an appointment at this hour!"; } return(View(viewModel)); } //string connectionString = Configuration["ConnectionStrings:DefaultConnection"]; //using (SqlConnection connection = new SqlConnection(connectionString)) //{ // string insertString = $"Insert Into Appointments (FirstName, LastName, Date) Values ('{viewModel.FirstName}', '{viewModel.LastName}','{viewModel.Date}')"; // using (SqlCommand command = new SqlCommand(insertString, connection)) // { // command.CommandType = CommandType.Text; // connection.Open(); // command.ExecuteNonQuery(); // connection.Close(); // } // return RedirectToAction("Appointments"); //} else { return(View()); } }
public bool Add(AppoinmentView model) { return(_appoinment.Add(model)); }