private EditorRepositoryItem AddFile(EditorRepositoryItem item, EditorRepositoryItem folder) { EditorRepositoryItem file = item; try { Manager.BeginTransaction(); Person p = Manager.GetPerson(UC.CurrentUserID); if (p != null && item != null) { file = new EditorRepositoryItem(); file.Name = item.Name; file.Size = item.Size; file.MimeType = item.MimeType; file.Description = item.Description; file.Extension = item.Extension; file.Identifyer = item.Identifyer; file.CreateMetaInfo(p, UC.IpAddress, UC.ProxyIpAddress); file.IdOwner = IdUser; file.IdCommunity = IdCommunity; file.IsDirectory = false; file.Folder = folder; Manager.SaveOrUpdate(file); } Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); file = null; } return(file); }
//private string AddItem(String name, int parentId, string mimeType, Boolean isDirectory, long size, byte[] content) //{ // try // { // SqlConnection connection = this.GetConnection(this.connectionString); // SqlCommand command = // new SqlCommand( // "INSERT INTO Items ([Name], ParentId, MimeType, IsDirectory, [Size], Content) VALUES (@Name, @ParentId, @MimeType, @IsDirectory, @Size, @Content)", connection); // command.Parameters.Add(new SqlParameter("@Name", name)); // command.Parameters.Add(new SqlParameter("@ParentId", parentId)); // command.Parameters.Add(new SqlParameter("@MimeType", mimeType)); // command.Parameters.Add(new SqlParameter("@IsDirectory", isDirectory)); // command.Parameters.Add(new SqlParameter("@Size", size)); // command.Parameters.Add(new SqlParameter("@Content", content)); // using (connection) // { // connection.Open(); // command.ExecuteNonQuery(); // this._data = null; //force update // } // return String.Empty; // } // catch (Exception e) // { // return e.Message; // } //} private EditorRepositoryItem AddDirectory(String name, long?idFolder) { EditorRepositoryItem folder = null; try { Manager.BeginTransaction(); Person p = Manager.GetPerson(UC.CurrentUserID); if (p != null) { folder = new EditorRepositoryItem(); folder.CreateMetaInfo(p, UC.IpAddress, UC.ProxyIpAddress); folder.IdOwner = IdUser; folder.IdCommunity = IdCommunity; folder.IsDirectory = true; folder.Name = name; folder.Identifyer = Guid.NewGuid(); if (idFolder.HasValue) { folder.Folder = Manager.Get <EditorRepositoryItem>(idFolder.Value); } Manager.SaveOrUpdate(folder); } Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); } return(folder); }