public static List<FileRegistration> getMijnBestanden(string ingelogdeUser) { List<FileRegistration> files = new List<FileRegistration>(); string sql = "SELECT * FROM FileRegistration WHERE UserName=@username"; DbParameter par1 = Database.AddParameter(CONNECTIONSTRING, "@username", ingelogdeUser); DbParameter[] parameters = { par1 }; DbDataReader reader = Database.GetData(CONNECTIONSTRING, sql, parameters); while (reader.Read()) { FileRegistration bestand = new FileRegistration() { FileId = Convert.ToInt32(reader["FileId"]), Description = reader["Description"].ToString(), FileName = reader["FileName"].ToString(), UploadTime = Convert.ToDateTime(reader["UploadTime"]), UserName = reader["UserName"].ToString() }; files.Add(bestand); } return files; }
public static List<FileRegistration> getAlleBestanden() { List<FileRegistration> files = new List<FileRegistration>(); // SELECT column_name(s) //FROM table1 //INNER JOIN table2 //ON table1.column_name=table2.column_name; string sql = "SELECT * FROM FileRegistration"; DbParameter[] parameters = null; DbDataReader reader = Database.GetData(CONNECTIONSTRING, sql, parameters); while (reader.Read()) { FileRegistration bestand = new FileRegistration() { FileId = (int)reader["FileId"], Description = reader["Description"].ToString(), FileName = reader["FileName"].ToString(), UploadTime = Convert.ToDateTime(reader["UploadTime"]), UserName = reader["UserName"].ToString() }; files.Add(bestand); } return files; }
public static List<FileRegistration> getBestandenToegang(string ingelogdeUser) { List<FileRegistration> files = new List<FileRegistration>(); // SELECT column_name(s) //FROM table1 //INNER JOIN table2 //ON table1.column_name=table2.column_name; string sql = "SELECT * FROM FileRegistration INNER JOIN FileUser ON FileRegistration.FileId = FileUser.FileId WHERE FileUser.UserName = @username"; DbParameter par1 = Database.AddParameter(CONNECTIONSTRING, "@username", ingelogdeUser); DbParameter[] parameters = { par1 }; DbDataReader reader = Database.GetData(CONNECTIONSTRING, sql, parameters); while (reader.Read()) { FileRegistration bestand = new FileRegistration() { FileId = (int)reader["FileId"], Description = reader["Description"].ToString(), FileName = reader["FileName"].ToString(), UploadTime = Convert.ToDateTime(reader["UploadTime"]), UserName = reader["UserName"].ToString() }; files.Add(bestand); } return files; }
public static void SaveLogs(FileRegistration file) { string sql = "INSERT INTO DownloadLog VALUES(@fileId, @fileName, @datetime, @username)"; DbParameter par1 = Database.AddParameter(CONNECTIONSTRING, "@fileId", file.FileId); DbParameter par2 = Database.AddParameter(CONNECTIONSTRING, "@fileName", file.FileName); DbParameter par3 = Database.AddParameter(CONNECTIONSTRING, "@datetime", DateTime.Now); DbParameter par4 = Database.AddParameter(CONNECTIONSTRING, "@username", file.UserName); DbParameter[] parameters = { par1, par2, par3, par4 }; Database.ModifyData(CONNECTIONSTRING, sql, parameters); }
public static void UpdateFile(FileRegistration file) { string sql = "UPDATE FileRegistration SET Description=@description WHERE FileId=@id"; DbParameter par1 = Database.AddParameter(CONNECTIONSTRING, "@description", file.Description); DbParameter par2 = Database.AddParameter(CONNECTIONSTRING, "@id", file.FileId); DbParameter[] parameters = { par1, par2 }; int affected = Database.ModifyData(CONNECTIONSTRING, sql, parameters); }
public static FileRegistration GetFileRegistrationById(int id) { FileRegistration nieuw = new FileRegistration(); string sql = "SELECT * FROM FileRegistration WHERE FileId=@fileId"; DbParameter par1 = Database.AddParameter(CONNECTIONSTRING, "@fileId", id); DbParameter[] parameters = { par1 }; DbDataReader reader = Database.GetData(CONNECTIONSTRING, sql, parameters); while (reader.Read()) { FileRegistration bestand = new FileRegistration() { FileId = (int)reader["FileId"], Description = reader["Description"].ToString(), FileName = reader["FileName"].ToString(), UploadTime = Convert.ToDateTime(reader["UploadTime"]), UserName = reader["UserName"].ToString(), }; nieuw = bestand; } return nieuw; }
public ViewResult Edit2(FileRegistration file) { if (file.UserName == User.Identity.Name) { FileRegistrationDA.UpdateFile(file); FileRegistrationVM overzicht = new FileRegistrationVM(); overzicht.Me = FileRegistrationDA.getMijnBestanden(User.Identity.Name); overzicht.Others = FileRegistrationDA.getBestandenToegang(User.Identity.Name); return View("File", overzicht); } else { return View("Error"); } }