Bus IService1.GetBus(int id)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Online_Bus_Ticket_System;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "select * from Bus where id=@id";
            SqlParameter p = new SqlParameter("@id", id);

            cmd.Parameters.Add(p);
            cnn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            Bus           bs     = new Bus();

            if (reader.Read())
            {
                bs.ID           = reader.GetInt32(0);
                bs.Source       = reader.GetString(1);
                bs.Destination  = reader.GetString(2);
                bs.Dept_time    = reader.GetDateTime(3);
                bs.Arrival_time = reader.GetDateTime(4);
                bs.Bus_no       = reader.GetInt32(5);
                bs.Price        = reader.GetInt32(6);
            }
            else
            {
                NotFoundFolt nf = new NotFoundFolt();
                nf.Exception = "No record found with given ID";
                throw new FaultException <NotFoundFolt>(nf);
            }
            reader.Close();
            cnn.Close();
            return(bs);
        }
        Bus IService1.UpdateBus(Bus b)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Online_Bus_Ticket_System;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "update Bus set source=@source,destination=@destination,dept_time=@dept_time,arrival_time=@arrival_time,bus_no=@bus_no,price=@price where id=@id";
            SqlParameter para6 = new SqlParameter("@id", b.ID);
            SqlParameter para  = new SqlParameter("@source", b.Source);
            SqlParameter para1 = new SqlParameter("@destination", b.Destination);
            SqlParameter para2 = new SqlParameter("@dept_time", b.Dept_time);
            SqlParameter para3 = new SqlParameter("@arrival_time", b.Arrival_time);
            SqlParameter para4 = new SqlParameter("@bus_no", b.Bus_no);
            SqlParameter para5 = new SqlParameter("@price", b.Price);

            cmd.Parameters.Add(para);
            cmd.Parameters.Add(para1);
            cmd.Parameters.Add(para2);
            cmd.Parameters.Add(para3);
            cmd.Parameters.Add(para4);
            cmd.Parameters.Add(para5);
            cmd.Parameters.Add(para6);
            cnn.Open();
            int reader = cmd.ExecuteNonQuery();

            cnn.Close();
            if (reader == 0)
            {
                NotFoundFolt nf = new NotFoundFolt();
                nf.Exception = "Some issue found in updating the product please try after some time!!";
                throw new FaultException <NotFoundFolt>(nf);
            }
            return(b);
        }
        Ticket IService1.UpdateTicket(Ticket t)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Online_Bus_Ticket_System;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "update Ticket set c_name=@c_name,phone_no=@phone_no,c_to=@c_to,c_from=@c_from,dept_time=@dept_time,arrival_time=@arrival_time,total_seat=@total_seat,seat_num=@seat_num,amount=@amount,status=@status,email=@email where id=@id";

            SqlParameter para11 = new SqlParameter("@id", t.ID);
            SqlParameter para   = new SqlParameter("@c_name", t.C_name);
            SqlParameter para1  = new SqlParameter("@phone_no", t.Phone_no);
            SqlParameter para2  = new SqlParameter("@c_to", t.C_to);
            SqlParameter para3  = new SqlParameter("@c_from", t.C_from);
            SqlParameter para4  = new SqlParameter("@dept_time", t.Dept_time);
            SqlParameter para5  = new SqlParameter("@arrival_time", t.Arrival_time);
            SqlParameter para6  = new SqlParameter("@total_seat", t.Total_seat);
            SqlParameter para7  = new SqlParameter("@seat_num", t.Seat_num);
            SqlParameter para8  = new SqlParameter("@amount", t.Amount);
            SqlParameter para9  = new SqlParameter("@status", t.Status);
            SqlParameter para10 = new SqlParameter("@email", t.Email);


            cmd.Parameters.Add(para11);
            cmd.Parameters.Add(para);
            cmd.Parameters.Add(para1);
            cmd.Parameters.Add(para2);
            cmd.Parameters.Add(para3);
            cmd.Parameters.Add(para4);
            cmd.Parameters.Add(para5);
            cmd.Parameters.Add(para6);
            cmd.Parameters.Add(para7);
            cmd.Parameters.Add(para8);
            cmd.Parameters.Add(para9);
            cmd.Parameters.Add(para10);


            cnn.Open();
            int reader = cmd.ExecuteNonQuery();

            cnn.Close();
            if (reader == 0)
            {
                NotFoundFolt nf = new NotFoundFolt();
                nf.Exception = "Some issue found in updating the product please try after some time!!";
                throw new FaultException <NotFoundFolt>(nf);
            }
            return(t);
        }
        bool IService1.DeleteBus(int id)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Online_Bus_Ticket_System;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "delete from Bus where id=@id";
            SqlParameter para = new SqlParameter("@id", id);

            cmd.Parameters.Add(para);
            cnn.Open();
            int reader = cmd.ExecuteNonQuery();

            cnn.Close();
            if (reader == 0)
            {
                NotFoundFolt nf = new NotFoundFolt();
                nf.Exception = "No record found with given ID";
                throw new FaultException <NotFoundFolt>(nf);
            }
            return(true);
        }
        Ticket IService1.GetTicket(int id)
        {
            SqlConnection cnn = new SqlConnection(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Online_Bus_Ticket_System;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = "select * from Ticket where id=@id";
            SqlParameter p = new SqlParameter("@id", id);

            cmd.Parameters.Add(p);
            cnn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            Ticket        tc     = new Ticket();

            if (reader.Read())
            {
                tc.ID           = reader.GetInt32(0);
                tc.C_name       = reader.GetString(1);
                tc.Phone_no     = reader.GetString(2);
                tc.C_to         = reader.GetString(3);
                tc.C_from       = reader.GetString(4);
                tc.Dept_time    = reader.GetDateTime(5);
                tc.Arrival_time = reader.GetDateTime(6);
                tc.Total_seat   = reader.GetInt32(7);
                tc.Seat_num     = reader.GetString(8);
                tc.Amount       = reader.GetInt32(9);
                tc.Status       = (bool)reader.GetSqlBoolean(10);
                tc.Email        = reader.GetString(11);
            }
            else
            {
                NotFoundFolt nf = new NotFoundFolt();
                nf.Exception = "No record found with given ID";
                throw new FaultException <NotFoundFolt>(nf);
            }
            reader.Close();
            cnn.Close();
            return(tc);
        }