public virtual ActionResult Delete(string entityName, string key)
        {
            var entity = _admin.GetEntity(entityName);

            if (entity == null)
            {
                return(RedirectToAction("NotFound", new { entityName }));
            }

            var entityRecord = _source.GetEntityRecord(entity, key);

            if (entityRecord == null)
            {
                return(RedirectToAction("Index", "Entities", new { area = "IlaroAdmin", entityName }));
            }

            var deleteOptions = DeleteOptionsHierarchyBuilder.GetHierarchy(entity);
            var model         = new EntityDeleteModel(deleteOptions)
            {
                EntityRecord    = entityRecord,
                RecordHierarchy = _hierarchySource.GetRecordHierarchy(entityRecord, deleteOptions)
            };

            return(View(model));
        }
        public virtual ActionResult Delete(string entityName, string key)
        {
            var entity = AdminInitialise.EntitiesTypes
                         .FirstOrDefault(x => x.Name == entityName);

            if (entity == null)
            {
                throw new NoNullAllowedException("entity is null");
            }

            entity.Key.Value.Raw = key;

            var model = new EntityDeleteModel
            {
                Entity = entity,
                PropertiesDeleteOptions = entity.Properties
                                          .Where(x =>
                                                 x.IsForeignKey &&
                                                 x.DeleteOption == DeleteOption.AskUser)
                                          .Select(x =>
                                                  new PropertyDeleteOption
                {
                    PropertyName = x.ForeignEntity.Name
                })
                                          .ToList(),
                RecordHierarchy = _hierarchySource.GetRecordHierarchy(entity)
            };

            return(View(model));
        }
Exemple #3
0
        private void AddForeignsDelete(
            DbCommand cmd,
            Entity entity,
            IDictionary <string, DeleteOption> options)
        {
            if (options.All(x => x.Value == DeleteOption.Nothing || x.Value == DeleteOption.AskUser))
            {
                return;
            }

            var sbDeletes       = new StringBuilder();
            var recordHierarchy = _hierarchySource.GetRecordHierarchy(entity);

            foreach (var subRecord in recordHierarchy.SubRecordsHierarchies)
            {
                var deleteOption = DeleteOption.Nothing;
                if (options.ContainsKey(subRecord.Entity.Name))
                {
                    deleteOption = options[subRecord.Entity.Name];
                }
                switch (deleteOption)
                {
                case DeleteOption.SetNull:
                    sbDeletes.AppendLine(GetSetToNullUpdateSql(cmd, entity, subRecord));
                    break;

                case DeleteOption.CascadeDelete:
                    var deletes = GetDeleteRelatedEntityDeleteSql(cmd, subRecord).Reverse();
                    sbDeletes.AppendLine(string.Join(Environment.NewLine, deletes));
                    break;
                }
            }
            cmd.CommandText = sbDeletes + cmd.CommandText;
        }
Exemple #4
0
        public virtual ActionResult Delete(string entityName, string key)
        {
            var entity = Admin.GetEntity(entityName);

            if (entity == null)
            {
                return(RedirectToAction("NotFound", new { entityName }));
            }

            if (_entityService.IsRecordExists(entity, key) == false)
            {
                return(RedirectToAction("Index", "Entities", new { area = "IlaroAdmin", entityName }));
            }

            var model = new EntityDeleteModel(entity)
            {
                RecordHierarchy = _hierarchySource.GetRecordHierarchy(entity)
            };

            return(View(model));
        }