public IActionResult OnGet() { string username = GetSessionValue("Username"); if (username == null || username == string.Empty) { return(new RedirectToPageResult("Index")); } int appointmentID = int.Parse(HttpContext.Session.GetString("UpdateAppointmentID")); System.Diagnostics.Debug.WriteLine($"UpdateAppointment: Updating appointment: {appointmentID}"); ResolutionsSystem rs = new ResolutionsSystem(); Classes.Appointment app = rs.GetAppointment(appointmentID); AppointmentID = app.AppointmentID; AppointmentDate = app.AppointmentDate; Classes.Client client = rs.GetClient(app.ClientID); ClientID = (int)client.ClientID; if (client.MiddleName == null) { ClientFullName = $"{client.FirstName} {client.LastName}"; } else { ClientFullName = $"{client.FirstName} {client.MiddleName} {client.LastName}"; } Classes.Counsellor counsellor = rs.GetCounsellor(app.CounsellorID); CounsellorID = counsellor.CounsellorID; CounsellorName = counsellor.Name; //Message = $"Updating appointment {appointmentID}\n" + // $"Date: {app.AppointmentDate}\n" + // $"Client Name: {clientName} ({client.ClientID})\n" + // $"Counsellor: {counsellor.Name} ({counsellor.CounsellorID})"; System.Diagnostics.Debug.WriteLine($"Updated appointment: {(int)AppointmentID}"); //PopulateFields(app); //counsellors dropdownlist //PopulateSelectList(); //ListOfCounsellors = rs.GetCounsellors(); //client dropdownlist //PopulateSelectListForClient(); //ListOfClients = rs.GetClients(); return(Page()); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } ResolutionsSystem rs = new ResolutionsSystem(); Classes.Client client = new Client(); if (MiddleName == null || MiddleName == "") { client = rs.GetClient(FirstName, LastName); } else { client = rs.GetClient(FirstName, MiddleName, LastName); } int counsellorID; SqlCode code; if (client.ClientID == null) { //client doesn't exist System.Diagnostics.Debug.WriteLine("Client doesn't exist"); //client doesn't exist, so insert a new client into the database code = rs.CreateClient(GetClient()); if (code == SqlCode.Failure) { System.Diagnostics.Debug.WriteLine("Failed to create client"); Message = "Failed to create client"; return(Page()); } } else { System.Diagnostics.Debug.WriteLine("Client exists"); } //client now exists if (MiddleName == null || MiddleName == "") { client = rs.GetClient(FirstName, LastName); } else { client = rs.GetClient(FirstName, MiddleName, LastName); } counsellorID = SelectedID; System.Diagnostics.Debug.WriteLine($"TimeSelected: {TimeSelected}"); //TimeSpan appointmentTime = TimeSpan.Parse(TimeSelected); //DateTime appointmentDateTime = Date.Add(appointmentTime); DateTime appointmentDateTime = Date.Add(Time); Classes.Appointment newAppointment = new Classes.Appointment() { AppointmentDate = appointmentDateTime, ClientID = (int)client.ClientID, CounsellorID = counsellorID }; code = rs.BookAppointment(newAppointment); if (code == SqlCode.Failure) { Message = "Failed to create appointment"; return(Page()); } return(new RedirectToPageResult("Index")); }