Example #1
0
        public async Task <IActionResult> PostChat(ClientPageDetailsViewModel viewModel)
        {
            var currentUser = await GetCurrentUserAsync();

            var chat = new Chat()
            {
                Text         = viewModel.ChatText,
                StoryBoardId = viewModel.StoryBoardId,
                UserId       = currentUser.Id,
                Timestamp    = DateTime.Now
            };

            if (ModelState.IsValid)
            {
                _context.Add(chat);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("Details", new { Id = viewModel.ClientPage.Id }));
        }
Example #2
0
        // GET: ClientPages/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            var clientPage = await _context.ClientPages
                             .Include(m => m.StoryBoards)
                             .FirstOrDefaultAsync(m => m.Id == id);

            var orderedStoryBoards = await _context.StoryBoards
                                     .Include(sb => sb.Chats)
                                     .ThenInclude(c => c.User)
                                     .OrderBy(sb => sb.PostDateTime)
                                     .Where(sb => sb.ClientPageId == clientPage.Id)
                                     .ToListAsync();

            var assignedUsers = await _context.ClientPageUsers
                                .Include(cpu => cpu.User)
                                .Where(cpu => cpu.ClientPageId == id)
                                .Select(cpu => cpu.User)
                                .ToListAsync();



            clientPage.StoryBoards = orderedStoryBoards;
            clientPage.Users       = assignedUsers;

            var viewModel = new ClientPageDetailsViewModel()
            {
                ClientPage = clientPage,
            };

            if (clientPage == null)
            {
                return(NotFound());
            }
            return(View(viewModel));
        }