Ejemplo n.º 1
0
        public async Task <AppSrvResult <long> > CreateAsync(DictCreationDto input)
        {
            var exists = (await _cacheService.GetAllDictsFromCacheAsync()).Exists(x => x.Name.EqualsIgnoreCase(input.Name));

            if (exists)
            {
                return(Problem(HttpStatusCode.BadRequest, "字典名字已经存在"));
            }

            var  dists = new List <SysDict>();
            long id    = IdGenerater.GetNextId();
            //var subDicts = GetSubDicts(id, input.DictValues);
            var dict = new SysDict {
                Id = id, Name = input.Name, Value = input.Value, Ordinal = input.Ordinal, Pid = 0
            };

            dists.Add(dict);
            input.Children?.ForEach(x =>
            {
                dists.Add(new SysDict
                {
                    Id      = IdGenerater.GetNextId(),
                    Pid     = id,
                    Name    = x.Name,
                    Value   = x.Value,
                    Ordinal = x.Ordinal
                });
            });

            await _dictRepository.InsertRangeAsync(dists);

            return(id);
        }
Ejemplo n.º 2
0
    public async Task <AppSrvResult <long> > CreateAsync(DictCreationDto input)
    {
        var exists = await _dictRepository.AnyAsync(x => x.Name.Equals(input.Name.Trim()));

        if (exists)
        {
            return(Problem(HttpStatusCode.BadRequest, "字典名字已经存在"));
        }

        var  dists = new List <SysDict>();
        long id    = IdGenerater.GetNextId();
        var  dict  = new SysDict {
            Id = id, Name = input.Name, Value = input.Value, Ordinal = input.Ordinal, Pid = 0
        };

        dists.Add(dict);
        input.Children?.ForEach(x =>
        {
            dists.Add(new SysDict
            {
                Id      = IdGenerater.GetNextId(),
                Pid     = id,
                Name    = x.Name,
                Value   = x.Value,
                Ordinal = x.Ordinal
            });
        });

        var cacheKey    = _cacheService.ConcatCacheKey(CachingConsts.DictSingleKeyPrefix, id);
        var cahceBf     = _bloomFilterFactory.Create(CachingConsts.BloomfilterOfCacheKey);
        var addedStatus = await cahceBf.AddAsync(cacheKey);

        if (!addedStatus)
        {
            return(Problem(HttpStatusCode.BadRequest, "添加到布隆过滤器失败!"));
        }
        else
        {
            await _dictRepository.InsertRangeAsync(dists);
        }
        return(id);
    }
Ejemplo n.º 3
0
 public async Task <ActionResult <long> > CreateAsync([FromBody] DictCreationDto input)
 {
     return(CreatedResult(await _dictAppService.CreateAsync(input)));
 }