Beispiel #1
0
        public async Task <ActionResult> EditEntity(EntityMetadataModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }
            var error = EditTypeValidation(model);

            if (error != null)
            {
                return(BadRequest(error));
            }

            var type = await _dbContext.Entities.FindAsync(model.Id);

            type.BaseEntityId           = model.BaseEntityId;
            type.CodePath               = model.CodePath;
            type.DisplayNamePath        = model.DisplayNamePath;
            type.Name                   = model.Name;
            type.SchemaName             = model.SchemaName;
            type.SingularTitle          = model.SingularTitle;
            type.PluralTitle            = model.PluralTitle;
            type.GeneralUsageCategoryId = model.EntityGeneralUsageCategoryId;
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Beispiel #2
0
        public async Task <ActionResult> AddEntity(EntityMetadataModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }
            var error = AddTypeValidation(model);

            if (error != null)
            {
                return(BadRequest(error));
            }

            var type = new Entity
            {
                BaseEntityId           = model.BaseEntityId,
                CodePath               = model.CodePath,
                DisplayNamePath        = model.DisplayNamePath,
                Name                   = model.Name,
                SchemaName             = model.SchemaName,
                SingularTitle          = model.SingularTitle,
                PluralTitle            = model.PluralTitle,
                GeneralUsageCategoryId = model.EntityGeneralUsageCategoryId,
                AppTypeId              = _implementations.InstanceInfo.AppTypeId
            };

            _dbContext.Entities.Add(type);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Beispiel #3
0
        private string EditTypeValidation(EntityMetadataModel model)
        {
            string error = null;

            if (string.IsNullOrWhiteSpace(model.Name))
            {
                return(error = "Name Can't be empty");
            }
            if (model.Name.Length > 128)
            {
                return(error = "Table name length should be less than 128 characters.");
            }
            return(error);
        }
Beispiel #4
0
        public async Task <ActionResult> DeleteEntity(EntityMetadataModel model)
        {
            if (!_permissionService.IsAllowed(new ActionRequestInfo(HttpContext, _implementations, null, ActionTypeEnum.ManageMetadata)))
            {
                return(Unauthorized());
            }
            //TODO: Handle errors, validate model
            var type = await _dbContext.Entities.FindAsync(model.Id);

            _dbContext.Entities.Remove(type);
            await _dbContext.SaveChangesAsync();

            return(Ok());
        }