예제 #1
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var todo = await _context.Todos
                       .Include(x => x.PersonInCharge)
                       .Include(x => x.Comments)
                       .ThenInclude(x => x.User)
                       .Include(x => x.Participants)
                       .SingleOrDefaultAsync(x => x.Id == id);

            if (todo == null)
            {
                return(NotFound());
            }

            var users = await _userServices.GetAllUsers();

            var userIdsInTodo  = todo.Participants.Select(x => x.UserId);
            var usersInTodo    = users.Where(x => userIdsInTodo.Contains(x.Id));
            var usersNotInTodo = users.Except(usersInTodo);

            ApplicationUser currentUser = await _userManager.GetUserAsync(User);

            ViewBag.UserId = currentUser.Id;

            var medias = await _context.Medias
                         .Where(x => x.TodoId == id)
                         .ToListAsync();

            var todoListFileModels = _mapper.Map <List <TodoListFileModel> >(medias);

            foreach (var item in todoListFileModels)
            {
                var matchedMedia = medias.SingleOrDefault(x => x.Id == item.Id);

                item.FileName      = Path.GetFileNameWithoutExtension(matchedMedia.Location);
                item.FileExtension = Path.GetExtension(matchedMedia.Location);
            }

            TodoDetailViewModel viewModel = new TodoDetailViewModel
            {
                TodoId         = todo.Id,
                TodoInfo       = _mapper.Map <TodoViewModel>(todo),
                AllUsers       = _mapper.Map <List <UserViewModel> >(users),
                Participants   = _mapper.Map <List <UserViewModel> >(usersInTodo),
                UsersNotInTodo = _mapper.Map <List <UserViewModel> >(usersNotInTodo),
                ListFiles      = todoListFileModels
            };

            return(View(viewModel));
        }
예제 #2
0
        public TodoDetailPage()
        {
            InitializeComponent();

            var item = new ToDoApp.Models.Todo
            {
                Name        = "Item 1",
                Description = "This is an item description."
            };

            viewModel      = new TodoDetailViewModel(item);
            BindingContext = viewModel;
        }
예제 #3
0
        public TodoDetailPage(TodoDetailViewModel viewModel)
        {
            InitializeComponent();

            BindingContext = this.viewModel = viewModel;
        }