public MainViewModel(IDataService dataService) { _book = new ViewBooks(); Books = new ObservableCollection <ViewBooks>(dataService.ConvertItem <ViewBooks>(dataService.GetItems)); _index = 0; _dataService = dataService; Add = new RelayCommand(() => { var add = GetClone(_book); Books.Add(add); var InsertItem = _dataService.ConvertItem <ViewBooks>(add); _dataService.AddItem(InsertItem); add.Id = InsertItem.Id; }); Remove = new RelayCommand(() => { if (_index < Books.Count && _index >= 0) { _dataService.RemoveItem(_dataService.ConvertItem <ViewBooks>(Books[Index])); Books.RemoveAt(Index); } }); Modify = new RelayCommand(() => { GetClone(Book, Books[Index]); _dataService.ModifyItem(_dataService.ConvertItem(Books[Index])); }); }
private void DoDone() { if (_mode == Mode.Adding) { _dataService.AddItem(Item); } else { _dataService.UpdateItem(Item); } Close(this); }
public async Task <ActionResult> Create(TEntry entry) { try { if (ModelState.IsValid) { var item = await dataService.AddItem(entry); return(RedirectToAction(nameof(Index), new { id = item.Id })); } else { return(View(entry)); } } catch { return(View()); } }
public ObservableCollection <Task> AddItem(Task newTask) { service.AddItem(newTask); todoList.Add(newTask); return(todoList); }
private void DoDone() { _dataService.AddItem(Item); Close(this); }