示例#1
0
        // GET: ToDoItems/Edit/5
        public async Task <ActionResult> Edit(int id)
        {
            var item = await _context.ToDoItem.FirstOrDefaultAsync(ti => ti.Id == id);

            var loggedInUser = await GetCurrentUserAsync();


            var ToDoStatuses = await _context.ToDoStatus
                               .Select(td => new SelectListItem()
            {
                Text = td.Status, Value = td.Id.ToString()
            })
                               .ToListAsync();

            var viewModel = new ToDoItemFormViewModel()
            {
                Id                = id,
                Title             = item.Title,
                ToDoStatusId      = item.ToDoStatusId,
                ToDoStatusOptions = ToDoStatuses,
            };

            if (item.ApplicationUserId != loggedInUser.Id)
            {
                return(NotFound());
            }

            return(View(viewModel));
        }
示例#2
0
        public async Task <ActionResult> Edit(int id, ToDoItemFormViewModel toDoViewItem)
        {
            try
            {
                var toDoItem = new ToDoItem()
                {
                    Id           = toDoViewItem.Id,
                    Title        = toDoViewItem.Title,
                    ToDoStatusId = toDoViewItem.ToDoStatusId
                };

                var user = await GetCurrentUserAsync();

                toDoItem.ApplicationUserId = user.Id;

                _context.ToDoItem.Update(toDoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View());
            }
        }
示例#3
0
        // GET: ToDoItems/Create
        public async Task <ActionResult> Create()
        {
            var ToDoStatuses = await _context.ToDoStatus
                               .Select(td => new SelectListItem()
            {
                Text = td.Status, Value = td.Id.ToString()
            })
                               .ToListAsync();

            var viewModel = new ToDoItemFormViewModel();

            viewModel.ToDoStatusOptions = ToDoStatuses;

            return(View(viewModel));
        }