public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } Client AddClient = new Client(); AddClient.FirstName = FName; AddClient.LastName = LName; AddClient.MiddleName = MName; AddClient.Email = Email; AddClient.Phone = Phone; AddClient.Address = Address; ResolutionsSystem rs = new ResolutionsSystem(); SqlCode code = rs.CreateClient(AddClient); return(new RedirectToPageResult("Index")); }
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")); }