Exemplo n.º 1
0
        /// <summary>
        /// 对实体中的字符进行截取
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private LanguageDetailRequestModel SubStrInModel(LanguageDetailRequestModel model)
        {
            model.Code = SubString(model.Code, PrintPropertyValue <Language>("Code"));
            model.Desc = SubString(model.Desc, PrintPropertyValue <Language>("Desc"));
            model.En   = SubString(model.En, PrintPropertyValue <Language>("En"));
            model.Zh   = SubString(model.Zh, PrintPropertyValue <Language>("Zh"));
            model.Ko   = SubString(model.Ko, PrintPropertyValue <Language>("Ko"));

            return(model);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 增
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public ExcutedResult InsertLanguage(LanguageDetailRequestModel model)
 {
     try
     {
         if (model == null)
         {
             throw new BusinessException(BusinessResultCode.ArgumentError, "参数错误或无效");
         }
         model.Verify();
         Language data = Repository.GetLanguageByTypeAndCode(model.Code, model.Type);
         if (data != null)
         {
             throw new BusinessException(BusinessResultCode.DataExist, " 数据已存在");
         }
         model = SubStrInModel(model);
         Language language = new Language()
         {
             Id         = Guid.NewGuid(),
             Type       = model.Type,
             Code       = model.Code,
             CreateTime = DateTime.UtcNow,
             Desc       = model.Desc,
             En         = string.IsNullOrEmpty(model.En) ? string.Empty : model.En,
             Ko         = string.IsNullOrEmpty(model.Ko) ? string.Empty : model.Ko,
             Zh         = model.Zh
         };
         Create(language, out var result);
         return(result);
     }
     catch (BusinessException businessException)
     {
         return(ExcutedResult.FailedResult(businessException.ErrorCode,
                                           GetDescribe(businessException.ErrorCode, EnumLanguageDataType.BusinessResultCode)));
     }
     catch (Exception exception)
     {
         return(ExcutedResult.FailedResult(SysResultCode.ServerException,
                                           GetDescribe(SysResultCode.ServerException, EnumLanguageDataType.BusinessResultCode)));
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ExcutedResult EditLanguage(LanguageDetailRequestModel model)
        {
            try
            {
                if (model == null)
                {
                    throw new BusinessException(BusinessResultCode.ArgumentError, "参数错误或无效");
                }
                model.Verify();
                model = SubStrInModel(model);
                Guid id = Guid.Empty;
                if (string.IsNullOrEmpty(model.Guid) || !Guid.TryParse(model.Guid, out id))
                {
                    throw new BusinessException(BusinessResultCode.ArgumentError, "参数错误或无效");
                }
                Language language = base.GetById(id);
                if (language == null)
                {
                    throw new BusinessException(BusinessResultCode.DataNotExist, "数据不存在,请刷新!");
                }

                string originalValue = JsonConvert.SerializeObject(language);
                //如果需要更改类型或者类型
                if (model.Type != language.Type && model.Code != language.Code)
                {
                    Language data = Repository.GetLanguageByTypeAndCode(model.Code, model.Type);
                    if (data != null)
                    {
                        throw new BusinessException(BusinessResultCode.DataExist, " 数据已存在");
                    }
                    language.Code = model.Code;
                    language.Type = model.Type;
                }
                else if (model.Type != language.Type)
                {
                    Language data = Repository.GetLanguageByTypeAndCode(language.Code, model.Type);
                    if (data != null)
                    {
                        throw new BusinessException(BusinessResultCode.DataExist, " 数据已存在");
                    }
                    language.Type = model.Type;
                }
                else if (model.Code != language.Code)
                {
                    Language data = Repository.GetLanguageByTypeAndCode(model.Code, language.Type);
                    if (data != null)
                    {
                        throw new BusinessException(BusinessResultCode.DataExist, " 数据已存在");
                    }
                    language.Code = model.Code;
                }
                if (model.Desc != language.Desc)
                {
                    language.Desc = model.Desc;
                }
                language.Zh = model.Zh;
                language.En = model.En;
                language.Ko = model.Ko;

                string newValue = JsonConvert.SerializeObject(language);
                base.Update(language, out var result);
                OperateLog log = new OperateLog()
                {
                    Id             = Guid.NewGuid(),
                    ClientIp       = CurrentUser.ClientIP,
                    CreateTime     = DateTime.Now,
                    ManagerAccount = CurrentUser.UserName,
                    ManagerId      = CurrentUser.Id,
                    Function       = "语言管理",
                    OriginalValue  = originalValue,
                    NewValue       = newValue,
                    Operate        = "Update",
                };
                _operateLogRepository.Insert(log);
                return(result);
            }
            catch (BusinessException businessException)
            {
                return(ExcutedResult.FailedResult(businessException.ErrorCode,
                                                  GetDescribe(businessException.ErrorCode, EnumLanguageDataType.BusinessResultCode)));
            }
            catch (Exception exception)
            {
                return(ExcutedResult.FailedResult(SysResultCode.ServerException,
                                                  GetDescribe(SysResultCode.ServerException, EnumLanguageDataType.BusinessResultCode)));
            }
        }
Exemplo n.º 4
0
 public ExcutedResult EditLanguage([FromBody] LanguageDetailRequestModel model)
 {
     return(_LanguageLogic.EditLanguage(model));
 }