public async Task <IResultModel> Add(OrganizeAddModel model) { if (await _organizeRepository.ExistsAsync(m => (m.OrganizeCode == model.OrganizeCode || m.OrganizeName == model.OrganizeName) && m.IsDel == false)) { return(ResultModel.HasExists); } var entity = _mapper.Map <OrganizeEntity>(model); if (entity.ParentId == Guid.Empty.ToString("N")) { entity.OrganizeFullName = $"{entity.OrganizeName}"; } else { var parent = await _organizeRepository.FirstAsync(m => m.Id == entity.ParentId); if (parent != null) { entity.Level = parent.Level + 1; entity.OrganizeFullName = $"{parent.OrganizeFullName}/{entity.OrganizeName}"; } } var result = await _organizeRepository.InsertAsync(entity); if (result) { return(ResultModel.Success(entity)); } return(ResultModel.Failed()); }
public Task <IResultModel> Add(OrganizeAddModel model) { return(_service.Add(model)); }