Blacker.MangaScraper.Library.DAL.StorageDAL.GetRecentFolders C# (CSharp) Method

GetRecentFolders() public method

public GetRecentFolders ( System.Guid scraperId, string mangaId ) : int>.IDictionary
scraperId System.Guid
mangaId string
return int>.IDictionary
        public IDictionary<string, int> GetRecentFolders(Guid scraperId, string mangaId)
        {
            if (scraperId == Guid.Empty)
                throw new ArgumentException("Scraper Id must not empty.", "scraperId");

            if (String.IsNullOrEmpty(mangaId))
                throw new ArgumentException("Manga Id must not be null or empty", "mangaId");

            // let's select just latest 5 records
            const string sql = @"SELECT DownloadFolder FROM Chapters WHERE ScraperId=@ScraperId AND MangaId=@MangaId ORDER BY Downloaded DESC LIMIT 5";

            var folders = new Dictionary<string, int>();

            using (var connection = GetConnection())
            using (var command = GetTextCommand(sql))
            {
                command.Parameters.AddWithValue("@ScraperId", scraperId);
                command.Parameters.AddWithValue("@MangaId", mangaId);

                var table = ExecuteDataTable(command, connection);

                if (table == null)
                    return folders;

                foreach (DataRow row in table.Rows)
                {
                    var folder = row["DownloadFolder"] as string;

                    if (folder == null)
                    {
                        continue;
                    }

                    if (folders.ContainsKey(folder))
                    {
                        folders[folder]++;
                    }
                    else
                    {
                        folders[folder] = 1;
                    }
                }
            }

            return folders;
        }