public async Task TestDeleteAsync()
        {
            // Arrange
            var random = new Random(0);
            var number = random.Next(5);
            var entity = GetList()[number];

            entity = await _service.InsertAsync(entity);

            var id = entity.Id;

            _dbContext.Entry(entity).State = EntityState.Detached;

            // Act
            var entityExsist = await _service.GetAsync(id);

            _dbContext.Entry(entityExsist).State = EntityState.Detached;
            await _service.DeleteAsync(id);

            var entityNotExsist = await _service.GetAsync(id) ?? null;

            // Assert
            Assert.Multiple(() =>
            {
                Assert.IsNull(entityNotExsist);
                Assert.IsNotNull(entityExsist);
            });
        }
示例#2
0
        public async Task DeleteAsync(int siteId, int formId)
        {
            if (formId <= 0) return;

            var formInfo = await _formRepository.GetFormInfoAsync(siteId, formId);
            var relatedIdentities = GetRelatedIdentities(formInfo.Id);

            await _tableStyleRepository.DeleteAllAsync(FormUtils.TableNameData, relatedIdentities);
            await _dataRepository.DeleteByFormIdAsync(formId);
            await _formRepository.DeleteAsync(siteId, formId);
        }
示例#3
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            try
            {
                await _repository.DeleteAsync(id);

                await _repository.SaveChangesAsync();
            }
            catch
            {
                if (!await FormExistsAsync(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToAction(nameof(Index)));
        }