示例#1
0
        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));
        }
示例#2
0
        public virtual ActionResult Delete(EntityDeleteModel model)
        {
            var entity = Admin.GetEntity(model.EntityName);

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

            try
            {
                var isSuccess = _entityService.Delete(entity, model.Key, model.PropertiesDeleteOptions);
                if (isSuccess)
                {
                    _notificator.Success(IlaroAdminResources.DeleteSuccess, entity.Verbose.Singular);

                    return(RedirectToAction("Index", "Entities", new { entityName = model.EntityName }));
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                _notificator.Error(ex.Message);
            }

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

            return(View(model));
        }
示例#3
0
        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));
        }
示例#4
0
        public virtual ActionResult Delete(EntityDeleteModel model)
        {
            var entity = AdminInitialise.EntitiesTypes
                         .FirstOrDefault(x => x.Name == model.EntityName);

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

            try
            {
                var deleteOptions =
                    model.PropertiesDeleteOptions ??
                    new List <PropertyDeleteOption>();
                if (_entityService.Delete(entity, model.Key, deleteOptions))
                {
                    _notificator.Success(IlaroAdminResources.DeleteSuccess, entity.Verbose.Singular);

                    return(RedirectToAction("Index", "Entities", new { entityName = model.EntityName }));
                }

                _notificator.Error(IlaroAdminResources.UncaughtError);
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += "<br />" + ex.InnerException.Message;
                }
                _notificator.Error(message);
            }

            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));
        }
示例#5
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));
        }
 public ResponseWrapper<EntityDeleteModel> DeleteEntity(int entityId)
 {
     var entity = context
         .Entities
         .Single(x => 
             x.EntityId == entityId
         );
     
     context
         .Entities
         .Remove(entity);
     
     context.SaveChanges();
     
     var response = new EntityDeleteModel
     {
         EntityId = entity.EntityId,
     };
     
     return new ResponseWrapper<EntityDeleteModel>(_validationDictionary, response);
 }