コード例 #1
0
        private async Task <List <UserExerciseSubmission> > TryGetExerciseSubmissions(int count)
        {
            var notSoLongAgo = DateTime.Now - TimeSpan.FromMinutes(15);
            List <UserExerciseSubmission> submissions;

            using (var transaction = db.Database.BeginTransaction(IsolationLevel.Serializable))
            {
                submissions = db.UserExerciseSubmissions
                              .AsNoTracking()
                              .Where(s =>
                                     s.Timestamp > notSoLongAgo &&
                                     s.AutomaticChecking.Status == AutomaticExerciseCheckingStatus.Waiting)
                              .OrderByDescending(s => s.Timestamp)
                              .Take(count)
                              .ToList();
                foreach (var submission in submissions)
                {
                    submission.AutomaticChecking.Status = AutomaticExerciseCheckingStatus.Running;
                }
                await SaveAll(submissions.Select(s => s.AutomaticChecking));

                transaction.Commit();

                db.ObjectContext().AcceptAllChanges();
            }

            DateTime value;

            foreach (var submission in submissions)
            {
                unhandledSubmissions.TryRemove(submission.Id, out value);
            }

            return(submissions);
        }
コード例 #2
0
ファイル: UsersRepo.cs プロジェクト: epeshk/uLearn
        // ReSharper disable once MemberCanBePrivate.Global
        public IQueryable <UserIdWrapper> GetUsersByNamePrefix(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(db.Users.Select(u => new UserIdWrapper(u.Id)));
            }
            ;
            var splittedName  = name.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
            var nameQuery     = string.Join(" & ", splittedName.Select(s => "\"" + s.Trim().Replace("\"", "\\\"") + "*\""));
            var nameParameter = new ObjectParameter("name", nameQuery);

            return(db.ObjectContext().CreateQuery <UserIdWrapper>($"[{nameof(GetUsersByNamePrefix)}](@name)", nameParameter));
        }
コード例 #3
0
        private async Task TryUpdate(string userId, Guid slideId, string ltiRequestJson)
        {
            var ltiRequestModel = FindElement(userId, slideId);

            if (ltiRequestModel == null)
            {
                ltiRequestModel = new LtiSlideRequest
                {
                    UserId  = userId,
                    SlideId = slideId,
                    Request = ltiRequestJson
                };
            }
            else
            {
                ltiRequestModel.Request = ltiRequestJson;
            }

            db.LtiRequests.AddOrUpdate(ltiRequestModel);
            await db.ObjectContext().SaveChangesAsync(SaveOptions.DetectChangesBeforeSave);

            db.ObjectContext().AcceptAllChanges();
        }