Beispiel #1
0
 protected abstract bool IsMovedToAnotherCategory(EntityPair <Course, TCourseParseModel> coursePair);
Beispiel #2
0
 protected abstract void AssignCategoryIdToDbEntity(EntityPair <Course, TCourseParseModel> coursePair);
Beispiel #3
0
        protected virtual ICollection <CourseAuthorBackup> DetectCourseAuthorChanges(EntityPair <Course, TCourseParseModel> coursePair, List <AuthorResolve> authorResolves)
        {
            var existingCourseAuthors = coursePair.DbEntity.CourseAuthors;

            var courseAuthorsParseResult = GetCourseAuthorsParseResult(coursePair.ParseModelEntity, authorResolves);

            AddFullnamesakeAuthorsToResolveList(courseAuthorsParseResult.FullnamesakeAuthors);
            AddNullUrlAuthorsToResolveList(courseAuthorsParseResult.NullUrlAuthors);

            var processingCourseAuthorsDictionary = courseAuthorsParseResult.ValidAuthors
                                                    .ToDictionary(x => x, x => x, CourseAuthor.IdentityComparer);

            var courseAuthorsBackup = new List <CourseAuthorBackup>();

            foreach (var existingCourseAuthor in existingCourseAuthors)
            {
                CourseAuthor processingCourseAuthor;
                if (processingCourseAuthorsDictionary.TryGetValue(existingCourseAuthor, out processingCourseAuthor))
                {
                    if (existingCourseAuthor.IsAuthorCoAuthor != processingCourseAuthor.IsAuthorCoAuthor)
                    {
                        // modify
                        courseAuthorsBackup.Add(new CourseAuthorBackup
                        {
                            UpdateEventId      = UpdateEvent.Id,
                            TrainingProviderId = TrainingProviderId,
                            CourseId           = existingCourseAuthor.CourseId,
                            AuthorId           = existingCourseAuthor.AuthorId,
                            IsAuthorCoAuthor   = existingCourseAuthor.IsAuthorCoAuthor,
                            OperationType      = OperationType.Modify
                        });

                        existingCourseAuthor.IsAuthorCoAuthor = processingCourseAuthor.IsAuthorCoAuthor;
                    }

                    // restore author
                    existingCourseAuthor.IsDeleted = false;

                    processingCourseAuthorsDictionary.Remove(existingCourseAuthor);
                }
                else
                {
                    // remove
                    if (existingCourseAuthor.IsDeleted)
                    {
                        continue;
                    }

                    courseAuthorsBackup.Add(new CourseAuthorBackup
                    {
                        UpdateEventId      = UpdateEvent.Id,
                        TrainingProviderId = TrainingProviderId,
                        CourseId           = existingCourseAuthor.CourseId,
                        AuthorId           = existingCourseAuthor.AuthorId,
                        OperationType      = OperationType.Delete
                    });

                    existingCourseAuthor.IsDeleted = true;
                }
            }

            foreach (var newCourseAuthor in processingCourseAuthorsDictionary.Values)
            {
                // add
                courseAuthorsBackup.Add(new CourseAuthorBackup
                {
                    UpdateEventId      = UpdateEvent.Id,
                    TrainingProviderId = TrainingProviderId,
                    CourseId           = newCourseAuthor.CourseId,
                    AuthorId           = newCourseAuthor.AuthorId,
                    OperationType      = OperationType.Add
                });

                existingCourseAuthors.Add(newCourseAuthor);
            }


            return(courseAuthorsBackup);
        }