public OperationResult AddFolder(Folder folder) { OperationResult operationResult = new Models.OperationResult(); using (IDbConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection)) { try { string query = "INSERT INTO [HoldFolders]" + " (" + " [ActiveDirectoryUser]" + " ,[DocumentType]" + " ,[FolderName]" + " )" + "VALUES" + " (" + " @ActiveDirectoryUser,@DocumentType,@FolderName" + " )"; db.Execute(query, new { @ActiveDirectoryUser = Utility.GetUserName(), @DocumentType = folder.DocumentType, @FolderName = folder.FolderName }); operationResult.Success = true; return operationResult; } catch (Exception er) { operationResult.Success = false; operationResult.AddMessage(er.ToString()); return operationResult; } } }
public List<Folder> GetFolders(string folderType) { List<Folder> folderList = new List<Folder>(); List<Folder> folderList2 = new List<Folder>(); Folder folder = new Folder(); folder.Id = 0; folder.FolderName = "Select Folder"; folderList2.Add(folder); try { string query = "SELECT [ID],[FolderName]" + " FROM [HoldFolders]" + " where [ActiveDirectoryUser] = @ActiveDirectoryUser" + " and documentType = @documentType"; using (SqlConnection db = new SqlConnection(ConfigurationValues.PostOfficeDatabaseConnection)) { folderList = db.Query<Folder>(query, new { @ActiveDirectoryUser = Utility.GetUserName(), @documentType = folderType }).ToList(); for (int i = 0; i < folderList.Count; i++) { folderList2.Add(folderList[i]); } return folderList2; } } catch (Exception er) { Logging.LogErrors(ConfigurationValues.ErrorLogPath, er.ToString()); return folderList2; } }