Esempio n. 1
0
        public List <Classes.Appointment> GetAppointments()
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = Util.GetConnectionString();
            connection.Open();

            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "GetAppointments";

            List <Classes.Appointment> appointments = new List <Classes.Appointment>();

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Classes.Appointment newAppt = new Classes.Appointment()
                {
                    AppointmentID   = int.Parse(reader["AppointmentID"].ToString()),
                    AppointmentDate = DateTime.Parse(reader["AppointmentDate"].ToString()),
                    ClientID        = int.Parse(reader["ClientID"].ToString()),
                    CounsellorID    = int.Parse(reader["CounsellorID"].ToString()),
                    Notes           = reader["Notes"].ToString(),
                };

                appointments.Add(newAppt);
            }

            return(appointments);
        }
        public IActionResult OnPost()
        {
            SqlCode code;

            //System.Diagnostics.Debug.WriteLine($"TimeSelected: {TimeSelected}");
            //DateTime appointmentDateTime = Date.Add(Time);

            //counsellorID = SelectedID;
            //clientID = SelectedClientID;

            Classes.Appointment appointment = new Classes.Appointment()
            {
                AppointmentID   = (int)AppointmentID,
                AppointmentDate = AppointmentDate,
                ClientID        = ClientID,
                CounsellorID    = CounsellorID,
                Notes           = Notes
            };

            System.Diagnostics.Debug.WriteLine("Displaying updated appointment");
            appointment.Print();

            ResolutionsSystem rs = new ResolutionsSystem();

            code = rs.UpdateAppointment(appointment);

            if (code == SqlCode.Failure)
            {
                Message = "Failed to Update appointment";
                //return Page();
            }

            return(new RedirectToPageResult("ViewAppointments"));
        }
 private void PopulateFields(Classes.Appointment Appointment)
 {
     AppointmentID   = Appointment.AppointmentID;
     AppointmentDate = Appointment.AppointmentDate;
     Notes           = Appointment.Notes;
     //Date = DateTime.Now;
     //Time = new TimeSpan(8, 0, 0);
 }
        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());
        }
Esempio n. 5
0
        public List <Classes.Appointment> GetAppointmentsByClient(int ClientID)
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = Util.GetConnectionString();
            connection.Open();

            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "GetAppointmentsByClient";

            SqlParameter parameter = new SqlParameter
            {
                ParameterName = "@ClientID",
                SqlDbType     = SqlDbType.Int,
                Direction     = ParameterDirection.Input,
                SqlValue      = ClientID
            };

            command.Parameters.Add(parameter);

            List <Classes.Appointment> appointments = new List <Classes.Appointment>();

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Classes.Appointment newAppt = new Classes.Appointment()
                {
                    AppointmentID   = int.Parse(reader["AppointmentID"].ToString()),
                    AppointmentDate = DateTime.Parse(reader["AppointmentDate"].ToString()),
                    ClientID        = int.Parse(reader["ClientID"].ToString()),
                    CounsellorID    = int.Parse(reader["CounsellorID"].ToString()),
                    Notes           = reader["Notes"].ToString(),
                };

                appointments.Add(newAppt);
            }

            return(appointments);
        }
Esempio n. 6
0
        public Classes.Appointment GetAppointment(int AppointmentID)
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = Util.GetConnectionString();
            connection.Open();

            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "GetAppointment";

            SqlParameter parameter = new SqlParameter
            {
                ParameterName = "@AppointmentID",
                SqlDbType     = SqlDbType.Int,
                Direction     = ParameterDirection.Input,
                SqlValue      = AppointmentID
            };

            command.Parameters.Add(parameter);

            Classes.Appointment appointment = new Classes.Appointment();

            SqlDataReader reader = command.ExecuteReader();

            reader.Read();

            if (reader.HasRows)
            {
                appointment = new Classes.Appointment()
                {
                    AppointmentID   = int.Parse(reader["AppointmentID"].ToString()),
                    AppointmentDate = DateTime.Parse(reader["AppointmentDate"].ToString()),
                    ClientID        = int.Parse(reader["ClientID"].ToString()),
                    CounsellorID    = int.Parse(reader["CounsellorID"].ToString()),
                    Notes           = reader["Notes"].ToString(),
                };
            }

            return(appointment);
        }
Esempio n. 7
0
        public SqlCode UpdateAppointment(Classes.Appointment Appointment)
        {
            SqlConnection connection = new SqlConnection();

            connection.ConnectionString = Util.GetConnectionString();
            connection.Open();

            SqlCommand command = new SqlCommand();

            command.Connection  = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "UpdateAppointment";

            SqlParameter parameter = new SqlParameter
            {
                ParameterName = "@AppointmentID",
                SqlDbType     = SqlDbType.Int,
                Direction     = ParameterDirection.Input,
                SqlValue      = Appointment.AppointmentID
            };

            command.Parameters.Add(parameter);

            parameter = new SqlParameter
            {
                ParameterName = "@AppointmentDate",
                SqlDbType     = SqlDbType.DateTime,
                Direction     = ParameterDirection.Input,
                SqlValue      = Appointment.AppointmentDate
            };
            command.Parameters.Add(parameter);

            parameter = new SqlParameter
            {
                ParameterName = "@ClientID",
                SqlDbType     = SqlDbType.Int,
                Direction     = ParameterDirection.Input,
                SqlValue      = Appointment.ClientID
            };
            command.Parameters.Add(parameter);

            parameter = new SqlParameter
            {
                ParameterName = "@CounsellorID",
                SqlDbType     = SqlDbType.Int,
                Direction     = ParameterDirection.Input,
                SqlValue      = Appointment.CounsellorID
            };
            command.Parameters.Add(parameter);

            parameter = new SqlParameter
            {
                ParameterName = "@Notes",
                SqlDbType     = SqlDbType.NText,
                Direction     = ParameterDirection.Input,
                SqlValue      = Appointment.Notes
            };
            command.Parameters.Add(parameter);

            int     returnVal;
            SqlCode code;

            try
            {
                returnVal = command.ExecuteNonQuery();
                code      = SqlCode.Success;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine($"e: {e.Message}");
                code = SqlCode.Failure;
            }

            connection.Close();
            return(code);
        }
Esempio n. 8
0
        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"));
        }