コード例 #1
0
        public async Task <Dictionary> Handle(AddDictionaryCommand request, CancellationToken cancellationToken)
        {
            var dictionaryDomain = new Model.Dictionary(request.Name, request.DictionaryKey);

            dictionaryDomain.Validate();

            #region Persistence

            var dictionary = dictionaryDomain.ToModel <Command.Dictionary>(_Mapper);

            await _DictionaryRepository.Add(dictionary);

            await _UnitOfWork.Commit();

            #endregion

            #region Bus

            var publishMessage = new Message();
            publishMessage.MessageType = "AddDictionary";
            var response = dictionaryDomain.ToQueryModel <Query.Dictionary>(_Mapper);
            publishMessage.SetData(response);

            await _Bus.SendMessage(publishMessage);

            #endregion

            return(response);
        }
コード例 #2
0
 public Messages Save(DictionaryEntity model)
 {
     if (model != null && model.D_NAME.IsNotNullOrEmpty())
     {
         model.D_REMARK = model.D_REMARK ?? "";
         int result = 0;
         if (model.D_ID > 0)
         {
             result = dicRepository.Modify(model);
         }
         else
         {
             result = dicRepository.Add(model);
         }
         if (result > 0)
         {
             messages.Msg     = "提交成功!!";
             messages.Success = true;
         }
         else if (result == -10000)
         {
             messages.Msg = "同级字典存在相同的数据";
         }
         else
         {
             messages.Msg = "提交失败!!";
         }
     }
     else
     {
         messages.Msg = "请填写必填字段信息";
     }
     return(messages);
 }
コード例 #3
0
        public async Task <Message> PostDic([FromBody] DictionaryCreation dictionaryCreation)
        {
            if (dictionaryCreation == null)
            {
                return(Message.Fail());
            }
            var dbitem = await _dictionaryRepository.GetSingleAsync(x => x.DictionaryName == dictionaryCreation.DictionaryName || x.DictionaryCode == dictionaryCreation.DictionaryCode);

            if (dbitem != null)
            {
                return(Message.Fail().Add("content", "字典码或字典名重复"));
            }
            dictionaryCreation.DictionaryId = Method.GetGuid32();
            // dictionaryCreation.DictionaryOrderNum = await _dictionaryRepository.OrderNumAsync(dictionaryCreation.ParentDictionaryCode);

            var newItem = _mapper.Map <TbDictionary>(dictionaryCreation);

            _dictionaryRepository.Add(newItem);

            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }
コード例 #4
0
        public AjaxResult Save(Dictionary old, Dictionary dic)
        {
            bool addFlag = dic.ID < 1;
            var  user    = log.User;

            dic.CREATEBY   = user.ACCOUNT;
            dic.CREATEDATE = DateTime.Now;
            dic.UPDATEBY   = user.ACCOUNT;
            dic.UPDATEDATE = DateTime.Now;
            dic.ENABLED    = true;

            if (addFlag)
            {
                int        dicId = dicRep.Add <int>(dic);
                bool       flag  = dicId > 0;
                ActionType type  = ActionType.SYS_ADD;
                string     msg   = WebConst.GetActionMsg(type, flag);
                log.Append(msg);
                log.AppendLine();
                log.AppendAdd("字典类型", dic.TYPE.ToString()).AppendAdd("字典编码", dic.CODE).AppendAdd("文本", dic.TEXT).AppendAdd("值", dic.VALUE);
                log.AddSystem(type, dicId);
                if (flag)
                {
                    RemoveCache();
                }
                return(new AjaxResult(flag, msg));
            }
            else
            {
                bool flag = dicRep.Update(dic, m => new
                {
                    m.TYPE,
                    m.TEXT,
                    m.CODE,
                    m.VALUE,
                    m.REMARK,
                    m.ENABLED,
                    m.SORTID,
                    m.UPDATEBY,
                    m.UPDATEDATE
                }, m => m.ID == dic.ID);
                ActionType type = ActionType.SYS_UPDATE;
                string     msg  = WebConst.GetActionMsg(type, flag);
                log.Append(msg);
                log.AppendLine();
                log.AppendUpdate("字典类型", old.TYPE.ToString(), dic.TYPE.ToString()).AppendUpdate("字典编码", old.CODE, dic.CODE).AppendUpdate("文本", old.TEXT, dic.TEXT).AppendUpdate("值", old.VALUE, dic.VALUE);
                log.AddSystem(type, dic.ID);
                if (flag)
                {
                    RemoveCache();
                }
                return(new AjaxResult(flag, msg));
            }
        }
コード例 #5
0
        /// <summary>
        /// The Save
        /// </summary>
        /// <param name="entity">The entity<see cref="Dictionary"/></param>
        /// <returns>The <see cref="ServiceResult"/></returns>
        public ServiceResult Save(Dictionary entity)
        {
            try
            {
                if (entity.Identifier == 0)
                {
                    _repository.Add(entity);
                }
                else
                {
                    _repository.Update(entity);
                }

                return(new ServiceResult(true));
            }
            catch (Exception ex)
            {
                return(new ServiceResult(false)
                {
                    Error = ex.ToString()
                });
            }
        }
コード例 #6
0
 public bool AddEntity(DictionaryEntity entity)
 {
     return(_dictionaryRepository.Add(entity));
 }