public async Task <CompensationResult> Compensate(CompensateContext <Coding> context) { _db.Remove(context.Log); await _db.SaveChangesAsync(); return(context.Compensated()); }
public virtual void Delete(TEntity entity) { if (_context.Entry(entity).State == EntityState.Detached) { _context.Attach(entity); } _context.Remove(entity); }
/// <summary> /// Deletes an object from database. If the object is of type DBObject, then will only set the IsDeleted property to true, otherwise will delete. /// </summary> /// <typeparam name="T">Type of the entity.</typeparam> /// <param name="ctx">Database context instance.</param> /// <param name="id">ID of the object to be deleted.</param> /// <param name="_commitChanges">If should or not use transaction when deleting.</param> /// <returns>Returns an instance of the deleted object.</returns> public static T Delete <T>(this CoreDbContext ctx, int id, bool _commitChanges = true) where T : class, IEntity, IKeyed { var entity = ctx.Find <T>(id); if (entity != null) { if (entity is ITrackableEntity entityTrackable) { if (entity.ID > 0) { if (entity is DBObject entityDBObject) { entityDBObject.IsDeleted = true; if (_commitChanges) { ctx.SaveChanges(entityDBObject); } else { ctx.ApplyChanges(entityTrackable); } } else { ctx.Remove(entityTrackable); ctx.SaveChanges(); } } else { ctx.RemoveTrackedEntity(entity); } } else { ctx.Remove(entity); ctx.SaveChanges(); } return(entity); } throw new KeyNotFoundException(); }
public async Task <bool> DeleteReactionRole(ulong guild, string name) { var gid = guild.MapUlongToLong(); var result = await(_context.ReactionRoleModels as IQueryable <ReactionRoleStorageModel>).FirstOrDefaultAsync(x => x.GuildId == gid && x.Name == name); if (result != null) { _context.Remove(result); await _context.SaveChangesAsync(); } return(true); }
public async Task <Result <Unit> > Delete(ulong guildId, ulong userId) { var gid = guildId.MapUlongToLong(); var uid = userId.MapUlongToLong(); var result = await(_context.JailDatas as IQueryable <JailDataStorage>).FirstOrDefaultAsync(x => x.GuildId == gid && x.UserId == uid); if (result != null) { _context.Remove(result); await _context.SaveChangesAsync(); } return(new Unit()); }