private void AddToLog(C_Log logItem) { var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext; logItem.AsOf = DateTime.Now; db.C_Log.Add(logItem); db.SaveChanges(); }
protected override bool AuthorizeCore(System.Web.HttpContextBase httpContext) { var authorized = base.AuthorizeCore(httpContext) && (UserSession.IsGuestTeller || UserSession.IsKnownTeller); if (!authorized) { // The user is not authenticated return(false); } var electionModel = new ElectionModel(); if (UserSession.IsGuestTeller) { if (!electionModel.GuestsAllowed()) { UserSession.ProcessLogout(); return(false); } return(true); } // only update visit every 5 minutes. Lasts for 1 hour, so could be only 45 minutes. var currentElection = UserSession.CurrentElection; var delayTime = TimeSpan.FromMinutes(5); if (currentElection != null && currentElection.ListForPublic.AsBoolean()) { LogTime("init"); var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext; LogTime("resolve"); db.Election.Attach(currentElection); LogTime("attach"); currentElection.ListedForPublicAsOf = DateTime.Now; LogTime("listed"); var electionCacher = new ElectionCacher(db); LogTime("cacher"); electionCacher.UpdateItemAndSaveCache(currentElection); LogTime("update cache"); if (currentElection.ListForPublic.AsBoolean() && (DateTime.Now - currentElection.ListedForPublicAsOf.GetValueOrDefault(DateTime.Now.AddMinutes(-60))).TotalMinutes > delayTime.TotalMinutes) { db.SaveChanges(); LogTime("db save"); } new PublicHub().TellPublicAboutVisibleElections(); LogTime("notify"); } return(true); }
/// <Summary>Erase all ballots and results</Summary> public static void EraseBallotsAndResults(Guid electionGuid) { var db = UnityInstance.Resolve <IDbContextFactory>().GetNewDbContext; db.Result.Where(r => r.ElectionGuid == electionGuid).Delete(); db.ResultTie.Where(r => r.ElectionGuid == electionGuid).Delete(); db.ResultSummary.Where(r => r.ElectionGuid == electionGuid).Delete(); // delete ballots in all locations... cascading will delete votes db.Ballot.Where(b => db.Location.Where(x => x.ElectionGuid == electionGuid).Select(l => l.LocationGuid) .Contains(b.LocationGuid)).Delete(); }
/// <summary>From the layout page, this is called to inject links to CSS and JS files for this view</summary> /// <param name="extension"></param> /// <param name="secondaryExtensions"></param> public IHtmlString CreateTagsToReferenceContentFiles(string extension, params string[] secondaryExtensions) { var cachedPaths = UnityInstance.Resolve <IViewResourcesCache>(); // make a local copy, so we can clear the ones we've done var list = _list.ToList(); //_list.Clear(); // --> is an included View creates tags, other ones will be re-injected too... should find way to stop this // however, browsers are forgiving, and only call for the resource once! var alreadySent = ItemKey.ClientFilesSent.FromPageItems(new List <string>(), true); var htmlString = list .SelectMany(s => cachedPaths.GetTag(s, extension, secondaryExtensions)) .Where(s => s.HasContent() && !alreadySent.Contains(s)) .AddTo(alreadySent) .JoinedAsString("\n"); return(htmlString.AsRawHtml()); }
private void OnEndRequest(object sender, EventArgs eventArgs) { UnityInstance.Resolve <IDbContextFactory>().CloseAll(); }
public ViewResourcesCache() { _linkedResourcesHelper = UnityInstance.Resolve <ILinkedResourcesHelper>(); _dict = new Dictionary <string, bool>(); }