Exemple #1
0
 public void Insert(AssignmentTracker assignmentTracker)
 {
     using (var conn = new SqlConnection(Settings.ConnectionString))
     {
         string sql = "insert into AssignmentTracker (AssignmentId, RosterId, EarnedPoints) values (@AssignmentId, @RosterId, @EarnedPoints); select CAST(SCOPE_IDENTITY() as int)";
         assignmentTracker.Id = (int)conn.ExecuteScalar(sql, assignmentTracker);
     }
 }
Exemple #2
0
 public void Update(AssignmentTracker assignmentTracker)
 {
     using (var conn = new SqlConnection(Settings.ConnectionString))
     {
         string sql = "update AssignmentTracker set AssignmentId = @AssignmentId, RosterId = @RosterId, EarnedPoints = @EarnedPoints where Id = @Id";
         conn.Execute(sql, assignmentTracker);
     }
 }
        public AssignmentTracker PostGrade(AssignmentTracker at)
        {
            AssignmentTrackerRepo repo = new AssignmentTrackerRepo();

            if (at.Id == 0)
            {
                repo.Insert(at);
            }
            else
            {
                repo.Update(at);
            }
            return(at);
        }
Exemple #4
0
        protected override void Seed(ApplicationDbContext context)
        {
            // Don't want to redo this multiple times, only if we drop the database and need to re-seed
            if (new UserProfileRepo().GetAll().Any())
            {
                return;
            }

            CreateRole(context, "Admin");
            CreateRole(context, "Parent");
            CreateRole(context, "Student");
            CreateRole(context, "Teacher");

            string fakeTeacherId = CreateUser(context, "*****@*****.**", "password123", "Test", "Teacher", "Teacher", null);
            string fakeStudentId = CreateUser(context, "*****@*****.**", "password123", "Test", "Student", "Student", null);
            string fakeParentId  = CreateUser(context, "*****@*****.**", "password123", "Test", "Parent", "Parent", null);

            ParentStudentRepository psRepo = new ParentStudentRepository();

            psRepo.Add(fakeParentId, fakeStudentId);

            var algebra = new Course()
            {
                TeacherId         = fakeTeacherId,
                Name              = "Algebra 1",
                Department        = "Math",
                CourseDescription = "Math and math related stuff",
                StartDate         = DateTime.Today,
                EndDate           = DateTime.Today.AddDays(90)
            };

            var history = new Course()
            {
                TeacherId         = fakeTeacherId,
                Name              = "America",
                Department        = "Social Studies",
                CourseDescription = "lots of old people",
                StartDate         = DateTime.Today,
                EndDate           = DateTime.Today.AddDays(90)
            };

            CourseRepository      cRepo  = new CourseRepository();
            RosterRepository      rRepo  = new RosterRepository();
            AssignmentRepository  aRepo  = new AssignmentRepository();
            AssignmentTrackerRepo atRepo = new AssignmentTrackerRepo();

            cRepo.Insert(algebra);
            cRepo.Insert(history);

            List <string> moreStudentsIds = new List <string>();

            for (int i = 0; i < 50; i++)
            {
                string newStudentId = CreateUser(context, "fakestudent." + i + "@test.com", "password123", "Fake", "Student" + i, "Student", i % 13);
                moreStudentsIds.Add(newStudentId);

                if (i % 10 == 0)
                {
                    rRepo.Insert(new Roster()
                    {
                        CourseId = history.CourseId, IsActive = true, UserId = newStudentId
                    });
                }

                if (i % 8 == 0)
                {
                    rRepo.Insert(new Roster()
                    {
                        CourseId = algebra.CourseId, IsActive = true, UserId = newStudentId
                    });
                }
            }

            var rosterInfo = new Roster
            {
                CourseId = algebra.CourseId,
                UserId   = fakeStudentId,
                IsActive = true
            };

            rRepo.Insert(rosterInfo);

            var assignment = new Assignment
            {
                AssignmentDescription = "First Assignment Description",
                CourseId       = algebra.CourseId,
                DueDate        = DateTime.Now.AddDays(90),
                Name           = "First Assignment",
                PointsPossible = 45
            };

            aRepo.Insert(assignment);

            var assignment2 = new Assignment
            {
                AssignmentDescription = "Second Assignment Description",
                CourseId       = algebra.CourseId,
                DueDate        = DateTime.Now.AddDays(90),
                Name           = "Second Assignment",
                PointsPossible = 50
            };

            aRepo.Insert(assignment2);

            var grade = new AssignmentTracker
            {
                AssignmentId = assignment.AssignmentId,
                EarnedPoints = 40,
                RosterId     = rosterInfo.RosterId
            };

            atRepo.Insert(grade);

            var grade2 = new AssignmentTracker
            {
                AssignmentId = assignment2.AssignmentId,
                EarnedPoints = 47,
                RosterId     = rosterInfo.RosterId
            };

            atRepo.Insert(grade2);
        }
