public async Task <IResultModel> Add(ClassAddModel model)
        {
            var entity = _mapper.Map <ClassEntity>(model);

            if (await _repository.Exists(entity))
            {
                return(ResultModel.Failed($"类名称({entity.Name})已存在"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                if (await _repository.AddAsync(entity, uow))
                {
                    if (entity.BaseEntityType != BaseEntityType.Normal)
                    {
                        var propertyEntities = _baseEntityPropertyCollection.Get(entity.BaseEntityType);
                        propertyEntities.ForEach(m => m.ClassId = entity.Id);
                        //添加基类实体的属性
                        if (await _propertyRepository.AddAsync(propertyEntities, uow))
                        {
                            var methodEntity = _mapper.Map <ClassMethodEntity>(model.Method);
                            methodEntity.ClassId = entity.Id;
                            //添加方法
                            if (await _classMethodRepository.AddAsync(methodEntity, uow))
                            {
                                uow.Commit();
                                return(ResultModel.Success());
                            }
                        }
                    }
                }
            }

            return(ResultModel.Failed());
        }
示例#2
0
        public async Task <IResultModel> UpdateSortList(SortUpdateModel <Guid> model)
        {
            if (model.Options == null || !model.Options.Any())
            {
                return(ResultModel.Failed("不包含数据"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var option in model.Options)
                {
                    var entity = await _repository.GetAsync(option.Id, uow);

                    if (entity == null)
                    {
                        uow.Rollback();
                        return(ResultModel.Failed());
                    }

                    entity.Sort = option.Sort;
                    if (!await _repository.UpdateAsync(entity, uow))
                    {
                        uow.Rollback();
                        return(ResultModel.Failed());
                    }
                }

                uow.Commit();
            }

            return(ResultModel.Success());
        }
示例#3
0
        public async Task<IResultModel> Delete(Guid id)
        {
            var entity = await _repository.GetAsync(id);
            if (entity == null)
                return ResultModel.NotExists;

            using (var uow = _dbContext.NewUnitOfWork())
            {
                var result = await _repository.SoftDeleteAsync(id, uow);
                if (result)
                {
                    result = await _classRepository.DeleteByProject(id, uow);
                    if (result)
                    {
                        result = await _propertyRepository.DeleteByProject(id, uow);
                        if (result)
                        {
                            result = await _modelPropertyRepository.DeleteByProject(id, uow);
                            if (result)
                            {
                                uow.Commit();
                                return ResultModel.Success();
                            }
                        }
                    }
                }
            }

            return ResultModel.Failed();
        }