| | | 1 | | namespace ConsoleApp1; |
| | | 2 | | |
| | | 3 | | public static class StoredProcedureTypeExtensions |
| | | 4 | | { |
| | | 5 | | public static string GetProcedureName(this StoredProcedureType type) |
| | | 6 | | { |
| | 19 | 7 | | return type switch |
| | 19 | 8 | | { |
| | 1 | 9 | | StoredProcedureType.GetVolnaCategories => "GetVolnaCategories", |
| | 1 | 10 | | StoredProcedureType.GetOzonCategories => "GetOzonCategories", |
| | 1 | 11 | | StoredProcedureType.GetCtCategories => "GetCtCategories", |
| | 1 | 12 | | StoredProcedureType.GetICGroups => "GetICGroups", |
| | 1 | 13 | | StoredProcedureType.SearchVolnaCategoryByName => "SearchVolnaCategoryByName", |
| | 1 | 14 | | StoredProcedureType.SearchOzonCategoryByName => "SearchOzonCategoryByName", |
| | 1 | 15 | | StoredProcedureType.SearchCtCategoryByName => "SearchCtCategoryByName", |
| | 1 | 16 | | StoredProcedureType.SearchVolnaCategoryById => "SearchVolnaCategoryById", |
| | 1 | 17 | | StoredProcedureType.SearchOzonCategoryById => "SearchOzonCategoryById", |
| | 1 | 18 | | StoredProcedureType.SearchCtCategoryById => "SearchCtCategoryById", |
| | 1 | 19 | | StoredProcedureType.AddCategoryLink => "AddCategoryLink", |
| | 1 | 20 | | StoredProcedureType.DeleteCategoryLink => "DeleteCategoryLinkById", |
| | 1 | 21 | | StoredProcedureType.GetCatTreeCategories => "GetCatTreeCategories", |
| | 1 | 22 | | StoredProcedureType.SearchCatTreeCategoryById => "SearchCatTreeCategoryById", |
| | 1 | 23 | | StoredProcedureType.SearchICGroupById => "SearchICGroupById", |
| | 1 | 24 | | StoredProcedureType.InsertUnifiedCategoryIfNotExists => "sp_InsertUnifiedCategoryIfNotExists", |
| | 1 | 25 | | StoredProcedureType.DeleteUnifiedCategoryByIcId => "DeleteUnifiedCategoryByIcId", |
| | 1 | 26 | | StoredProcedureType.AddCategoryTranslations => "AddCategoryTranslations", |
| | 1 | 27 | | _ => throw new ArgumentException("Unknown procedure type") |
| | 19 | 28 | | }; |
| | | 29 | | } |
| | | 30 | | public static Dictionary<string, object> GetParameter(this StoredProcedureType type, object parameter) |
| | | 31 | | { |
| | 15 | 32 | | var paramDict = new Dictionary<string, object>(); |
| | | 33 | | |
| | 15 | 34 | | if (parameter is not null) |
| | | 35 | | { |
| | | 36 | | switch (type) |
| | | 37 | | { |
| | | 38 | | case StoredProcedureType.SearchVolnaCategoryByName: |
| | | 39 | | case StoredProcedureType.SearchOzonCategoryByName: |
| | | 40 | | case StoredProcedureType.SearchCtCategoryByName: |
| | 3 | 41 | | if (parameter is string searchName) |
| | | 42 | | { |
| | 3 | 43 | | paramDict["searchName"] = searchName; |
| | | 44 | | } |
| | 3 | 45 | | break; |
| | | 46 | | |
| | | 47 | | case StoredProcedureType.SearchCtCategoryById: |
| | | 48 | | case StoredProcedureType.SearchVolnaCategoryById: |
| | | 49 | | case StoredProcedureType.SearchOzonCategoryById: |
| | 4 | 50 | | if (parameter is int searchId) |
| | | 51 | | { |
| | 3 | 52 | | paramDict["categoryId"] = searchId; |
| | | 53 | | } |
| | 3 | 54 | | break; |
| | | 55 | | |
| | | 56 | | case StoredProcedureType.AddCategoryLink: |
| | 1 | 57 | | if (parameter is (int ctCategoryId, int linkCategoryId, string linkTypeName)) |
| | | 58 | | { |
| | 1 | 59 | | paramDict["ct_category_id"] = ctCategoryId; |
| | 1 | 60 | | paramDict["link_category_id"] = linkCategoryId; |
| | 1 | 61 | | paramDict["link_type_name"] = linkTypeName; |
| | | 62 | | } |
| | 1 | 63 | | break; |
| | | 64 | | case StoredProcedureType.DeleteCategoryLink: |
| | 1 | 65 | | if (parameter is int categoryLinkId) |
| | | 66 | | { |
| | 1 | 67 | | paramDict["CategoryLinkId"] = categoryLinkId; |
| | | 68 | | } |
| | 1 | 69 | | break; |
| | | 70 | | case StoredProcedureType.SearchCatTreeCategoryById: |
| | 1 | 71 | | if (parameter is int catTreeId) |
| | | 72 | | { |
| | 1 | 73 | | paramDict["categoryId"] = catTreeId; |
| | | 74 | | } |
| | 1 | 75 | | break; |
| | | 76 | | case StoredProcedureType.SearchICGroupById: |
| | 1 | 77 | | if (parameter is int groupId) |
| | | 78 | | { |
| | 1 | 79 | | paramDict["groupId"] = groupId; |
| | | 80 | | } |
| | 1 | 81 | | break; |
| | | 82 | | case StoredProcedureType.InsertUnifiedCategoryIfNotExists: |
| | 1 | 83 | | if (parameter is ValueTuple<int?, int?, int?> tuple) |
| | | 84 | | { |
| | 1 | 85 | | paramDict["ozon_id"] = tuple.Item1; |
| | 1 | 86 | | paramDict["volna_id"] = tuple.Item2; |
| | 1 | 87 | | paramDict["ic_id"] = tuple.Item3; |
| | | 88 | | } |
| | 1 | 89 | | break; |
| | | 90 | | case StoredProcedureType.DeleteUnifiedCategoryByIcId: |
| | 1 | 91 | | if (parameter is int icId) |
| | | 92 | | { |
| | 1 | 93 | | paramDict["IcId"] = icId; |
| | | 94 | | } |
| | 1 | 95 | | break; |
| | | 96 | | case StoredProcedureType.AddCategoryTranslations: |
| | 1 | 97 | | if (parameter is (int categoryId, string linkType, string translation)) |
| | | 98 | | { |
| | 1 | 99 | | paramDict["category_id"] = categoryId; |
| | 1 | 100 | | paramDict["link_type_name"] = linkType; |
| | 1 | 101 | | paramDict["translation"] = translation; |
| | | 102 | | } |
| | | 103 | | break; |
| | | 104 | | |
| | | 105 | | } |
| | | 106 | | } |
| | | 107 | | |
| | 15 | 108 | | return paramDict; |
| | | 109 | | } |
| | | 110 | | } |