Exemplo n.º 1
0
        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]));
            });
        }
Exemplo n.º 2
0
 private void DoDone()
 {
     if (_mode == Mode.Adding)
     {
         _dataService.AddItem(Item);
     }
     else
     {
         _dataService.UpdateItem(Item);
     }
     Close(this);
 }
Exemplo n.º 3
0
        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());
            }
        }
Exemplo n.º 4
0
 public ObservableCollection <Task> AddItem(Task newTask)
 {
     service.AddItem(newTask);
     todoList.Add(newTask);
     return(todoList);
 }
 private void DoDone()
 {
     _dataService.AddItem(Item);
     Close(this);
 }