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); }); }
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); }
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))); }