Exemple #1
0
        public async Task <Message> PostRules([FromBody] RulesCreation rulesCreation)
        {
            if (rulesCreation == null)
            {
                return(Message.Fail());
            }

            var dbitem = await _rulesRepository.GetSingleAsync(x => x.Name == rulesCreation.Name);

            if (dbitem != null)
            {
                return(Message.Fail().Add("content", "规则名重复"));
            }
            rulesCreation.Id   = Method.GetGuid32();
            rulesCreation.Sort = await _rulesRepository.CountAsync();

            var newItem = _mapper.Map <Rules>(rulesCreation);

            _rulesRepository.Add(newItem);

            if (!await _unitOfWork.SaveAsync())
            {
                return(Message.ServerError());
            }
            return(Message.Ok());
        }