public async Task <EventHead> DeleteEventHead(DataForDeletingEventHeadDto dataForDeletingEventHead) { if (dataForDeletingEventHead.Id == 0 || dataForDeletingEventHead.Name == null) { throw new DataInvalidException("Incorrect input. Please re-check the ID and Name"); } var eventHeadFromDb = await _context.EventHeads.FindAsync(dataForDeletingEventHead.Id); if (eventHeadFromDb == null) { throw new DataInvalidException("Invalid id. Please re-check the ID"); } if (dataForDeletingEventHead.Name != eventHeadFromDb.Name) { throw new DataInvalidException(" Name and Id does not match. Please re-check the ID and Name"); } _context.EventHeads.Remove(eventHeadFromDb); await _context.SaveChangesAsync(); return(eventHeadFromDb); }
public async Task <ActionResult <EventHead> > RemoveEventHead(DataForDeletingEventHeadDto dataFromClient) { return(Ok(await _repo.DeleteEventHead(dataFromClient))); }