Пример #1
0
        public YourChallenge( int challengeId, int userId )
        {
            Entities db = new Entities();
            Challenge = db.Challenges.SingleOrDefault( c => c.Id == challengeId );

            List<YourProblem> yourProblems = new List<YourProblem>();

            IEnumerable<model.Problem> problems = db.Problems.Where( p => p.ChallengeId == challengeId ).OrderBy( p => p.Order );

            foreach ( model.Problem p in problems )
            {
                YourProblem problem = new YourProblem( p, userId );
                yourProblems.Add( problem );
            }

            Problems = yourProblems;

            NumberOfProblem = yourProblems.Count();

            // Count number of solved problem
            NumberOfSolvedProblem = 0;
            foreach ( YourProblem problem in yourProblems )
            {
                if ( problem.Status == SolvingStatus.RESOLVED )
                    NumberOfSolvedProblem++;
            }

            // Get start time
            YourProblem firstProblem = yourProblems[ 0 ];
            Solving firstSolving = db.Solvings.SingleOrDefault( s => s.ProblemId == firstProblem.Problem.Id && s.UserId == userId );
            if ( firstSolving != null )
                StartTime = firstSolving.FirstOpenTime;

            // Get end time
            int lastSolvedProblemIndex = NumberOfProblem - 1;
            while ( yourProblems[ lastSolvedProblemIndex ].Status != SolvingStatus.RESOLVED && lastSolvedProblemIndex > 0 )
                lastSolvedProblemIndex--;

            // First correct submission
            int lastSolvedProblemId = yourProblems[ lastSolvedProblemIndex ].Problem.Id;
            Solving lastCorrectSolving = db.Solvings.SingleOrDefault( s => s.ProblemId == lastSolvedProblemId && s.UserId == userId );
            if ( lastCorrectSolving != null )
            {
                IList<Submission> submissions = lastCorrectSolving.Submissions.OrderByDescending( s => s.Result ).ThenBy( s => s.Time ).ToList();
                if ( submissions != null && submissions.Count > 0 )
                {
                    CorrectTime = submissions.ToList()[ 0 ].Time;
                }
            }
        }
Пример #2
0
        public YourProblem( Problem problem, int userId )
        {
            Entities db = new Entities();

            Problem = problem;

            CanOpen = Security.CanOpen( problem.Id, userId );
            CanSubmit = Security.CanSubmit( problem.Id, userId );

            Solving solving = db.Solvings.SingleOrDefault( s => s.ProblemId == problem.Id && s.UserId == userId );

            if ( solving == null )
            {
                Status = SolvingStatus.NOT_OPEN;
                return;
            }

            FirstAttempt = solving.FirstOpenTime;
            LastAttempt = solving.LastOpenTime;

            Submissions = db.Submissions.Where( s => s.SolvingId == solving.Id ).OrderByDescending( s => s.Time );

            if ( Submissions == null || Submissions.Count() == 0 )
            {
                Status = SolvingStatus.NOT_SUBMIT;
                return;
            }

            Submission firstResolved = Submissions.FirstOrDefault( s => s.Result != null && s.Result != 0 );

            if ( firstResolved == null )
                Status = SolvingStatus.NOT_RESOLVED;
            else
            {
                Status = SolvingStatus.RESOLVED;
                FirstResolved = firstResolved.Time;
            }
        }
Пример #3
0
        private void SetUserIdToSession( string username )
        {
            Entities db = new Entities();
            UserProfile user = db.UserProfiles.Single( u => u.UserName.Equals( username ) );

            if ( user != null )
            {
                Session[ Constants.SESSION_USER_ID ] = user.UserId;
            }
        }
Пример #4
0
 static TimeZoneUtil()
 {
     dbContext = new Entities();
     Setting settings = dbContext.Settings.SingleOrDefault( s => s.Key.ToLower().Equals( "timezone" ) );
     timeZoneId = settings.Value;
 }
Пример #5
0
        public ActionResult Register( RegisterModel model )
        {
            if ( ModelState.IsValid )
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount( model.UserName, model.Password );
                    WebSecurity.Login( model.UserName, model.Password );

                    Entities dbContext = new Entities();
                    UserProfile userProfile = dbContext.UserProfiles.SingleOrDefault( u => u.UserName.Equals( model.UserName ) );

                    userProfile.FullName = model.FullName;
                    userProfile.Email = model.Email;
                    userProfile.Company = model.Company;

                    dbContext.Entry( userProfile ).State = System.Data.EntityState.Modified;
                    dbContext.SaveChanges();

                    Roles.AddUserToRole( model.UserName, "Contestant" );

                    SetUserIdToSession( model.UserName );

                    return RedirectToAction( "Index", "Home" );
                }
                catch ( MembershipCreateUserException e )
                {
                    ModelState.AddModelError( "", ErrorCodeToString( e.StatusCode ) );
                }
            }

            // If we got this far, something failed, redisplay form
            return View( model );
        }