Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Remove redundant else keyword

support75cc2ed46176
diff --git a/src/API/Grand.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs b/src/API/Grand.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs
index 9533ba484..6cb466070 100644
--- a/src/API/Grand.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs
+++ b/src/API/Grand.Api/Queries/Handlers/Common/GetGenericQueryHandler.cs
@@ -22,8 +22,7 @@ namespace Grand.Api.Queries.Handlers.Common
if (string.IsNullOrEmpty(request.Id))
return query;
- else
- return await Task.FromResult(query.Where(x => x.Id == request.Id));
+ return await Task.FromResult(query.Where(x => x.Id == request.Id));
}
}
diff --git a/src/Business/Grand.Business.Common/Utilities/PowerExcelMapper.cs b/src/Business/Grand.Business.Common/Utilities/PowerExcelMapper.cs
index a947d7eaa..6f8c8d6ef 100644
--- a/src/Business/Grand.Business.Common/Utilities/PowerExcelMapper.cs
+++ b/src/Business/Grand.Business.Common/Utilities/PowerExcelMapper.cs
@@ -276,12 +276,12 @@ namespace Grand.Business.Common.Utilities
{
return DataFormatter.FormatCellValue(cell);
}
- else if (cell.NumericCellValue < maxDate && DateUtil.IsCellDateFormatted(cell))
+
+ if (cell.NumericCellValue < maxDate && DateUtil.IsCellDateFormatted(cell))
{
return cell.DateCellValue;
}
- else
- return cell.NumericCellValue;
+ return cell.NumericCellValue;
case CellType.Formula:
return cell.CellFormula;
case CellType.Boolean:
@@ -294,8 +294,7 @@ namespace Grand.Business.Common.Utilities
default:
if (targetColumn.Json)
return JsonSerializer.Deserialize(cell.StringCellValue, targetColumn.PropertyType);
- else
- return cell.StringCellValue;
+ return cell.StringCellValue;
}
}
diff --git a/src/Core/Grand.Domain/Customers/CustomerExtensions.cs b/src/Core/Grand.Domain/Customers/CustomerExtensions.cs
index fbad82bd6..bae920fd0 100644
--- a/src/Core/Grand.Domain/Customers/CustomerExtensions.cs
+++ b/src/Core/Grand.Domain/Customers/CustomerExtensions.cs
@@ -152,14 +152,7 @@ namespace Grand.Domain.Customers
throw new ArgumentNullException(nameof(customer));
var existingCouponCodes = customer.GetUserFieldFromEntity<string>(key);
- if (string.IsNullOrEmpty(existingCouponCodes))
- {
- return couponCode;
- }
- else
- {
- return string.Join(CouponSeparator, existingCouponCodes.Split(CouponSeparator).Append(couponCode).Distinct());
- }
+ return string.IsNullOrEmpty(existingCouponCodes) ? couponCode : string.Join(CouponSeparator, existingCouponCodes.Split(CouponSeparator).Append(couponCode).Distinct());
}
/// <summary>
/// Adds a coupon codes
@@ -177,12 +170,10 @@ namespace Grand.Domain.Customers
{
return string.Join(CouponSeparator, couponCodes);
}
- else
- {
- var coupons = existingCouponCodes.Split(CouponSeparator).ToList();
- coupons.AddRange(couponCodes.ToList());
- return string.Join(CouponSeparator, coupons.Distinct());
- }
+
+ var coupons = existingCouponCodes.Split(CouponSeparator).ToList();
+ coupons.AddRange(couponCodes.ToList());
+ return string.Join(CouponSeparator, coupons.Distinct());
}
/// <summary>
/// Adds a coupon code
@@ -200,10 +191,8 @@ namespace Grand.Domain.Customers
{
return "";
}
- else
- {
- return string.Join(CouponSeparator, existingCouponCodes.Split(CouponSeparator).Except(new List<string> { couponCode }).Distinct());
- }
+
+ return string.Join(CouponSeparator, existingCouponCodes.Split(CouponSeparator).Except(new List<string> { couponCode }).Distinct());
}
/// <summary>
diff --git a/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs
index e7e42df32..521875f25 100644
--- a/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs
+++ b/src/Core/Grand.Domain/Data/Mongo/MongoDBContext.cs
@@ -75,10 +75,7 @@ namespace Grand.Domain.Data.Mongo
var filter = new BsonDocument("name", "GrandNodeVersion");
var found = database.ListCollectionsAsync(new ListCollectionsOptions { Filter = filter }).Result;
- if (found.Any())
- return true;
- else
- return false;
+ return await found.AnyAsync();
}
public async Task CreateTable(string name, string collation)
diff --git a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
index a8f968b54..49bd74f67 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
@@ -120,7 +120,7 @@ namespace Grand.Business.Customers.Tests.Extensions
.Returns(() =>
{
if (invokeNumber <= 2) return Task.FromResult(new Affiliate());
- else return Task.FromResult<Affiliate>(null);
+ return Task.FromResult<Affiliate>(null);
}).Callback(() => invokeNumber++);
var friendlyUrl = "macbool-pro";
diff --git a/src/Tests/Grand.Data.Tests/MongoDb/CoreTestConfiguration.cs b/src/Tests/Grand.Data.Tests/MongoDb/CoreTestConfiguration.cs
index c31990998..3519322e0 100644
--- a/src/Tests/Grand.Data.Tests/MongoDb/CoreTestConfiguration.cs
+++ b/src/Tests/Grand.Data.Tests/MongoDb/CoreTestConfiguration.cs
@@ -255,11 +255,9 @@ namespace Grand.Data.Tests.MongoDb
{
return collectionName;
}
- else
- {
- var maxCollectionNameLength = 123 - (databaseNamespace.DatabaseName.Length + 1);
- return collectionName.Substring(0, maxCollectionNameLength);
- }
+
+ var maxCollectionNameLength = 123 - (databaseNamespace.DatabaseName.Length + 1);
+ return collectionName.Substring(0, maxCollectionNameLength);
}
private static string TruncateDatabaseNameIfTooLong(string databaseName)
@@ -268,10 +266,8 @@ namespace Grand.Data.Tests.MongoDb
{
return databaseName;
}
- else
- {
- return databaseName.Substring(0, 63);
- }
+
+ return databaseName.Substring(0, 63);
}
#endregion
diff --git a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
index f08798316..244c50a7d 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CategoryController.cs
@@ -415,11 +415,9 @@ namespace Grand.Web.Admin.Controllers
return Content("");
}
- else
- {
- Error(ModelState);
- return View(model);
- }
+
+ Error(ModelState);
+ return View(model);
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs b/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
index c4c4427d3..7cf36dba2 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CollectionController.cs
@@ -459,11 +459,9 @@ namespace Grand.Web.Admin.Controllers
}
return Content("");
}
- else
- {
- Error(ModelState);
- return View(model);
- }
+
+ Error(ModelState);
+ return View(model);
}
#endregion
diff --git a/src/Web/Grand.Web.Admin/Controllers/PictureController.cs b/src/Web/Grand.Web.Admin/Controllers/PictureController.cs
index 336db4a39..a2c21d9ee 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PictureController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PictureController.cs
@@ -166,12 +166,12 @@ namespace Grand.Web.Admin.Controllers
imageUrl = fileName
});
}
- else
- return Json(new
- {
- success = false,
- message = "Physical path not exist"
- });
+
+ return Json(new
+ {
+ success = false,
+ message = "Physical path not exist"
+ });
}
catch (Exception ex)
{
@@ -182,7 +182,7 @@ namespace Grand.Web.Admin.Controllers
});
}
}
- else
+
{
var filepath = _mediaFileStore.GetDirectoryInfo("");
if (filepath != null)
@@ -197,12 +197,12 @@ namespace Grand.Web.Admin.Controllers
imageUrl = fileName
});
}
- else
- return Json(new
- {
- success = false,
- message = "Physical path not exist"
- });
+
+ return Json(new
+ {
+ success = false,
+ message = "Physical path not exist"
+ });
}
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs b/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
index 3a4cb3e0f..e2bf53907 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PluginController.cs
@@ -436,27 +436,25 @@ namespace Grand.Web.Admin.Controllers
}
if (!supportedVersion)
throw new Exception($"This plugin doesn't support the current version - {GrandVersion.SupportedPluginVersion}");
- else
- {
- var pluginname = _fpath[(_fpath.LastIndexOf('/') + 1)..];
- var _path = "";
+
+ var pluginname = _fpath[(_fpath.LastIndexOf('/') + 1)..];
+ var _path = "";
- var entries = archive.Entries.ToArray();
- foreach (var y in entries)
- {
- if (y.Name.Length > 0)
- _path = y.FullName.Replace(y.Name, "").Replace(_fpath, pluginname).TrimEnd('/');
- else
- _path = y.FullName.Replace(_fpath, pluginname);
+ var entries = archive.Entries.ToArray();
+ foreach (var y in entries)
+ {
+ if (y.Name.Length > 0)
+ _path = y.FullName.Replace(y.Name, "").Replace(_fpath, pluginname).TrimEnd('/');
+ else
+ _path = y.FullName.Replace(_fpath, pluginname);
- var _entry = archive.CreateEntry($"{_path}/{y.Name}");
- using (var a = y.Open())
- using (var b = _entry.Open())
- a.CopyTo(b);
+ var _entry = archive.CreateEntry($"{_path}/{y.Name}");
+ using (var a = y.Open())
+ using (var b = _entry.Open())
+ a.CopyTo(b);
- archive.GetEntry(y.FullName).Delete();
+ archive.GetEntry(y.FullName).Delete();
- }
}
}
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
index 8ff6e029b..482683fed 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
@@ -139,8 +139,7 @@ namespace Grand.Web.Admin.Controllers
{
if (!product.LimitedToStores || (product.Stores.Contains(_workContext.CurrentCustomer.StaffStoreId) && product.LimitedToStores))
return RedirectToAction("Edit", new { id = product.Id });
- else
- return RedirectToAction("List", "Product");
+ return RedirectToAction("List", "Product");
}
return RedirectToAction("Edit", "Product", new { id = product.Id });
@@ -655,13 +654,11 @@ namespace Grand.Web.Admin.Controllers
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareRelatedProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareRelatedProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -758,13 +755,11 @@ namespace Grand.Web.Admin.Controllers
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareSimilarProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareSimilarProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -862,13 +857,11 @@ namespace Grand.Web.Admin.Controllers
model.IsLoggedInAsVendor = _workContext.CurrentVendor != null;
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareBundleProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareBundleProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -957,13 +950,11 @@ namespace Grand.Web.Admin.Controllers
}
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareCrossSellProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareCrossSellProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -1051,13 +1042,11 @@ namespace Grand.Web.Admin.Controllers
}
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareRecommendedProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareRecommendedProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -1166,13 +1155,11 @@ namespace Grand.Web.Admin.Controllers
}
return Content("");
}
- else
- {
- Error(ModelState);
- model = await _productViewModelService.PrepareAssociatedProductModel();
- model.ProductId = model.ProductId;
- return View(model);
- }
+
+ Error(ModelState);
+ model = await _productViewModelService.PrepareAssociatedProductModel();
+ model.ProductId = model.ProductId;
+ return View(model);
}
#endregion
@@ -1826,13 +1813,11 @@ namespace Grand.Web.Admin.Controllers
return Content("");
}
- else
- {
- Error(ModelState);
- //If we got this far, something failed, redisplay form
- await _productViewModelService.PrepareTierPriceModel(model);
- return View(model);
- }
+
+ Error(ModelState);
+ //If we got this far, something failed, redisplay form
+ await _productViewModelService.PrepareTierPriceModel(model);
+ return View(model);
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
@@ -2882,8 +2867,8 @@ namespace Grand.Web.Admin.Controllers
await _auctionService.DeleteBid(toDelete);
return Json("");
}
- else
- return Json(new DataSourceResult { Errors = _translationService.GetResource("Admin.Catalog.Products.Bids.CantDeleteWithOrder") });
+
+ return Json(new DataSourceResult { Errors = _translationService.GetResource("Admin.Catalog.Products.Bids.CantDeleteWithOrder") });
}
return Json(new DataSourceResult { Errors = "Bid not exists" });
}
diff --git a/src/Web/Grand.Web.Admin/Extensions/AllowedFileExtensions.cs b/src/Web/Grand.Web.Admin/Extensions/AllowedFileExtensions.cs
index c482be3d8..3f77b9922 100644
--- a/src/Web/Grand.Web.Admin/Extensions/AllowedFileExtensions.cs
+++ b/src/Web/Grand.Web.Admin/Extensions/AllowedFileExtensions.cs
@@ -6,8 +6,7 @@
{
if (string.IsNullOrEmpty(allowedFileTypes))
return new List<string> { ".gif", ".jpg", ".jpeg", ".png", ".bmp", ".webp" };
- else
- return allowedFileTypes.Split(',').Select(x => x.Trim().ToLowerInvariant()).ToList();
+ return allowedFileTypes.Split(',').Select(x => x.Trim().ToLowerInvariant()).ToList();
}
}
}
diff --git a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ExpressionMetadataProvider.cs b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ExpressionMetadataProvider.cs
index 6cbf54f03..96686d54d 100644
--- a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ExpressionMetadataProvider.cs
+++ b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ExpressionMetadataProvider.cs
@@ -181,7 +181,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Func<object, object> modelAccessor = (ignore) => viewDataInfo.Value;
return containerExplorer.GetExplorerForExpression(propertyMetadata, modelAccessor);
}
- else if (viewDataInfo.Value != null)
+
+ if (viewDataInfo.Value != null)
{
// We have a value, even though we may not know where it came from.
var valueMetadata = metadataProvider.GetMetadataForType(viewDataInfo.Value.GetType());
@@ -209,10 +210,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
var model = viewData.Model == null ? null : Convert.ToString(viewData.Model, CultureInfo.CurrentCulture);
return metadataProvider.GetModelExplorerForType(typeof(string), model);
}
- else
- {
- return viewData.ModelExplorer;
- }
+
+ return viewData.ModelExplorer;
}
}
}
diff --git a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/TemplateRenderer.cs b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/TemplateRenderer.cs
index 88cf5ab44..5be57f015 100644
--- a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/TemplateRenderer.cs
+++ b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/TemplateRenderer.cs
@@ -195,7 +195,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
// Nothing more to provide
yield break;
}
- else if (!modelMetadata.IsComplexType)
+
+ if (!modelMetadata.IsComplexType)
{
// IsEnum is false for the Enum class itself
if (fieldTypeInfo.IsEnum)
@@ -211,7 +212,7 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
yield return "String";
yield break;
}
- else if (!fieldTypeInfo.IsInterface)
+ if (!fieldTypeInfo.IsInterface)
{
var type = fieldType;
while (true)
diff --git a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ViewBufferTextWriter.cs b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ViewBufferTextWriter.cs
index 531dc8700..efcc02efe 100644
--- a/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ViewBufferTextWriter.cs
+++ b/src/Web/Grand.Web.Common/TagHelpers/Admin/Extend/ViewBufferTextWriter.cs
@@ -236,10 +236,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(value.ToString());
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteAsync(value);
- }
+
+ return _inner.WriteAsync(value);
}
/// <inheritdoc />
@@ -264,10 +262,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(new string(buffer, index, count));
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteAsync(buffer, index, count);
- }
+
+ return _inner.WriteAsync(buffer, index, count);
}
/// <inheritdoc />
@@ -278,10 +274,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(value);
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteAsync(value);
- }
+
+ return _inner.WriteAsync(value);
}
/// <inheritdoc />
@@ -320,10 +314,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(NewLine);
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteLineAsync(value);
- }
+
+ return _inner.WriteLineAsync(value);
}
/// <inheritdoc />
@@ -335,10 +327,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(NewLine);
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteLineAsync(value, start, offset);
- }
+
+ return _inner.WriteLineAsync(value, start, offset);
}
/// <inheritdoc />
@@ -350,10 +340,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(NewLine);
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteLineAsync(value);
- }
+
+ return _inner.WriteLineAsync(value);
}
/// <inheritdoc />
@@ -364,10 +352,8 @@ namespace Grand.Web.Common.TagHelpers.Admin.Extend
Buffer.AppendHtml(NewLine);
return Task.CompletedTask;
}
- else
- {
- return _inner.WriteLineAsync();
- }
+
+ return _inner.WriteLineAsync();
}
/// <summary>