public async Task Delete(int tenantId, SubnavLink subNavlink = null)
        {
            var apiContext = new ApiContext(tenantId);
            var entityContainerResource = new EntityContainerResource(apiContext);
            var collection = await entityContainerResource.GetEntityContainersAsync(SubnavLinkEntityName, 200);

            var entityResource = new EntityResource(apiContext);

            if (subNavlink == null)
            {
                var appId = await GetAppId(apiContext);

                foreach (
                    var item in
                    collection.Items.Where(subnavLink => subnavLink.Item.ToObject <SubnavLink>().AppId.Equals(appId))
                    )
                {
                    await entityResource.DeleteEntityAsync(SubnavLinkEntityName, item.Id);
                }
            }
            else
            {
                if (subNavlink.ParentId == null || subNavlink.Path == null || !subNavlink.Path.Any())
                {
                    throw new Exception("ParentId and Path is required to delete a link");
                }
                var existing = collection.Items.FirstOrDefault(x => subNavlink.Path.SequenceEqual(x.Item.ToObject <SubnavLink>().Path) &&
                                                               (subNavlink.ParentId == x.Item.ToObject <SubnavLink>().ParentId || subNavlink.Location == x.Item.ToObject <SubnavLink>().Location));

                if (existing != null)
                {
                    await entityResource.DeleteEntityAsync(SubnavLinkEntityName, existing.Id);
                }
            }
        }
Beispiel #2
0
        public async Task DeleteEvent(IApiContext apiContext, string id)
        {
            if (id == null)
            {
                return;
            }
            var correlationId = String.Empty;
            var errorCode     = String.Empty;

            try
            {
                var resource = new EntityResource(apiContext);
                await resource.DeleteEntityAsync(_listFullName, id);

                //var entityHandler = new EntityHandler(_appSetting);
                //await entityHandler.DeleteEntityAsync(apiContext, id, EntityListConstants.MozuEventQueueName);
            }
            catch (AggregateException ex)
            {
                ex.Handle(e =>
                {
                    var apiEx = e as ApiException;
                    if (apiEx != null)
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(apiEx);
                        correlationId      = apiEx.CorrelationId;
                        errorCode          = apiEx.ErrorCode;
                    }
                    else
                    {
                        _capturedException = ExceptionDispatchInfo.Capture(ex);
                    }
                    return(true);
                });
            }
            catch (ApiException ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
                correlationId      = ex.CorrelationId;
                errorCode          = ex.ErrorCode;
            }
            catch (Exception ex)
            {
                _capturedException = ExceptionDispatchInfo.Capture(ex);
            }
            if (_capturedException == null)
            {
                return;
            }
            if (_capturedException.SourceException.InnerException != null)
            {
                var message = String.Format("{0}. CorrId: {1}, ErrorCode: {2}",
                                            _capturedException.SourceException.Message, correlationId,
                                            errorCode);
                if (_capturedException.SourceException.InnerException != null)
                {
                    _logger.Error(message, _capturedException.SourceException);
                }
            }
        }
 public async Task DeleteEntityAsync(IApiContext apiContext, object id, string listName)
 {
     var entityResource = new EntityResource(apiContext);
     var listFQN        = ValidateListName(listName);
     await entityResource.DeleteEntityAsync(listFQN, id.ToString());
 }