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); }
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()); }
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())); } }
public NewTodoItemViewModelTest() { _target = new NewTodoItemViewModel(CreateDbContext); }
public NewTodoItemView(NewTodoItemViewModel viewModel) { InitializeComponent(); viewModel.Navigation = Navigation; BindingContext = viewModel; }