Ejemplo n.º 1
0
        public static ClientsDetailsPackage getClientsDetailsPackage(LoginPackage lp)
        {
            if (!isClientExist(lp.Username, lp.Password))
            {
                return new ClientsDetailsPackage {
                           Exist = false
                }
            }
            ;

            setLogOn(lp);
            Client c = new Client();

            c.getClient(lp.Username);

            foreach (var item in lp.FileList)
            {
                int id = item.insertFile();

                ClientFile cf = new ClientFile(lp.Username, id);
                cf.insertClientFile();
            }

            return(new ClientsDetailsPackage {
                Exist = true, Username = c.Username, UpPath = c.UpPath, DownPath = c.DownPath, IP = c.Ip, Port = c.Port
            });
        }
Ejemplo n.º 2
0
        private static void setLogOn(LoginPackage lp)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["MiniTorrentLibrary.Properties.Settings.MiniTorrentDBConnectionString"].ConnectionString;
            string query            = "UPDATE Clients SET Active = @active, Ip = @ip, Port = @port where Username = @username";

            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    connection.Open();

                    command.Parameters.AddWithValue("@username", lp.Username);
                    command.Parameters.AddWithValue("@active", true);
                    command.Parameters.AddWithValue("@ip", lp.IP);
                    command.Parameters.AddWithValue("@port", lp.Port);

                    command.ExecuteScalar();
                }
        }