Exemplo n.º 1
0
        /// <summary>
        /// 添加示例实体
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public OperationResult AddDemoEntity(DemoEntityDto dto)
        {
            dto.CheckNotNull("dto");
            if (CheckDemoEntityName(dto.Name, CheckExistsType.Insert))
            {
                return(new OperationResult(OperationResultType.ValidError, "名称为“{0}”的示例实体已存在,不能重复添加。".FormatWith(dto.Name)));
            }
            DemoEntity entity = Mapper.Map <DemoEntity>(dto);

            return(_demoEntityRepository.Insert(entity) > 0
                ? new OperationResult(OperationResultType.Success, "示例实体“{0}”添加成功。".FormatWith(entity.Name))
                : new OperationResult(OperationResultType.NoChanged));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 异步修改示例实体
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <OperationResult> UpdateDemoEntityAsync(DemoEntityDto dto)
        {
            dto.CheckNotNull("dto");
            if (await CheckDemoEntityNameAsync(dto.Name, CheckExistsType.Update, dto.Id))
            {
                return(new OperationResult(OperationResultType.ValidError, "名称为“{0}”的示例实体已存在,不能重复添加。".FormatWith(dto.Name)));
            }
            DemoEntity entity = await _demoEntityRepository.GetByKeyAsync(dto.Id);

            entity = Mapper.Map(dto, entity);
            return((await _demoEntityRepository.UpdateAsync(entity)) > 0
                ? new OperationResult(OperationResultType.Success, "示例实体“{0}”更新成功。".FormatWith(entity.Name))
                : new OperationResult(OperationResultType.NoChanged));
        }