Ejemplo n.º 1
0
 private void ExecuteUpdateItemCommand(ViewModels.TodoItemViewModel item)
 {
     try
     {
         TodoItemRepository.GetForToDoListId(TodoList.Id).UpdateItem(item.TodoItem.Id, item.TodoItem);
     }
     catch { }
 }
Ejemplo n.º 2
0
 private void ExecuteAddCommand(string title)
 {
     try
     {
         var index = this.Items.IndexOf(this.SelectedItem);
         var item = new ViewModels.TodoItemViewModel(_todoItemRepository.Factory(title: title));
         this.TodoList.Items.Insert((index > -1) ? index : 0, item.TodoItem);
         this.Items.Insert((index > -1) ? index : 0, item);
         this.SelectedItem = item;
     }
     catch { this.SelectedItem = null; }
 }
Ejemplo n.º 3
0
 private void ExecuteAddCommand(string title)
 {
     try
     {
         var index = this.Items.IndexOf(this.SelectedItem);
         var item  = new ViewModels.TodoItemViewModel(_todoItemRepository.Factory(title: title));
         this.TodoList.Items.Insert((index > -1) ? index : 0, item.TodoItem);
         this.Items.Insert((index > -1) ? index : 0, item);
         this.SelectedItem = item;
     }
     catch { this.SelectedItem = null; }
 }
Ejemplo n.º 4
0
        private async void ExecuteAddItemCommand(string title)
        {
            try
            {
                var item = _todoItemRepository.Factory(title: title);
                await _todoItemRepository.InsertTodoItem(item);

                var itemVM = new ViewModels.TodoItemViewModel(item);
                var index  = this.ItemVMs.IndexOf(this.SelectedItem);
                this.ItemVMs.Insert((index > -1) ? index : 0, itemVM);
                this.SelectedItem = itemVM;
            }
            catch { this.SelectedItem = null; }
        }
Ejemplo n.º 5
0
 //单例模式
 public static TodoItemViewModel GetInstance()
 {
     /*   if (viewmodel == null)
      * {
      *     //创建两个例子
      *     viewmodel = new TodoItemViewModel();
      *     BitmapImage bitmapImage_1 = new BitmapImage();
      *     bitmapImage_1.UriSource = new Uri("ms-appx:///Assets/background.jpg");
      *     viewmodel.allItem.Add(new Models.TodoItem(bitmapImage_1, "Todolist_1", "Hello world !", DateTime.Today));
      *     var db = new SQLiteConnection("demo.db");
      *     string sql = @"INSERT INTO Todoitem(Image,Title,Description,Date) VALUES (?,?,?,?);";
      *     using (var todoitem = db.Prepare(sql))
      *     {
      *         todoitem.Bind(1, bitmapImage_1.ToString());
      *         todoitem.Bind(2, "Todolist_1");
      *         todoitem.Bind(3, "Hello world !");
      *         todoitem.Bind(4, DateTime.Today.ToString());
      *         todoitem.Step();
      *     }
      *
      * }*/
     // else
     //  {
     using (var db = new SQLiteConnection("demo.db"))
     {
         viewmodel = new TodoItemViewModel();
         string sql = @"SELECT Image,Title,Description,Date FROM Todoitem;";
         using (var statement = db.Prepare(sql))
         {
             while (SQLiteResult.ROW == statement.Step())
             {
                 BitmapImage bitmapImage_1 = new BitmapImage();
                 if ((string)statement[0] == null)
                 {
                     bitmapImage_1.UriSource = new Uri("ms-appx:///Assets/bar.jpg");
                 }
                 else
                 {
                     bitmapImage_1.UriSource = new Uri((string)statement[0]);
                 }
                 viewmodel.allItem.Add(new Models.TodoItem(bitmapImage_1, (string)statement[1], (string)statement[2], (DateTimeOffset.Parse((string)statement[3]))));
             }
         }
     }
     // }
     return(viewmodel);
 }
Ejemplo n.º 6
0
        private async void ExecuteAddItemFromImageCommand(StorageFile file)
        {
            Busy = true;
            try
            {
                var item = _todoItemRepository.Factory(title: "New Item From Image");
                await _todoItemRepository.InsertTodoItem(item);

                var itemVM = new ViewModels.TodoItemViewModel(item);
                var index  = this.ItemVMs.IndexOf(this.SelectedItem);
                this.ItemVMs.Insert((index > -1) ? index : 0, itemVM);
                itemVM.SavePictureCommand.Execute(file);
                this.SelectedItem = itemVM;
            }
            catch { this.SelectedItem = null; }
            Busy = false;
        }
Ejemplo n.º 7
0
        public async Task <Dictionary <int, TodoItemViewModel> > LoadAsync(uint start, int size)
        {
            // constrain to count
            size = (int)start + size;
            if (size > Count)
            {
                size = Count;
            }

            var dictionary = new Dictionary <int, TodoItemViewModel>();

            foreach (var index in Enumerable.Range((int)start, size))
            {
                // fake delay for demo
                await Task.Delay(10);

                // fake data for demo
                var model     = _repository.Sample(1).First();
                var viewmodel = new ViewModels.TodoItemViewModel(model);
                dictionary.Add(index, viewmodel);
            }
            return(dictionary);
        }
Ejemplo n.º 8
0
 private bool CanExecuteUpdateItemCommand(ViewModels.TodoItemViewModel item)
 {
     return(true);
 }
Ejemplo n.º 9
0
        private async void ExecuteAddItemCommand(string title)
        {
            try
            {
                var item = _todoItemRepository.Factory(title: title);
                await _todoItemRepository.InsertTodoItem(item);

                var itemVM = new ViewModels.TodoItemViewModel(item);
                var index = this.ItemVMs.IndexOf(this.SelectedItem);
                this.ItemVMs.Insert((index > -1) ? index : 0, itemVM);
                this.SelectedItem = itemVM;
            }
            catch { this.SelectedItem = null; }
        }
Ejemplo n.º 10
0
        private async void ExecuteAddItemFromImageCommand(StorageFile file)
        {
            Busy = true;
            try
            {
                var item = _todoItemRepository.Factory(title: "New Item From Image");
                await _todoItemRepository.InsertTodoItem(item);

                var itemVM = new ViewModels.TodoItemViewModel(item);
                var index = this.ItemVMs.IndexOf(this.SelectedItem);
                this.ItemVMs.Insert((index > -1) ? index : 0, itemVM);
                itemVM.SavePictureCommand.Execute(file);
                this.SelectedItem = itemVM;
            }
            catch { this.SelectedItem = null; }
            Busy = false;
        }