protected void Session_Start() { using (var dbContext = new EntitiesContainer()) { var repository = new SessionsRepository() {Context = dbContext}; var sessionEntry = new Session() { IpAddress = Context.Request.UserHostAddress, StartDate = DateTime.Now, ServerSessionId = Session.SessionID, UserAgent = Context.Request.UserAgent }; repository.Add(sessionEntry); repository.Commit(); } }
public UnitOfWork(EntitiesContainer context) { Context = context; Current = this; }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { //Init ObjectContext per every request _currentContext = new EntitiesContainer(); SetDbContext(); if (IsAuthorized && CurrentUserName != String.Empty) { using (new UnitOfWork(_currentContext)) { accountRepository.GetByUsername(CurrentUserName).LastlogonAt = DateTime.Now; } } if (settingsRepository.IsInMaintenance && HttpContext.Request.RawUrl.ToLower().IndexOf("admin", System.StringComparison.Ordinal) == -1) filterContext.Result = RedirectToAction("Maintenance", "Error"); //main application specific operations if (HttpContext.Request.RawUrl.IndexOf("Admin", System.StringComparison.Ordinal) == -1) { //staticPages for menu IEnumerable<StaticPageViewModel> staticPages = staticPagesRepository.GetAll() .Select(page => new StaticPageViewModel() { Id = page.Id, Title = page.Title, Content = page.Content, Key = page.Key, Section = (StaticPageSection)page.Section, SubPages = page.SubPages.Select(subpage => new StaticSubPageViewModel() { Id = subpage.Id, Key = subpage.Key, Section = (StaticPageSection)page.Section, Title = subpage.Title, Content = subpage.Content, PageKey = page.Key }).ToList(), Files = page.Files.Select(file => new FileViewModel() { Id = file.Id, FileName = file.FileName, Extension = Path.GetExtension(file.FileName) }).ToList() }).ToList(); ViewBag.StaticPages = staticPages; } else //admin specific { } base.OnActionExecuting(filterContext); }