I don’t know whats the problem My data is being saved but toast message and redirection to an action method is not working the fun part is while debugging it executes both ending conditions but I don’t know why this is not working! (Toast messages and redirections are working on Other Controllers)
Code:
[HttpPost]
public async Task CreateSlot(AppointmentViewModel model, Appointment appointment)
{
var currentUser = await _tokenService.GetUserViaToken();
string[] timeParts = model.Time.Split('-');
if (timeParts.Length == 2)
{
string startTimeString = timeParts[0].Trim();
string endTimeString = timeParts[1].Trim();
//only start time
TimeOnly startTime = TimeOnly.ParseExact(startTimeString, "hh:mm tt", CultureInfo.InvariantCulture);
TimeOnly endTime = TimeOnly.ParseExact(endTimeString, "hh:mm tt", CultureInfo.InvariantCulture);
var appointmentDate = DateTime.ParseExact(model.Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
var dateCheck = appointmentDate.DayOfWeek.ToString();
var slotId = _context.AvailableSlots.Where(x => x.UserId == model.DoctorId && x.StartTime == startTime && x.EndTime == endTime && x.Day.Name == appointmentDate.DayOfWeek.ToString()).Select(x => x.Id).FirstOrDefault();
var data = new Appointment
{
AppointmentById = currentUser.Id,
AppointmentWithId = model.DoctorId,
CreatedTime = DateTime.UtcNow,
AppointmentDate = appointmentDate,
AppointmentStatusId = 1,
AvailableSlotId = slotId
};
_context.Appointments.Add(data);
await _context.SaveChangesAsync();
TempData.AddToastMessage("success", "Appointment Created!");
return RedirectToAction("Index", "Home");
}
else
{
return null;
}
}
I want to show the the toast message and redirect to Index view
Fahad_88 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.