Exemplo n.º 1
0
        public async Task <ActionResult> EditEntityType(EntityTypeModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }
            var validationMessage = await MetadataValidationLogic.EditEntityTypeValidation(model, _dbContext);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                return(BadRequest(validationMessage));
            }

            var entityType = await _dbContext.EntityTypes.FindAsync(model.Id);

            entityType.BaseEntityTypeId       = model.BaseEntityTypeId;
            entityType.CodePath               = model.CodePath;
            entityType.DisplayNamePath        = model.DisplayNamePath;
            entityType.Name                   = model.Name;
            entityType.SchemaName             = model.SchemaName;
            entityType.SingularTitle          = model.SingularTitle;
            entityType.PluralTitle            = model.PluralTitle;
            entityType.TableName              = model.TableName;
            entityType.GeneralUsageCategoryId = model.EntityTypeGeneralUsageCategoryId;
            await ProcessEntityTypeLocalFacets(model, true, entityType);

            await _dbContext.SaveChangesAsync();

            ((RequestLogModel)HttpContext.Items["RequestLog"]).EntityTypeId = entityType.Id;
            return(Ok());
        }
Exemplo n.º 2
0
        private async Task ProcessEntityTypeLocalFacets(EntityTypeModel model, bool isEdit, EntityType entityType)
        {
            List <EntityTypeFacetValue> existing;
            var definitions = await _dbContext.EntityTypeFacetDefinitions.ToListAsync();

            if (isEdit)
            {
                existing = await _dbContext.EntityTypeFacetValues.Where(x => x.EntityTypeId == model.Id).ToListAsync();
            }
            else
            {
                existing = new List <EntityTypeFacetValue>();
            }
            if (model.LocalFacets != null)
            {
                foreach (var localFacet in model.LocalFacets)
                {
                    var facet = existing.FirstOrDefault(x => x.FacetDefinition.Name == localFacet.FacetName);
                    if (facet == null)
                    {
                        facet = new EntityTypeFacetValue
                        {
                            EntityType      = entityType,
                            FacetDefinition = definitions.Single(x => x.Name == localFacet.FacetName)
                        };
                        _dbContext.EntityTypeFacetValues.Add(facet);
                    }
                    if (facet.Value != localFacet.Value)
                    {
                        facet.Value = localFacet.Value;
                    }
                }
                _dbContext.EntityTypeFacetValues.RemoveRange(existing.Where(x => !model.LocalFacets.Any(l => l.FacetName == x.FacetDefinition.Name)));
            }
        }
Exemplo n.º 3
0
        public void Test()
        {
            TinyMapper.Bind <EntityTypeModel, EntityType>(config =>
            {
                config.Bind(target => target.EntityMappingTypes, typeof(List <EntityMapppingType>));
            });

            TinyMapper.Bind <EntityType, EntityTypeModel>(config =>
            {
                config.Bind(target => target.EntityMappingTypes, typeof(List <EntityMapppingTypeModel>));
            });

            var entityType = new EntityType
            {
                CreateDate         = DateTime.Now,
                Id                 = 1,
                Type               = "MyType",
                EntityMappingTypes = new List <EntityMapppingType> {
                    new EntityMapppingType {
                        Value = 5
                    }
                }
            };

            EntityTypeModel entityTypeModel = TinyMapper.Map <EntityType, EntityTypeModel>(entityType);
            EntityType      newEntityType   = TinyMapper.Map <EntityTypeModel, EntityType>(entityTypeModel);
        }
Exemplo n.º 4
0
 public static async Task <string> EditEntityTypeValidation(EntityTypeModel model, MetadataDbContext dbContext)
 {
     if (!await dbContext.EntityTypes.AnyAsync(x => x.Id == model.Id))
     {
         return("Entity not found");
     }
     return(string.Empty);
 }
Exemplo n.º 5
0
 public static async Task <string> AddEntityTypeValidation(EntityTypeModel model, MetadataDbContext dbContext, IImplementationsContainer implementationsContainer)
 {
     if (await dbContext.EntityTypes.AnyAsync(x => x.Name == model.Name && x.AppTypeId == implementationsContainer.InstanceInfo.AppTypeId))
     {
         return($"Another entity with name: \"{ model.Name }\" is already defiend.");
     }
     return(await Task.FromResult(string.Empty));
 }
Exemplo n.º 6
0
        public async Task <IActionResult> Post(EntityTypeModel model)
        {
            var service = new EntityRepositoryService(connString);
            await service.CreateEntityType(model.Name, model.Description);

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "EntityType Created successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Exemplo n.º 7
0
        public static async Task <string> DeleteEntityValidation(EntityTypeModel model, MetadataDbContext dbContext)
        {
            if (await dbContext.Properties.AnyAsync(x => x.OwnerEntityTypeId == model.Id))
            {
                return("The selected entity has referenced to one or more properties.");
            }
            if (!await dbContext.EntityTypes.AnyAsync(x => x.Id == model.Id))
            {
                return("The selected entity is not exist");
            }

            var relativeProperty = await dbContext.Properties.Where(x => x.DataEntityTypeId == model.Id).Include(x => x.OwnerEntityType).ToListAsync();

            if (relativeProperty.Any())
            {
                return("The selected entity is navigated to '" + relativeProperty.FirstOrDefault().Name +
                       @"' in entity '" + relativeProperty.FirstOrDefault().OwnerEntityType.Name + "'");
            }
            return(string.Empty);
        }
Exemplo n.º 8
0
        public async Task <ActionResult> DeleteEntityType(EntityTypeModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }
            var validationMessage = await MetadataValidationLogic.DeleteEntityValidation(model, _dbContext);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                return(StatusCode(400, validationMessage));
            }
            var entityType = await _dbContext.EntityTypes.FindAsync(model.Id);

            var localFacets = await _dbContext.EntityTypeFacetValues.Where(x => x.EntityTypeId == model.Id).ToListAsync();

            _dbContext.EntityTypeFacetValues.RemoveRange(localFacets);
            _dbContext.EntityTypes.Remove(entityType);
            await _dbContext.SaveChangesAsync();

            ((RequestLogModel)HttpContext.Items["RequestLog"]).EntityTypeId = entityType.Id;
            return(Ok());
        }
Exemplo n.º 9
0
        public async Task <ActionResult> AddEntityType(EntityTypeModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }

            var validationMessage = await MetadataValidationLogic.AddEntityTypeValidation(model, _dbContext, _implementations);

            if (!string.IsNullOrEmpty(validationMessage))
            {
                return(StatusCode(400, validationMessage));
            }

            var entityType = new EntityType
            {
                BaseEntityTypeId       = model.BaseEntityTypeId,
                CodePath               = model.CodePath,
                DisplayNamePath        = model.DisplayNamePath,
                Name                   = model.Name,
                SchemaName             = model.SchemaName,
                SingularTitle          = model.SingularTitle,
                PluralTitle            = model.PluralTitle,
                GeneralUsageCategoryId = model.EntityTypeGeneralUsageCategoryId,
                AppTypeId              = _implementations.InstanceInfo.AppTypeId,
                TableName              = model.TableName
            };

            _dbContext.EntityTypes.Add(entityType);
            await ProcessEntityTypeLocalFacets(model, false, entityType);

            await _dbContext.SaveChangesAsync();

            ((RequestLogModel)HttpContext.Items["RequestLog"]).EntityTypeId = entityType.Id;
            return(Ok());
        }