Beispiel #1
0
        public async Task SetNotificationTransportSettingsAsync(string courseId, int transportId, NotificationType type, bool isEnabled)
        {
            var settings = db.NotificationTransportSettings.FirstOrDefault(
                s => s.CourseId == courseId && s.NotificationTransportId == transportId && s.NotificationType == type
                );

            if (settings == null)
            {
                settings = new NotificationTransportSettings
                {
                    CourseId = courseId,
                    NotificationTransportId = transportId,
                    NotificationType        = type,
                    IsEnabled = isEnabled,
                };
            }
            else
            {
                settings.IsEnabled = isEnabled;
            }


            db.AddOrUpdate(settings, s => s.Id == settings.Id);
            await db.SaveChangesAsync();
        }
Beispiel #2
0
        private async Task SaveAutomaticExerciseChecking(AutomaticExerciseChecking checking)
        {
            log.Info($"Обновляю статус автоматической проверки #{checking.Id}: {checking.Status}");
            db.AddOrUpdate(checking, c => c.Id == checking.Id);
            await UpdateIsRightAnswerForSubmission(checking);

            await db.SaveChangesAsync();
        }
Beispiel #3
0
        protected async Task SaveAll(IEnumerable <AutomaticExerciseChecking> checkings)
        {
            foreach (var checking in checkings)
            {
                log.Info($"Обновляю статус автоматической проверки #{checking.Id}: {checking.Status}");
                db.AddOrUpdate(checking, c => c.Id == checking.Id);
                await UpdateIsRightAnswerForSubmission(checking);
            }

            await db.SaveChangesAsync();
        }
Beispiel #4
0
        public async Task <TextBlob> AddText(string text)
        {
            if (text == null)
            {
                return new TextBlob
                       {
                           Hash = null,
                           Text = null
                       }
            }
            ;

            if (text.Length > MaxTextSize)
            {
                text = text.Substring(0, MaxTextSize);
            }

            if (text.Contains('\0'))
            {
                text = text.Replace("\0", "");                 // postgres не поддерживает \0 в строках
            }
            var hash = GetHash(text);
            var blob = await db.Texts.FindAsync(hash);

            if (blob != null)
            {
                return(blob);
            }

            blob = new TextBlob
            {
                Hash = hash,
                Text = text
            };
            db.AddOrUpdate(blob, b => b.Hash == hash);

            try
            {
                await db.SaveChangesAsync().ConfigureAwait(false);
            }
            catch (DbUpdateException)
            {
                // It's ok, just tried to insert text with hash which already exists, try to find it
                if (!db.Texts.AsNoTracking().Any(t => t.Hash == hash))
                {
                    throw;
                }
                db.Entry(blob).State = EntityState.Unchanged;
            }

            return(blob);
        }
Beispiel #5
0
        public async Task <TextBlob> AddText(string text)
        {
            if (text == null)
            {
                return new TextBlob
                       {
                           Hash = null,
                           Text = null
                       }
            }
            ;

            if (text.Length > MaxTextSize)
            {
                text = text.Substring(0, MaxTextSize);
            }

            var hash = GetHash(text);
            var blob = db.Texts.Find(hash);

            if (blob != null)
            {
                return(blob);
            }

            blob = new TextBlob
            {
                Hash = hash,
                Text = text
            };
            db.AddOrUpdate(blob, b => b.Hash == hash);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                // It's ok, just tried to insert text with hash which already exists, try to find it
                if (!db.Texts.AsNoTracking().Any(t => t.Hash == hash))
                {
                    throw;
                }
                db.Entry(blob).State = EntityState.Unchanged;
            }
            return(blob);
        }
Beispiel #6
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.AddOrUpdate(ltiRequestModel, r => r.RequestId == ltiRequestModel.RequestId);
            await db.SaveChangesAsync();
        }
Beispiel #7
0
        private Task TryUpdate(string courseId, Guid slideId, string userId, string ltiRequestJson)
        {
            var ltiRequestModel = FindElement(courseId, slideId, userId);

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

            db.AddOrUpdate(ltiRequestModel, r => r.RequestId == ltiRequestModel.RequestId);
            return(db.SaveChangesAsync());
        }