|
@@ -34,6 +34,10 @@ namespace Hotline.Api.Controllers
|
|
|
[HttpPut("add")]
|
|
|
public async Task<string> AddTemplate([FromBody] TemplateDto dto)
|
|
|
{
|
|
|
+ var data = await _messageTemplateRepository.GetAsync(p => p.Code == dto.Code, HttpContext.RequestAborted);
|
|
|
+ if (data != null)
|
|
|
+ throw UserFriendlyException.SameMessage("存在相同Code!");
|
|
|
+
|
|
|
var template = _mapper.Map<MessageTemplate>(dto);
|
|
|
|
|
|
Regex regex = new(@"\{[a-zA-Z0-9]{1,}\}");
|
|
@@ -47,10 +51,6 @@ namespace Hotline.Api.Controllers
|
|
|
list.Add(matches[i].ToString());
|
|
|
}
|
|
|
|
|
|
- var data = await _messageTemplateRepository.GetAsync(p => p.Code == template.Code, HttpContext.RequestAborted);
|
|
|
- if (data != null)
|
|
|
- throw UserFriendlyException.SameMessage("存在相同Code!");
|
|
|
-
|
|
|
return await _messageTemplateRepository.AddAsync(template, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
@@ -62,10 +62,16 @@ namespace Hotline.Api.Controllers
|
|
|
[HttpPut("update")]
|
|
|
public async Task UpdateTemplate([FromBody] UpdateTemplateDto dto)
|
|
|
{
|
|
|
- var template = _mapper.Map<MessageTemplate>(dto);
|
|
|
+ var model =await _messageTemplateRepository.GetAsync(dto.Id, HttpContext.RequestAborted);
|
|
|
+ if (model.Code!=dto.Code)
|
|
|
+ throw UserFriendlyException.SameMessage("不能修改编码");
|
|
|
+
|
|
|
+ _mapper.Map(dto,model);
|
|
|
+
|
|
|
+
|
|
|
|
|
|
Regex regex = new(@"\{[a-zA-Z0-9]{1,}\}");
|
|
|
- var matches = regex.Matches(template.Content);
|
|
|
+ var matches = regex.Matches(model.Content);
|
|
|
List<string> list = new List<string>();
|
|
|
for (int i = 0; i < matches.Count; i++)
|
|
|
{
|
|
@@ -75,23 +81,10 @@ namespace Hotline.Api.Controllers
|
|
|
list.Add(matches[i].ToString());
|
|
|
}
|
|
|
|
|
|
- var data = await _messageTemplateRepository.GetAsync(p => p.Code == template.Code && p.Id != template.Id, HttpContext.RequestAborted);
|
|
|
- if (data != null)
|
|
|
- throw UserFriendlyException.SameMessage("存在相同Code!");
|
|
|
-
|
|
|
- await _messageTemplateRepository.UpdateAsync(template, HttpContext.RequestAborted);
|
|
|
+ await _messageTemplateRepository.UpdateAsync(model, HttpContext.RequestAborted);
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 删除
|
|
|
- /// </summary>
|
|
|
- /// <param name="Id"></param>
|
|
|
- /// <returns></returns>
|
|
|
- [HttpDelete("remove")]
|
|
|
- public async Task RemoveType(string Id)
|
|
|
- {
|
|
|
- await _messageTemplateRepository.RemoveAsync(Id, false, HttpContext.RequestAborted);
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询详情
|
|
@@ -118,7 +111,7 @@ namespace Hotline.Api.Controllers
|
|
|
var (total, items) = await _messageTemplateRepository
|
|
|
.Queryable()
|
|
|
.WhereIF(!string.IsNullOrEmpty(pagedDto.Keyword), d => d.Code.Contains(pagedDto.Keyword!) || d.Content.Contains(pagedDto.Keyword!))
|
|
|
- .WhereIF(pagedDto.PushBusiness.HasValue, d => d.PushBusiness == pagedDto.PushBusiness)
|
|
|
+
|
|
|
.OrderByDescending(it => it.CreationTime)
|
|
|
.ToPagedListAsync(pagedDto.PageIndex, pagedDto.PageSize, HttpContext.RequestAborted);
|
|
|
|