Skip to content

Commit

Permalink
Minor improvements (#467)
Browse files Browse the repository at this point in the history
* Use ArgumentNullException
* Extend repository pattern (add new method GetOneAsync)
  • Loading branch information
KrzysztofPajak authored Feb 11, 2024
1 parent f6912b9 commit b1a94ce
Show file tree
Hide file tree
Showing 233 changed files with 1,026 additions and 2,174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public MetadataApiDescriptionProvider(
/// <inheritdoc />
public void OnProvidersExecuting(ApiDescriptionProviderContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
ArgumentNullException.ThrowIfNull(context);

foreach (var action in context.Actions.OfType<ControllerActionDescriptor>())
{
Expand Down
4 changes: 1 addition & 3 deletions src/API/Grand.Api/Filters/AuthorizeApiAdminAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ public AuthorizeApiAdminFilter(bool ignoreFilter, IPermissionService permissionS
/// <param name="filterContext">Authorization filter context</param>
public async Task OnAuthorizationAsync(AuthorizationFilterContext filterContext)
{

if (filterContext == null)
throw new ArgumentNullException(nameof(filterContext));
ArgumentNullException.ThrowIfNull(filterContext);

//check whether this filter has been overridden for the action
var actionFilter = filterContext.ActionDescriptor.FilterDescriptors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public CookieAuthenticationService(
/// <param name="isPersistent">Whether the authentication session is persisted across multiple requests</param>
public virtual async Task SignIn(Customer customer, bool isPersistent)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
ArgumentNullException.ThrowIfNull(customer);

//create claims for customer's username and email
var claims = new List<Claim>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ public virtual bool AuthenticationProviderIsAvailable(string systemName)
/// <returns>Result of an authentication</returns>
public virtual async Task<IActionResult> Authenticate(ExternalAuthParam parameters, string returnUrl = null)
{
if (parameters == null)
throw new ArgumentNullException(nameof(parameters));
ArgumentNullException.ThrowIfNull(parameters);

if (!AuthenticationProviderIsAvailable(parameters.ProviderSystemName))
return Error(new[] { "External authentication method cannot be loaded" });
Expand All @@ -279,8 +278,7 @@ public virtual async Task<IActionResult> Authenticate(ExternalAuthParam paramete
/// <param name="parameters">External authentication parameters</param>
public virtual async Task AssociateCustomer(Customer customer, ExternalAuthParam parameters)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
ArgumentNullException.ThrowIfNull(customer);

var externalAuthenticationRecord = new ExternalAuthentication {
CustomerId = customer.Id,
Expand All @@ -301,8 +299,7 @@ public virtual async Task AssociateCustomer(Customer customer, ExternalAuthParam
/// <returns>Customer</returns>
public virtual async Task<Customer> GetCustomer(ExternalAuthParam parameters)
{
if (parameters == null)
throw new ArgumentNullException(nameof(parameters));
ArgumentNullException.ThrowIfNull(parameters);

var associationRecord = (from q in _externalAuthenticationRecordRepository.Table
where q.ExternalIdentifier.ToLowerInvariant() == parameters.Identifier
Expand All @@ -317,8 +314,8 @@ where q.ExternalIdentifier.ToLowerInvariant() == parameters.Identifier

public virtual async Task<IList<ExternalAuthentication>> GetExternalIdentifiers(Customer customer)
{
if (customer == null)
throw new ArgumentNullException(nameof(customer));
ArgumentNullException.ThrowIfNull(customer);

var query = from p in _externalAuthenticationRecordRepository.Table
where p.CustomerId == customer.Id
select p;
Expand All @@ -331,8 +328,7 @@ public virtual async Task<IList<ExternalAuthentication>> GetExternalIdentifiers(
/// <param name="externalAuthentication">External authentication</param>
public virtual async Task DeleteExternalAuthentication(ExternalAuthentication externalAuthentication)
{
if (externalAuthentication == null)
throw new ArgumentNullException(nameof(externalAuthentication));
ArgumentNullException.ThrowIfNull(externalAuthentication);

await _externalAuthenticationRecordRepository.DeleteAsync(externalAuthentication);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public virtual Task<BrandLayout> GetBrandLayoutById(string brandLayoutId)
/// <param name="brandLayout">Brand layout</param>
public virtual async Task InsertBrandLayout(BrandLayout brandLayout)
{
if (brandLayout == null)
throw new ArgumentNullException(nameof(brandLayout));
ArgumentNullException.ThrowIfNull(brandLayout);

await _brandLayoutRepository.InsertAsync(brandLayout);

Expand All @@ -92,8 +91,7 @@ public virtual async Task InsertBrandLayout(BrandLayout brandLayout)
/// <param name="brandLayout">Brand layout</param>
public virtual async Task UpdateBrandLayout(BrandLayout brandLayout)
{
if (brandLayout == null)
throw new ArgumentNullException(nameof(brandLayout));
ArgumentNullException.ThrowIfNull(brandLayout);

await _brandLayoutRepository.UpdateAsync(brandLayout);

Expand All @@ -110,8 +108,7 @@ public virtual async Task UpdateBrandLayout(BrandLayout brandLayout)
/// <param name="brandLayout">Brand layout</param>
public virtual async Task DeleteBrandLayout(BrandLayout brandLayout)
{
if (brandLayout == null)
throw new ArgumentNullException(nameof(brandLayout));
ArgumentNullException.ThrowIfNull(brandLayout);

await _brandLayoutRepository.DeleteAsync(brandLayout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ public virtual Task<Brand> GetBrandById(string brandId)
/// <param name="brand">Brand</param>
public virtual async Task InsertBrand(Brand brand)
{
if (brand == null)
throw new ArgumentNullException(nameof(brand));
ArgumentNullException.ThrowIfNull(brand);

await _brandRepository.InsertAsync(brand);

Expand All @@ -128,8 +127,7 @@ public virtual async Task InsertBrand(Brand brand)
/// <param name="brand">Brand</param>
public virtual async Task UpdateBrand(Brand brand)
{
if (brand == null)
throw new ArgumentNullException(nameof(brand));
ArgumentNullException.ThrowIfNull(brand);

await _brandRepository.UpdateAsync(brand);

Expand All @@ -145,8 +143,7 @@ public virtual async Task UpdateBrand(Brand brand)
/// <param name="brand">Brand</param>
public virtual async Task DeleteBrand(Brand brand)
{
if (brand == null)
throw new ArgumentNullException(nameof(brand));
ArgumentNullException.ThrowIfNull(brand);

await _cacheBase.RemoveByPrefix(CacheKey.BRANDS_PATTERN_KEY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public virtual Task<CategoryLayout> GetCategoryLayoutById(string categoryLayoutI
/// <param name="categoryLayout">Category layout</param>
public virtual async Task InsertCategoryLayout(CategoryLayout categoryLayout)
{
if (categoryLayout == null)
throw new ArgumentNullException(nameof(categoryLayout));
ArgumentNullException.ThrowIfNull(categoryLayout);

await _categoryLayoutRepository.InsertAsync(categoryLayout);

Expand All @@ -92,8 +91,7 @@ public virtual async Task InsertCategoryLayout(CategoryLayout categoryLayout)
/// <param name="categoryLayout">Category layout</param>
public virtual async Task UpdateCategoryLayout(CategoryLayout categoryLayout)
{
if (categoryLayout == null)
throw new ArgumentNullException(nameof(categoryLayout));
ArgumentNullException.ThrowIfNull(categoryLayout);

await _categoryLayoutRepository.UpdateAsync(categoryLayout);

Expand All @@ -110,8 +108,7 @@ public virtual async Task UpdateCategoryLayout(CategoryLayout categoryLayout)
/// <param name="categoryLayout">Category layout</param>
public virtual async Task DeleteCategoryLayout(CategoryLayout categoryLayout)
{
if (categoryLayout == null)
throw new ArgumentNullException(nameof(categoryLayout));
ArgumentNullException.ThrowIfNull(categoryLayout);

await _categoryLayoutRepository.DeleteAsync(categoryLayout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ public virtual async Task<Category> GetCategoryById(string categoryId)
/// <param name="category">Category</param>
public virtual async Task InsertCategory(Category category)
{
if (category == null)
throw new ArgumentNullException(nameof(category));
ArgumentNullException.ThrowIfNull(category);

await _categoryRepository.InsertAsync(category);

Expand All @@ -416,8 +415,7 @@ public virtual async Task InsertCategory(Category category)
/// <param name="category">Category</param>
public virtual async Task UpdateCategory(Category category)
{
if (category == null)
throw new ArgumentNullException(nameof(category));
ArgumentNullException.ThrowIfNull(category);
if (string.IsNullOrEmpty(category.ParentCategoryId))
category.ParentCategoryId = "";

Expand Down Expand Up @@ -448,8 +446,7 @@ public virtual async Task UpdateCategory(Category category)
/// <param name="category">Category</param>
public virtual async Task DeleteCategory(Category category)
{
if (category == null)
throw new ArgumentNullException(nameof(category));
ArgumentNullException.ThrowIfNull(category);

//reset a "Parent category" property of all child subcategories
var subcategories = await GetAllCategoriesByParentCategoryId(category.Id, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ orderby pm.DisplayOrder
/// <param name="productId">Product ident</param>
public virtual async Task InsertProductCategory(ProductCategory productCategory, string productId)
{
if (productCategory == null)
throw new ArgumentNullException(nameof(productCategory));
ArgumentNullException.ThrowIfNull(productCategory);

await _productRepository.AddToSet(productId, x => x.ProductCategories, productCategory);

Expand All @@ -123,8 +122,7 @@ public virtual async Task InsertProductCategory(ProductCategory productCategory,
/// <param name="productId">Product ident</param>
public virtual async Task UpdateProductCategory(ProductCategory productCategory, string productId)
{
if (productCategory == null)
throw new ArgumentNullException(nameof(productCategory));
ArgumentNullException.ThrowIfNull(productCategory);

await _productRepository.UpdateToSet(productId, x => x.ProductCategories, z => z.Id, productCategory.Id, productCategory);

Expand All @@ -142,8 +140,7 @@ public virtual async Task UpdateProductCategory(ProductCategory productCategory,
/// <param name="productId">Product ident</param>
public virtual async Task DeleteProductCategory(ProductCategory productCategory, string productId)
{
if (productCategory == null)
throw new ArgumentNullException(nameof(productCategory));
ArgumentNullException.ThrowIfNull(productCategory);

await _productRepository.PullFilter(productId, x => x.ProductCategories, z => z.Id, productCategory.Id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public virtual Task<CollectionLayout> GetCollectionLayoutById(string collectionL
/// <param name="collectionLayout">Collection layout</param>
public virtual async Task InsertCollectionLayout(CollectionLayout collectionLayout)
{
if (collectionLayout == null)
throw new ArgumentNullException(nameof(collectionLayout));
ArgumentNullException.ThrowIfNull(collectionLayout);

await _collectionLayoutRepository.InsertAsync(collectionLayout);

Expand All @@ -92,8 +91,7 @@ public virtual async Task InsertCollectionLayout(CollectionLayout collectionLayo
/// <param name="collectionLayout">Collection layout</param>
public virtual async Task UpdateCollectionLayout(CollectionLayout collectionLayout)
{
if (collectionLayout == null)
throw new ArgumentNullException(nameof(collectionLayout));
ArgumentNullException.ThrowIfNull(collectionLayout);

await _collectionLayoutRepository.UpdateAsync(collectionLayout);

Expand All @@ -110,8 +108,7 @@ public virtual async Task UpdateCollectionLayout(CollectionLayout collectionLayo
/// <param name="collectionLayout">Collection layout</param>
public virtual async Task DeleteCollectionLayout(CollectionLayout collectionLayout)
{
if (collectionLayout == null)
throw new ArgumentNullException(nameof(collectionLayout));
ArgumentNullException.ThrowIfNull(collectionLayout);

await _collectionLayoutRepository.DeleteAsync(collectionLayout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ public virtual Task<Collection> GetCollectionById(string collectionId)
/// <param name="collection">Collection</param>
public virtual async Task InsertCollection(Collection collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
ArgumentNullException.ThrowIfNull(collection);

await _collectionRepository.InsertAsync(collection);

Expand All @@ -155,8 +154,7 @@ public virtual async Task InsertCollection(Collection collection)
/// <param name="collection">Collection</param>
public virtual async Task UpdateCollection(Collection collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
ArgumentNullException.ThrowIfNull(collection);

await _collectionRepository.UpdateAsync(collection);

Expand All @@ -173,8 +171,7 @@ public virtual async Task UpdateCollection(Collection collection)
/// <param name="collection">Collection</param>
public virtual async Task DeleteCollection(Collection collection)
{
if (collection == null)
throw new ArgumentNullException(nameof(collection));
ArgumentNullException.ThrowIfNull(collection);

await _cacheBase.RemoveByPrefix(CacheKey.COLLECTIONS_PATTERN_KEY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ orderby pm.DisplayOrder
/// <param name="productId">Product ident</param>
public virtual async Task InsertProductCollection(ProductCollection productCollection, string productId)
{
if (productCollection == null)
throw new ArgumentNullException(nameof(productCollection));
ArgumentNullException.ThrowIfNull(productCollection);

await _productRepository.AddToSet(productId, x => x.ProductCollections, productCollection);

Expand All @@ -124,8 +123,7 @@ public virtual async Task InsertProductCollection(ProductCollection productColle
/// <param name="productId">Product id</param>
public virtual async Task UpdateProductCollection(ProductCollection productCollection, string productId)
{
if (productCollection == null)
throw new ArgumentNullException(nameof(productCollection));
ArgumentNullException.ThrowIfNull(productCollection);

await _productRepository.UpdateToSet(productId, x => x.ProductCollections, z => z.Id, productCollection.Id, productCollection);

Expand All @@ -144,8 +142,7 @@ public virtual async Task UpdateProductCollection(ProductCollection productColle
/// <param name="productId">Product id</param>
public virtual async Task DeleteProductCollection(ProductCollection productCollection, string productId)
{
if (productCollection == null)
throw new ArgumentNullException(nameof(productCollection));
ArgumentNullException.ThrowIfNull(productCollection);

await _productRepository.PullFilter(productId, x => x.ProductCollections, z => z.Id, productCollection.Id);

Expand Down
Loading

0 comments on commit b1a94ce

Please sign in to comment.