Esempio n. 1
0
        public async Task <BaseResult> AddOrModifyAsync(ManagerAddOrModifyModel item)
        {
            var     result = new BaseResult();
            Manager manager;

            if (item.Id == 0)
            {
                //TODO ADD
                manager              = _mapper.Map <Manager>(item);
                manager.Password     = AESEncryptHelper.Encode(CzarCmsKeys.DefaultPassword, CzarCmsKeys.AesEncryptKeys);
                manager.LoginCount   = 0;
                manager.AddManagerId = 1;
                manager.IsDelete     = false;
                manager.AddTime      = DateTime.Now;
                int?isresult = await _repository.InsertAsync(manager);

                if (isresult > 0)
                {
                    result.ResultCode = ResultCodeAddMsgKeys.CommonObjectSuccessCode;
                    result.ResultMsg  = ResultCodeAddMsgKeys.CommonObjectSuccessMsg;
                }
                else
                {
                    result.ResultCode = ResultCodeAddMsgKeys.CommonExceptionCode;
                    result.ResultMsg  = ResultCodeAddMsgKeys.CommonExceptionMsg;
                }
            }
            else
            {
                //TODO Modify
                manager = await _repository.GetAsync(item.Id);

                if (manager != null)
                {
                    _mapper.Map(item, manager);
                    manager.ModifyManagerId = 1;
                    manager.ModifyTime      = DateTime.Now;
                    if (_repository.Update(manager) > 0)
                    {
                        result.ResultCode = ResultCodeAddMsgKeys.CommonObjectSuccessCode;
                        result.ResultMsg  = ResultCodeAddMsgKeys.CommonObjectSuccessMsg;
                    }
                    else
                    {
                        result.ResultCode = ResultCodeAddMsgKeys.CommonExceptionCode;
                        result.ResultMsg  = ResultCodeAddMsgKeys.CommonExceptionMsg;
                    }
                }
                else
                {
                    result.ResultCode = ResultCodeAddMsgKeys.CommonFailNoDataCode;
                    result.ResultMsg  = ResultCodeAddMsgKeys.CommonFailNoDataMsg;
                }
            }
            return(result);
        }
Esempio n. 2
0
        public BaseResult AddOrModify(ManagerAddOrModifyModel item)
        {
            var     result = new BaseResult();
            manager manager;

            if (item.Id == 0)
            {
                //TODO  Add
                manager              = _mapper.Map <manager>(item);
                manager.PASSWORD     = "******";
                manager.LOGINCOUNT   = 0;
                manager.ADDMANAGERID = 1;
                manager.ISDELETE     = false;
                manager.ADDTIME      = DateTime.Now;
                if (_repository.Insert(manager) > 0)
                {
                    result.ResultCode = ResultCodeAddMsgKey.CommonObjectSuccessCode;
                    result.ResultMsg  = ResultCodeAddMsgKey.CommonObjectSuccessMsg;
                }
                else
                {
                    result.ResultCode = ResultCodeAddMsgKey.CommonExceptionCode;
                    result.ResultMsg  = ResultCodeAddMsgKey.CommonExceptionMsg;
                }
            }
            else
            {
                //TODO Modify
                manager = _repository.Get(item.Id);
                if (manager != null)
                {
                    _mapper.Map(item, manager);
                    manager.MODIFYMANAGERID = 1;
                    manager.MODIFYTIME      = DateTime.Now;
                    if (_repository.Update(manager) > 0)
                    {
                        result.ResultCode = ResultCodeAddMsgKey.CommonObjectSuccessCode;
                        result.ResultMsg  = ResultCodeAddMsgKey.CommonObjectSuccessMsg;
                    }
                    else
                    {
                        result.ResultCode = ResultCodeAddMsgKey.CommonExceptionCode;
                        result.ResultMsg  = ResultCodeAddMsgKey.CommonExceptionMsg;
                    }
                }
                else
                {
                    result.ResultCode = ResultCodeAddMsgKey.CommonFailNoDataCode;
                    result.ResultMsg  = ResultCodeAddMsgKey.CommonFailNoDataMsg;
                }
            }
            return(result);
        }
Esempio n. 3
0
        public string AddOrModify([FromForm] ManagerAddOrModifyModel item)
        {
            var result = new BaseResult();
            ManagerValidation validationRules = new ManagerValidation();
            ValidationResult  results         = validationRules.Validate(item);

            if (results.IsValid)
            {
                result = _service.AddOrModify(item);
            }
            else
            {
                result.ResultCode = ResultCodeAddMsgKeys.CommonModelStateInvalidCode;
                result.ResultMsg  = results.ToString("||");
            }
            return(JsonHelper.ObjectToJSON(result));
        }