public YbpEngine( IServiceProvider services, IYbpContextStorage ctxStorage, YbpUserContext userContext ) { _services = services; _ctxStorage = ctxStorage; _userContext = userContext; }
public void Save <TProcess>(YbpContext <TProcess> ctx, YbpUserContext userContext) where TProcess : YbpProcessBase, new() { var dflags = _db .YbpFlags .Where(x => x.ProcessId == ctx.StoredId) .ToArray(); foreach (var f in ctx.Flags) { var df = dflags.FirstOrDefault(x => x.Key == f.Key); if (df == null) { df = new YbpFlag { ProcessId = ctx.StoredId, Key = f.Key, IsSet = f.Value, UpdatedUTC = DateTime.UtcNow, UserId = (int)userContext["UserId"] }; _db.YbpFlags.Add(df); var dfh = new YbpFlagHistory { Flag = df, IsSet = df.IsSet, UpdatedUTC = df.UpdatedUTC, UserId = df.UserId }; _db.YbpFlagHistory.Add(dfh); } else if (df.IsSet != f.Value) { df.IsSet = f.Value; df.UpdatedUTC = DateTime.UtcNow; df.UserId = (int)userContext["UserId"]; var dfh = new YbpFlagHistory { Flag = df, IsSet = df.IsSet, UpdatedUTC = df.UpdatedUTC, UserId = df.UserId }; _db.YbpFlagHistory.Add(dfh); } } _db.SaveChanges(); }
public virtual bool CanExecute(YbpUserContext user) { return(true); }