public override void OnActionExecuting(ActionExecutingContext filterContext) { using (var db = new UnboxedDbContext()) { object id; if (filterContext.ActionParameters.TryGetValue("id", out id)) { Guid idGuid; if (Guid.TryParse(id?.ToString(), out idGuid)) { if (db.Surveys.Any(s => s.ExternalId == idGuid)) { base.OnActionExecuting(filterContext); return; } } } // BAD PRACTICE ... altijd redirecten in een web omgeving, anders klopt de url niet meer! //filterContext.ActionParameters["id"] = db.Surveys.FirstOrDefault()?.ExternalId; //beter: filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", filterContext.ActionDescriptor.ControllerDescriptor.ControllerName }, { "action", filterContext.ActionDescriptor.ActionName }, { "id", db.Surveys.FirstOrDefault()?.ExternalId } }); } base.OnActionExecuting(filterContext); }
public virtual async Task <ActionResult> Index() { var db = new UnboxedDbContext(); var surveys = await db.Surveys .AsNoTracking() .ToListAsync(); var model = surveys.Select(s => new PanelModel() { Title = s.Title, Body = "Some random awesome description", ButtonText = "Resume", ButtonTarget = MVC.Survey.Index(s.ExternalId) }); return(View(model)); }
public MultipleChoiceController() { _db = new UnboxedDbContext(); }
public GetNextQuestionHandler() { _db = new UnboxedDbContext(); }
public YesNoController() { _db = new UnboxedDbContext(); }
public SurveyController() { _db = new UnboxedDbContext(); _dispatcher = new DefaultRequestDispatcher(); }
public CreateSurveyInstanceHandler() { _db = new UnboxedDbContext(); }