Ejemplo n.º 1
0
        /// <summary>
        /// 删除代码实体信息信息
        /// </summary>
        /// <param name="ids">要删除的代码实体信息编号</param>
        /// <returns>业务操作结果</returns>
        public async Task <OperationResult> DeleteCodeEntities(params Guid[] ids)
        {
            List <string> names = new List <string>();

            UnitOfWork.EnableTransaction();
            foreach (var id in ids)
            {
                var entity = EntityRepository.Query(m => m.Id == id).Select(m => new { D = m, PropertyCount = m.Properties.Count() })
                             .FirstOrDefault();
                if (entity == null)
                {
                    return(null);
                }

                if (entity.PropertyCount > 0)
                {
                    return(new OperationResult(OperationResultType.Error, $"实体“{entity.D.Name}”包含着 {entity.PropertyCount} 个属性,请先删除下属属性信息"));
                }

                int count = await EntityRepository.DeleteAsync(entity.D);

                if (count > 0)
                {
                    names.Add(entity.D.Name);
                }
            }

            await UnitOfWork.CommitAsync();

            return(names.Count > 0
                ? new OperationResult(OperationResultType.Success, $"实体“{names.ExpandAndToString()}”删除成功")
                : OperationResult.NoChanged);
        }
Ejemplo n.º 2
0
        public void DeleteAsync_SessionReadOnly_ExceptionThrown()
        {
            var session = new Mock <ISession>();

            session.Setup(x => x.DefaultReadOnly)
            .Returns(true);
            var repository = new EntityRepository <TestEntity>(session.Object);
            var entity     = new TestEntity();

            Assert.ThrowsAsync <EntityRepositoryException>(async() => await repository.DeleteAsync(entity),
                                                           "The Repository is read-only");
        }
Ejemplo n.º 3
0
        public override async Task <bool> DeleteAsync <TDto>(TDto dto)
        {
            TEntity primaryEntity = null;

            if (dto is IPrimary <TKey> )
            {
                var id = (dto as IPrimary <TKey>).Id;
                primaryEntity = await EntityRepository.GetByIdAsync(id);
            }

            var entity = Mapper.Map(dto, primaryEntity);

            return(await EntityRepository.DeleteAsync(entity));
        }
Ejemplo n.º 4
0
        public async Task TrackListing([TimerTrigger("* */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            var newCoins = await coingeckoClient.GetCoinsAsync();

            var listings = await listingRepository.GetAllAsync();

            foreach (var listing in listings)
            {
                if (newCoins.Any(c => c.Symbol.ToLower() == listing.Name.ToLower()))
                {
                    await botClient.SendTextMessageAsync(chatId : listing.ChatId,
                                                         text : $"Coin listed: {listing.Name}");

                    await listingRepository.DeleteAsync(listing.ChatId, new[] { listing.Name });
                }
            }
        }
Ejemplo n.º 5
0
        private async Task RemoveAsync(Message message)
        {
            var commandArgs = message.Text.Split(new[] { RemoveCmd }, StringSplitOptions.RemoveEmptyEntries);

            if (commandArgs.Length == 0)
            {
                return;
            }

            var coinName = HttpUtility.ParseQueryString(commandArgs[0]).Get("n");
            var listings = listingRepository.GetAll(message.Chat.Id);

            if (listings.Any(l => l.Name == coinName))
            {
                await listingRepository.DeleteAsync(message.Chat.Id, new[] { coinName });
            }
        }
Ejemplo n.º 6
0
        public async Task DeleteAsync_ItemById_ReturnsSingleRowDeleted()
        {
            var repositoryProvider = new Mock <IRepositoryProvider>();
            var definitionProvider = new DataAnnotationsDefinitionProvider();

            repositoryProvider.Setup(provider => provider.EntityDefinitionProvider).Returns(definitionProvider);
            repositoryProvider.Setup(provider => provider.DeleteAsync(It.IsAny <IEntitySet>(), It.IsAny <CancellationToken>())).ReturnsAsync(1);

            int actual;

            using (var provider = repositoryProvider.Object)
            {
                var repository = new EntityRepository <ComplexEntity, ComplexRaisedRow>(provider, this.mapper);
                actual = await repository.DeleteAsync(14, CancellationToken.None);
            }

            Assert.AreEqual(1, actual);
        }
Ejemplo n.º 7
0
        private async Task RemoveAsync(Message message)
        {
            var commandArgs = message.Text.Split(new[] { RemoveCmd }, StringSplitOptions.RemoveEmptyEntries);

            if (commandArgs.Length == 0)
            {
                return;
            }

            var queryArgs = commandArgs[0];
            var query     = HttpUtility.ParseQueryString(queryArgs);

            var name   = query.Get("id");
            var alerts = alertRepository.GetAll(message.Chat.Id);

            if (alerts.Any(l => l.Name == name))
            {
                await alertRepository.DeleteAsync(message.Chat.Id, new[] { name });
            }
        }
Ejemplo n.º 8
0
 public async Task <bool> DeleteAsync(TKey id)
 {
     return(await EntityRepository.DeleteAsync(id));
 }
 public async Task <CommandResult> DeleteAsync(TEntity entity, bool saveChanges = true)
 {
     return(await EntityRepository.DeleteAsync(entity, saveChanges));
 }
Ejemplo n.º 10
0
 public virtual Task <bool> DeleteAsync(int id)
 => EntityRepository.DeleteAsync(id);