public ReadingCategory <ReadingWord> AddNewWordCategory(string programId = "program Id",
                                                                string name      = "My category")
        {
            var dto = new ReadingCategoryDTO <ReadingWordDTO>()
            {
                ProgramId      = programId,
                Title          = name,
                ActivityStatus = new ActivityStatusDTO
                {
                    Type         = ActivityStatusType.Planned,
                    SortingIndex = 1
                },
                Cards = new []
                {
                    new ReadingWordDTO {
                        Text = "Word 1"
                    }
                }
            };
            var session = DocumentStore.OpenSession();

            session.Store(dto);
            session.SaveChanges();
            WaitOfIndexesInDocumentStore();

            var category = dto.ToCategory();

            return(category);
        }
        public static ReadingCategory <ReadingWord> ToCategory(this ReadingCategoryDTO <ReadingWordDTO> dto)
        {
            var category = new ReadingCategory <ReadingWord>(dto.Id, dto.Title,
                                                             dto.Cards.Select(x => x.ToReadingWord()),
                                                             dto.ActivityStatus.ToStatus(),
                                                             dto.Sessions.Select(s => new ActivitySession(s.ChildId, s.DateTime)));

            return(category);
        }
        public static ReadingCategoryDTO <ReadingWordDTO> ToDTO(this ReadingCategory <ReadingWord> category, string programId)
        {
            var dto = new ReadingCategoryDTO <ReadingWordDTO>
            {
                ProgramId      = programId,
                Title          = category.Title,
                Cards          = category.ReadingCards.Select(x => x.ToDTO()),
                ActivityStatus = category.ActivityStatus.ToDTO(),
                Sessions       = category.CompletedSessions.Select(x => new ActivitySessionDTO {
                    ChildId = x.ChildId, DateTime = x.DateStamp
                }).ToList()
            };

            return(dto);
        }
        private async Task ChangeSortIndex(int toSpot, ReadingCategoryDTO <ReadingWordDTO> dto)
        {
            if (toSpot < 0)
            {
                await SetSortIndexToLast(dto);
            }

            if (toSpot == 0)
            {
                await SetSortIndexToFirst(dto);
            }

            if (toSpot > 0)
            {
                await UpdateSortIndex(toSpot, dto);
            }

            await SaveChanges();
        }