public async Task Delete() { var handler = new StorageSpaceHandler(BasicNeeds); var sp = context.StorageSpaces.First(); var query = new DeleteStorageSpace { Id = sp.Id, }; await handler.Handle(query, CancellationToken.None); var cat = await context.StorageSpaces.AnyAsync <StorageSpaceDb>(p => p.Id == sp.Id); Assert.IsFalse(cat); }
public async Task <Unit> Handle(DeleteStorageSpace message, CancellationToken cancellationToken) { var command = context.StorageSpaces.Where(m => m.Id == message.Id).AsQueryable() .Include(a => a.Address); var storageSpace = await command.FirstOrDefaultAsync(); ValidateStorageSpace(storageSpace); context.StorageSpaces.Remove(storageSpace); await context.SaveChangesAsync(); return(Unit.Value); }
public async Task <IActionResult> Delete([FromBody] DeleteStorageSpace storageSpace) { await mediator.Send(storageSpace); return(NoContent()); }