fix currency api
This commit is contained in:
@@ -120,7 +120,7 @@
|
|||||||
result = await HttpService.Post<ApiResult<string>>(url, model);
|
result = await HttpService.Post<ApiResult<string>>(url, model);
|
||||||
|
|
||||||
|
|
||||||
if (result.Code == (int)ResultCode.Success)
|
if (result.Success)
|
||||||
{
|
{
|
||||||
saving = false;
|
saving = false;
|
||||||
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
|
await ModalService.InfoAsync(new ConfirmOptions() { Title = "提示", Content = "数据提交成功!" });
|
||||||
|
|||||||
@@ -162,10 +162,10 @@ namespace Atomx.Admin.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("detail")]
|
[HttpGet("{id:long}")]
|
||||||
public IActionResult Get(long id)
|
public IActionResult Get(long id)
|
||||||
{
|
{
|
||||||
var result = new ApiResult<CurrencyModel>();
|
var result = new ApiResult<Currency>();
|
||||||
|
|
||||||
var data = _dbContext.Currencies.SingleOrDefault(p => p.Id == id);
|
var data = _dbContext.Currencies.SingleOrDefault(p => p.Id == id);
|
||||||
if (data == null)
|
if (data == null)
|
||||||
@@ -173,11 +173,7 @@ namespace Atomx.Admin.Controllers
|
|||||||
return new JsonResult(result);
|
return new JsonResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
var currency = _mapper.Map<CurrencyModel>(data);
|
return new JsonResult(new ApiResult<Currency>().IsSuccess(data));
|
||||||
|
|
||||||
result.Data = currency;
|
|
||||||
|
|
||||||
return new JsonResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -192,14 +188,13 @@ namespace Atomx.Admin.Controllers
|
|||||||
var validation = _validator.Validate(model);
|
var validation = _validator.Validate(model);
|
||||||
if (!validation.IsValid)
|
if (!validation.IsValid)
|
||||||
{
|
{
|
||||||
result = result.IsFail(ModelState.Values.First().Errors[0].ErrorMessage);
|
var message = validation.Errors.FirstOrDefault()?.ErrorMessage ?? string.Empty;
|
||||||
return new JsonResult(result);
|
return new JsonResult(new ApiResult<string>().IsFail(message, null));
|
||||||
}
|
}
|
||||||
var data = _dbContext.Currencies.SingleOrDefault(p => p.Id != model.Id && p.CurrencyCode == model.CurrencyCode);
|
var data = _dbContext.Currencies.SingleOrDefault(p => p.Id != model.Id && p.CurrencyCode == model.CurrencyCode);
|
||||||
if (data != null)
|
if (data != null)
|
||||||
{
|
{
|
||||||
result = result.IsFail("该货币代码数据已经存在,请更换!");
|
return new JsonResult(new ApiResult<string>().IsFail("该货币代码数据已经存在,请更换!", null));
|
||||||
return new JsonResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.Id.HasValue && model.Id > 0)
|
if (model.Id.HasValue && model.Id > 0)
|
||||||
@@ -218,21 +213,6 @@ namespace Atomx.Admin.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//var data = new Currency()
|
|
||||||
//{
|
|
||||||
// Name = model.Name,
|
|
||||||
// CurrencyCode = model.CurrencyCode,
|
|
||||||
// DisplayLocale = model.DisplayLocale,
|
|
||||||
// CustomFormatting = model.CustomFormatting,
|
|
||||||
// Rate = (decimal)model.Rate,
|
|
||||||
// DisplayOrder = model.DisplayOrder,
|
|
||||||
// EnableDisplay = model.Enabled,
|
|
||||||
// Symbolic = "",
|
|
||||||
// Enabled = model.Enabled,
|
|
||||||
// Title = model.Name,
|
|
||||||
// EnablePay = true,
|
|
||||||
// CreateTime = DateTime.UtcNow
|
|
||||||
//};
|
|
||||||
data = model.Adapt<Currency>();
|
data = model.Adapt<Currency>();
|
||||||
data.CreateTime = DateTime.UtcNow;
|
data.CreateTime = DateTime.UtcNow;
|
||||||
|
|
||||||
@@ -240,11 +220,8 @@ namespace Atomx.Admin.Controllers
|
|||||||
_dbContext.SaveChanges();
|
_dbContext.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result.IsSuccess(true);
|
|
||||||
|
|
||||||
//todo 更新缓存
|
//todo 更新缓存
|
||||||
|
return new JsonResult(new ApiResult<string>().IsSuccess("操作成功"));
|
||||||
return new JsonResult(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user