public IEnumerable <Punishment> getPunishments(Diapasone diapasone) { return(Punishment.LoadByIds( from stringId in Config.instance.mainConnection.LoadIdsByConditions( Punishment.TableSpec.instance, new ComplexCondition( ConditionsJoinType.AND, new ComparisonCondition( Punishment.TableSpec.instance.getColumnSpec(Punishment.TableSpec.FIELD_OWNERID), ComparisonType.EQUAL, this.id.ToString() ), new ComparisonCondition( Punishment.TableSpec.instance.getColumnSpec(Punishment.TableSpec.FIELD_EXPIRES), ComparisonType.GREATEROREQUAL, DateTime.Now.ToUTCString() ), new ComparisonCondition( Punishment.TableSpec.instance.getColumnSpec(Punishment.TableSpec.FIELD_ISWITHDRAWED), ComparisonType.EQUAL, "0" ) ), diapasone ) select int.Parse(stringId) )); }
public static void RecalculateRestrictions(Board board, User user) { List <Punishment> punishments = (from punishment in Punishment.getEffectivePunishments(user, board) where punishment.punishmentType.weight > 0 orderby punishment.expires descending select punishment).ToList(); Dictionary <int, DateTime> layer2expirationDate = new Dictionary <int, DateTime>(); foreach (var layer in PostLayer.allLayers) { if (!layer.maxPunishments.HasValue) { continue; } bool restricted = false; int accumulated = 0; DateTime?expirationDate = null; foreach (var punishment in punishments) { accumulated += punishment.punishmentType.weight; if (accumulated >= layer.maxPunishments.Value) { expirationDate = punishment.expires; restricted = true; break; } } if (restricted) { layer2expirationDate[layer.id] = expirationDate.Value; } } string data = (from kvp in layer2expirationDate select string.Format("{0}:{1}", kvp.Key, kvp.Value.Ticks)).Join(";"); ChangeSetUtil.ApplyChanges( new InsertOrUpdateChange( TableSpec.instance, new Dictionary <string, AbstractFieldValue> { { TableSpec.FIELD_BOARDID, new ScalarFieldValue(board.id.ToString()) }, { TableSpec.FIELD_USERID, new ScalarFieldValue(user.id.ToString()) }, { TableSpec.FIELD_DATA, new ScalarFieldValue(data) }, }, new Dictionary <string, AbstractFieldValue> { { TableSpec.FIELD_DATA, new ScalarFieldValue(data) }, }, new ComplexCondition( ConditionsJoinType.AND, new ComparisonCondition( TableSpec.instance.getColumnSpec(TableSpec.FIELD_BOARDID), ComparisonType.EQUAL, board.id.ToString() ), new ComparisonCondition( TableSpec.instance.getColumnSpec(TableSpec.FIELD_USERID), ComparisonType.EQUAL, user.id.ToString() ) ) ) ); }