Esempio n. 1
0
 protected async Task LoadChaptersAsync(StoryListModel story)
 {
     if (story.Chapters > 0 && !Chapters.ContainsKey(story.Id))
     {
         Chapters[story.Id] = await Api.GetStoryChapterListAsync(story.Id);
     }
 }
Esempio n. 2
0
        public async Task <ActionResult <List <StoryListModel> > > GetList()
        {
            string userId = HttpContext.User.FindUserId();

            if (userId == null)
            {
                return(Unauthorized());
            }

            List <Story> entities = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Stories, userId)
                                    .OrderByDescending(s => s.Order)
                                    .ToListAsync();

            List <StoryListModel> models = new List <StoryListModel>();

            foreach (Story entity in entities)
            {
                var model = new StoryListModel();
                models.Add(model);

                MapEntityToModel(entity, model);

                int chapters = await db.Stories
                               .Where(s => s.Id == entity.Id)
                               .SelectMany(s => s.Chapters)
                               .CountAsync();

                int entries = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Entries, userId)
                              .Where(e => e.Story.Id == entity.Id || e.Chapter.Story.Id == entity.Id)
                              .CountAsync();

                model.Chapters = chapters;
                model.Entries  = entries;

                if (entries > 0)
                {
                    DateTime minDate = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Entries, userId)
                                       .Where(e => e.Story.Id == entity.Id || e.Chapter.Story.Id == entity.Id)
                                       .MinAsync(e => e.When);

                    DateTime maxDate = await shareStatus.OwnedByOrExplicitlySharedWithUser(db, db.Entries, userId)
                                       .Where(e => e.Story.Id == entity.Id || e.Chapter.Story.Id == entity.Id)
                                       .MaxAsync(e => e.When);

                    model.MinDate = minDate;
                    model.MaxDate = maxDate;
                }
            }

            var userNames = await this.userNames.GetUserNamesAsync(models.Select(e => e.UserId).ToArray());

            for (int i = 0; i < models.Count; i++)
            {
                models[i].UserName = userNames[i];
            }

            return(Ok(models));
        }
Esempio n. 3
0
        protected void Select(StoryListModel story, StoryChapterListModel chapter)
        {
            Hide();

            if (Selected != null)
            {
                Selected(new EntryStoryModel()
                {
                    StoryId      = story?.Id,
                    StoryTitle   = story?.Title,
                    ChapterId    = chapter?.Id,
                    ChapterTitle = chapter?.Title
                });
            }
        }
Esempio n. 4
0
        public ActionResult List(
            string createdDate,
            string description,
            string isArchived,
            string isCompleted,
            string isOpened,
            string modifiedDate,
            int?projectId,
            string projectName,
            int?statusId,
            string statusName,
            int?storyId,
            int?userId,
            string userName)
        {
            var model    = new StoryListModel();
            var criteria = new StoryDataCriteria
            {
                AssignedTo     = userId,
                AssignedToName = userName,
                CreatedDate    = CriteriaHelper.ToDateRangeCriteria(createdDate),
                Description    = description,
                IsArchived     = CriteriaHelper.ToBoolean(isArchived),
                IsCompleted    = CriteriaHelper.ToBoolean(isCompleted),
                IsOpened       = CriteriaHelper.ToBoolean(isOpened),
                ModifiedDate   = CriteriaHelper.ToDateRangeCriteria(modifiedDate),
                ProjectId      = CriteriaHelper.ToArray(projectId),
                ProjectName    = projectName,
                StoryId        = storyId,
                StatusId       = statusId,
                StatusName     = statusName
            };
            var stories = StoryRepository.StoryFetchInfoList(criteria);

            model.Stories = stories;

            return(this.View(model));
        }
Esempio n. 5
0
 private void MapEntityToModel(Story entity, StoryListModel model)
 {
     model.Id     = entity.Id;
     model.UserId = entity.UserId;
     model.Title  = entity.Title;
 }