Exemple #1
0
        public async Task <IResultModel> Add(DictAddModel model)
        {
            var entity = _mapper.Map <DictEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Exemple #2
0
        public async Task <IResultModel> Add(DictAddModel model)
        {
            var entity = _mapper.Map <DictEntity>(model);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.HasExists);
            }

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Success(result));
        }
        public async Task <ApiResult> AddAsync(SubmitDTO <DictDTO> model)
        {
            var dto = model.Data;

            //参数校验
            if (!dto.IsValid(out string exMsg))
            {
                return(ApiResultUtil.IsFailed(exMsg));
            }

            //转换为数据库实体
            DictDO dictDO = this.ObjectMapper.Map <DictDO>(dto);

            long newId = await this.GrainFactory.GetGrain <IUtcUID>(GrainIdKey.UtcUIDGrainKey).NewLongID();

            dictDO.Id         = newId;
            dictDO.IsDel      = 0;
            dictDO.Version    = 1;
            dictDO.CreateBy   = model.UserId;
            dictDO.CreateDate = System.DateTime.Now;
            dictDO.ModityBy   = model.UserId;
            dictDO.ModityDate = System.DateTime.Now;

            string attribute = System.Guid.NewGuid().ToString();

            //测试先去掉数据写数
            //await PublishAsync(new TestModel
            //{
            //    Id = System.Guid.NewGuid().ToString(),
            //    CreateDate = System.DateTime.Now,
            //    Attribute01 = attribute,
            //    Attribute02 = attribute,
            //    Attribute03 = attribute,
            //    Attribute04 = attribute,
            //    Attribute05 = attribute,
            //    Attribute06 = attribute,
            //    Attribute07 = attribute,
            //    Attribute08 = attribute,
            //    Attribute09 = attribute,
            //    Attribute10 = attribute,
            //    Attribute11 = attribute,
            //    Attribute12 = attribute,
            //    Attribute13 = attribute
            //});

            bool bRet = await _dictRepository.AddAsync(dictDO);

            if (!bRet)
            {
                return(ApiResultUtil.IsFailed("数据插入失败!"));
            }

            if (this.GrainId != "TY22")
            {
                var client = _httpClientFactory.CreateClient();
                client.BaseAddress = new Uri("http://127.0.0.1:6114");
                Dictionary <string, string> postForm = new Dictionary <string, string>
                {
                    { "Data.DataType", "TY22" },
                    { "Data.DataCode", "A001" },
                    { "Data.DataValue", "V001" },
                    { "Data.DataDesc", "测试" },
                    { "Data.SortNo", "1" },
                    { "Data.Firm", "YT001" }
                };
                var task = await client.PostKanekoAsync("/BasicData/api/Dict/add", "", null, postForm);
            }

            //更新服务状态
            DictState scheduleTaskState = this.State;

            scheduleTaskState.Balance.Add(dictDO);

            await this.Persist(ProcessAction.Create, scheduleTaskState);

            return(ApiResultUtil.IsSuccess(newId.ToString()));
        }