chore
This commit is contained in:
@@ -3,6 +3,7 @@ using Atomx.Admin.Services;
|
||||
using Atomx.Common.Constants;
|
||||
using Atomx.Common.Entities;
|
||||
using Atomx.Common.Models;
|
||||
using Atomx.Core.Jos;
|
||||
using Atomx.Data;
|
||||
using Atomx.Data.CacheServices;
|
||||
using Atomx.Data.Services;
|
||||
@@ -29,6 +30,7 @@ namespace Atomx.Admin.Controllers
|
||||
private readonly IIdentityService _identityService;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly IBackgroundJobService _backgroundService;
|
||||
readonly IValidator<AreaModel> _validator;
|
||||
readonly IStringLocalizer<AreaController> _localizer;
|
||||
|
||||
@@ -40,9 +42,12 @@ namespace Atomx.Admin.Controllers
|
||||
/// <param name="identityService"></param>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="mapper"></param>
|
||||
/// <param name="jwtSettings"></param>
|
||||
/// <param name="cacheService"></param>
|
||||
public AreaController(ILogger<AreaController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper, ICacheService cacheService, IValidator<AreaModel> validator, IStringLocalizer<AreaController> localizer)
|
||||
/// <param name="backgroundJobService"></param>
|
||||
/// <param name="validator"></param>
|
||||
/// <param name="localizer"></param>
|
||||
public AreaController(ILogger<AreaController> logger, IIdCreatorService idCreator, IIdentityService identityService, DataContext dbContext, IMapper mapper,
|
||||
ICacheService cacheService, IBackgroundJobService backgroundJobService, IValidator<AreaModel> validator, IStringLocalizer<AreaController> localizer)
|
||||
{
|
||||
_logger = logger;
|
||||
_idCreator = idCreator;
|
||||
@@ -50,6 +55,7 @@ namespace Atomx.Admin.Controllers
|
||||
_dbContext = dbContext;
|
||||
_mapper = mapper;
|
||||
_cacheService = cacheService;
|
||||
_backgroundService = backgroundJobService;
|
||||
_validator = validator;
|
||||
_localizer = localizer;
|
||||
}
|
||||
@@ -112,7 +118,7 @@ namespace Atomx.Admin.Controllers
|
||||
countries = _dbContext.Countries.Where(p => countryIds.Contains(p.Id)).ToList();
|
||||
}
|
||||
|
||||
if(search.StateProvinceId > 0)
|
||||
if (search.StateProvinceId > 0)
|
||||
{
|
||||
var state = _dbContext.StateProvinces.SingleOrDefault(p => p.Id == search.StateProvinceId);
|
||||
if (state != null)
|
||||
@@ -213,6 +219,8 @@ namespace Atomx.Admin.Controllers
|
||||
}
|
||||
if (model.Id > 0)
|
||||
{
|
||||
|
||||
|
||||
data = _dbContext.Areas.SingleOrDefault(p => p.Id == model.Id);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -221,6 +229,18 @@ namespace Atomx.Admin.Controllers
|
||||
|
||||
data = _mapper.Map(model, data);
|
||||
|
||||
var parent = _dbContext.Categories.Where(p => p.Id == model.ParentId).SingleOrDefault();
|
||||
if (parent == null)
|
||||
{
|
||||
data.Depth = 0;
|
||||
data.Path = model.Id.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Depth = parent.Depth + 1;
|
||||
data.Path = $"{parent.Path},{data.Id}";
|
||||
}
|
||||
|
||||
_dbContext.SaveChanges();
|
||||
|
||||
}
|
||||
@@ -229,10 +249,25 @@ namespace Atomx.Admin.Controllers
|
||||
data = _mapper.Map<Area>(model);
|
||||
data.Id = _idCreator.CreateId();
|
||||
|
||||
var parent = _dbContext.Categories.Where(p => p.Id == data.ParentId).SingleOrDefault();
|
||||
if (parent == null)
|
||||
{
|
||||
data.Depth = 0;
|
||||
data.Path = data.Id.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Depth = parent.Depth + 1;
|
||||
data.Path = $"{parent.Path},{data.Id}";
|
||||
}
|
||||
|
||||
_dbContext.Areas.Add(data);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
_backgroundService.ResetStateProvinceAndAreaTree(model.CountryId);
|
||||
|
||||
|
||||
return new JsonResult(new ApiResult<string>().IsSuccess("操作成功"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user