Example #1
0
 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);
 }
Example #2
0
        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));
        }
Example #3
0
 public MultipleChoiceController()
 {
     _db = new UnboxedDbContext();
 }
Example #4
0
 public GetNextQuestionHandler()
 {
     _db = new UnboxedDbContext();
 }
Example #5
0
 public YesNoController()
 {
     _db = new UnboxedDbContext();
 }
Example #6
0
 public SurveyController()
 {
     _db         = new UnboxedDbContext();
     _dispatcher = new DefaultRequestDispatcher();
 }
Example #7
0
 public CreateSurveyInstanceHandler()
 {
     _db = new UnboxedDbContext();
 }