Exemple #5
0
 public static string Grade(AssignmentTracker at, Assignment a)
 {
     return(Grade(at.EarnedPoints, a.PointsPossible));
 }
Exemple #6
0
        public static string Percentage(AssignmentTracker at, Assignment a)
        {
            decimal pct = Percentage(at.EarnedPoints, a.PointsPossible);

            return(pct.ToString("0.0") + "%");
        }
Exemple #7
0
        public static ValidationData Validated(this INode node, ComputationContext ctx)
        {
            var evaluable = node as IEvaluable;

            if (evaluable != null && evaluable.Validation != null)
            {
                return(evaluable.Validation);
            }

            if (!ctx.AddVisited(node))
            {
                return(evaluable?.Validation);
            }

            ValidationData result = ValidationData.Create();

            INameRegistryExtension.CreateRegistry(INameRegistryExtension.EnterNode(node, ctx.ValAssignTracker),
                                                  ref ctx.ValAssignTracker, () => new AssignmentTracker());

            if (node is Loop)
            {
                ++ctx.ValLoopLevel;
            }


            {
                if (node is VariableDeclaration decl)
                {
                    ctx.ValAssignTracker?.Add(decl, ctx.ValLoopLevel);
                }
            }

            if (node is IExpression expr)
            {
                AssignmentTracker parent_tracker = ctx.ValAssignTracker;

                validateExecutionPath(node, expr.Flow.AlwaysPath, ctx, ref result);

                if (expr.Flow.ThenMaybePath != null || expr.Flow.ElseMaybePath != null)
                {
                    var branch_results = new List <ValidationData>();

                    foreach (ExecutionPath maybes in expr.Flow.ForkMaybePaths)
                    {
                        {
                            AssignmentTracker cont_tracker = null;
                            if (maybes == expr.Flow.ThenMaybePath)
                            {
                                cont_tracker = parent_tracker?.ThenBranch;
                            }
                            else if (maybes == expr.Flow.ElseMaybePath)
                            {
                                cont_tracker = parent_tracker?.ElseBranch;
                            }
                            ctx.ValAssignTracker = (cont_tracker ?? parent_tracker)?.Clone();
                        }
                        ValidationData branch_result = result.Clone();

                        validateExecutionPath(node, maybes, ctx, ref branch_result);

                        // time to remove "continue", because we are about to process
                        // step and post-check of the (could be) loop
                        if (node is IAnchor loop)
                        {
                            branch_result.RemoveInterruptionFor(loop, isBreak: false);
                        }

                        if (maybes == expr.Flow.ThenMaybePath && expr.Flow.ThenPostMaybes != null)
                        {
                            validateExecutionPath(node, expr.Flow.ThenPostMaybes, ctx, ref branch_result);
                        }

                        // we need to store the branch or kill it, because few lines below we compute intersection of the branches
                        // so we don't want to intersect with some artifact from the previous tracker
                        if (maybes == expr.Flow.ThenMaybePath)
                        {
                            parent_tracker.ThenBranch = branch_result.IsTerminated
                                ? null : (ctx.ValAssignTracker.ThenBranch ?? ctx.ValAssignTracker);
                        }
                        else if (maybes == expr.Flow.ElseMaybePath)
                        {
                            parent_tracker.ElseBranch = branch_result.IsTerminated
                                ? null : (ctx.ValAssignTracker.ElseBranch ?? ctx.ValAssignTracker);
                        }
                        else
                        {
                            throw new Exception();
                        }

                        branch_results.Add(branch_result);
                    }

                    if (expr.Flow.ExhaustiveMaybes)
                    {
                        parent_tracker?.MergeInitializations();
                    }
                    parent_tracker?.MergeAssigments();

                    result.Combine(branch_results);
                }

                ctx.ValAssignTracker = parent_tracker; // restore original tracker

                foreach (IExpression sub in expr.Flow.Enumerate)
                {
                    validateReadingValues(sub, ctx);
                }
            }


            node.ChildrenNodes.ForEach(it => Validated(it, ctx));

            if (node is IValidable verificable)
            {
                verificable.Validate(ctx);
            }

            if (node is IFunctionExit)
            {
                result.AddExit();
            }
            else if (node is LoopInterrupt loop_interrupt)
            {
                result.AddInterruption(loop_interrupt);
            }
            else if (node is IAnchor loop)
            {
                result.RemoveInterruptionFor(loop, isBreak: true);
            }
            else if (node is FunctionDefinition)
            {
                result = ValidationData.Create(); // clear it, function scope should not leak any info outside
            }
            if (evaluable != null)
            {
                evaluable.Validation = result;
            }

            ctx.RemoveVisited(node);

            return((node as IEvaluable)?.Validation);
        }