public override async Task <DeleteResult.IDeleteResult> Work(DeleteCmd Op, Unit state) { try { var entity = _ctx.Entry(Op.Item); switch (entity.State) { case EntityState.Unchanged: entity.State = EntityState.Deleted; await _ctx.SaveChangesAsync(); return(new DeleteResult.Successful(entity.Entity)); case EntityState.Added: _ctx.Remove(entity); return(new DeleteResult.Successful(entity.Entity)); default: return(new DeleteResult.Failed($"Entity is in an incorrect state. Expected Added or Unchanged. Got {entity.State.ToString()}")); } } catch (Exception ex) { //log exception return(new DeleteResult.Failed(ex.ToString())); } }
public override async Task <IDeteleEntityResult> Work(DeleteEntityCmd Op, Unit state) { try { var entity = _context.Entry(Op.Item); //if (entity.State == Microsoft.EntityFrameworkCore.EntityState.De) // { _context.Remove(Op.Item); await _context.SaveChangesAsync(); return(new Success()); //} //else // { // return new Failed("Incorrect entity state! Expected Detached, got" + entity.State); //} } catch (Exception exp) { Console.WriteLine(exp.ToString()); return(new Failed(exp.ToString())); } }