コード例 #1
0
        public async Task <bool> AddItemAsync(NewTodoItemViewModel newItem, ApplicationUser user)
        {
            TodoItem item = new TodoItem()
            {
                Id      = Guid.NewGuid(),
                IsDone  = false,
                Title   = newItem.Title,
                DueAt   = DateTimeOffset.UtcNow.AddDays(3),
                OwnerId = user.Id
            };

            _context.Items.Add(item);

            int saveResult = await _context.SaveChangesAsync();

            return(saveResult == 1);
        }
コード例 #2
0
        public async Task <IActionResult> AddItem(NewTodoItemViewModel newItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ApplicationUser currentUser = await _userManager.GetUserAsync(User);

            if (currentUser == null)
            {
                return(Challenge());
            }
            bool sucessful = await _todoItemService.AddItemAsync(newItem, currentUser);

            if (!sucessful)
            {
                return(BadRequest(new { error = "Could not add item" }));
            }
            return(Ok());
        }
コード例 #3
0
        public MainWindow()
        {
            InitializeComponent();

            if (!DesignerProperties.GetIsInDesignMode(this))
            {
                using (var dbContext = new TodoDbContext())
                {
                    dbContext.Database.Migrate();
                }

                var newTodoItemViewModel = new NewTodoItemViewModel(() => new TodoDbContext());
                NewTodoItemView.DataContext = newTodoItemViewModel;
                var showTodoListViewModel = new ShowTodoListViewModel(() => new TodoDbContext());
                ShowTodoListView.DataContext = showTodoListViewModel;

                showTodoListViewModel.Observe(newTodoItemViewModel);
                showTodoListViewModel.Initialize();

                Resources.Add("RemoveTodoItemCommand", new RemoveTodoItemCommand(() => new TodoDbContext()));
            }
        }
コード例 #4
0
 public NewTodoItemViewModelTest()
 {
     _target = new NewTodoItemViewModel(CreateDbContext);
 }
コード例 #5
0
 public NewTodoItemView(NewTodoItemViewModel viewModel)
 {
     InitializeComponent();
     viewModel.Navigation = Navigation;
     BindingContext       = viewModel;
 }