public ActionResult Edit(TodoItemViewModel tvm)
        {
            TodoClient tc = new TodoClient();

            tc.Edit(tvm.todoItem);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        private async void NewTodoTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox       newTodoTextBox = (TextBox)sender;
            TodoListModel todoList       = GetDataContext <TodoListModel>(sender);

            if (!String.IsNullOrWhiteSpace(newTodoTextBox.Text))
            {
                HttpResult <TodoItem> result;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    result = await todoClient.AddTodoItemAsync(new TodoItem()
                    {
                        TodoListId = todoList.TodoListId, Title = newTodoTextBox.Text
                    });
                }

                if (result.Succeeded)
                {
                    todoList.Todos.Add(new TodoItemModel(result.Content)
                    {
                        TodoList = todoList
                    });
                }
                else
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
            newTodoTextBox.Text = "Add New Todo";
        }
        public ActionResult Delete(int id)
        {
            TodoClient tc = new TodoClient();

            tc.Delete(id);
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit(int id)
        {
            TodoClient        tc  = new TodoClient();
            TodoItemViewModel tvm = new TodoItemViewModel();

            tvm.todoItem = tc.find(id);
            return(View("Edit", tvm));
        }
 public HomeController(ILogger <HomeController> logger,
                       TodoClient todoClient,
                       IHttpClientFactory httpClientFactory,
                       IOperationScoped operationScoped)
 {
     _logger            = logger;
     _todoClient        = todoClient;
     _httpClientFactory = httpClientFactory;
     _operationScoped   = operationScoped;
 }
        // GET: TodoItem
        public ActionResult Index()
        {
            TodoClient tc = new TodoClient();

            if (tc != null)
            {
                ViewBag.listTodo = tc.findAll();
            }


            return(View());
        }
Exemplo n.º 7
0
        static async Task Main(string[] args)
        {
            System.Console.WriteLine("Hello OData!");

            client = new TodoClient(URL);

            await Seed();
            await ListTodos();
            await Update();
            await ListTodos();
            await Delete();
            await ListTodos();

            System.Console.WriteLine("\nDone");
        }
Exemplo n.º 8
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            TodoPageModel.TodoLists.Clear();
            HttpResult <UserInfo> userInfoResult;

            using (AccountClient accountClient = ClientFactory.CreateAccountClient())
            {
                userInfoResult = await accountClient.GetUserInfoAsync();
            }

            if (userInfoResult.Succeeded)
            {
                UserInfo userInfo = userInfoResult.Content;
                TodoPageModel.Username = String.Format("{0}", userInfo.UserName);

                HttpResult <TodoList[]> todoListResult;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    todoListResult = await todoClient.GetTodoListsAsync();
                }

                if (todoListResult.Succeeded)
                {
                    if (todoListResult.Content.Length == 0)
                    {
                        this.NavigationService.Navigate(AddTodoListPage.GetNavigationUri());
                    }
                    else
                    {
                        foreach (TodoList todoList in todoListResult.Content)
                        {
                            TodoPageModel.TodoLists.Add(new TodoListModel(todoList));
                        }
                    }
                }
                else
                {
                    ErrorDialog.ShowErrors(todoListResult.Errors);
                }
            }
            else
            {
                ErrorDialog.ShowErrors(userInfoResult.Errors);
            }
        }
Exemplo n.º 9
0
        private async void TodoListTitleTextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox       todoListTitleTextBox = (TextBox)sender;
            TodoListModel todoList             = GetDataContext <TodoListModel>(sender);

            string newTitle = todoListTitleTextBox.Text;

            if (newTitle != todoList.OriginalTitle)
            {
                HttpResult result;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    if (String.IsNullOrWhiteSpace(newTitle))
                    {
                        result = await todoClient.DeleteTodoListAsync(todoList.TodoListId);

                        if (result.Succeeded)
                        {
                            TodoPageModel.TodoLists.Remove(todoList);
                        }
                    }
                    else
                    {
                        TodoList update = new TodoList()
                        {
                            TodoListId = todoList.TodoListId, Title = newTitle
                        };
                        result = await todoClient.UpdateTodoListAsync(update);

                        if (!result.Succeeded)
                        {
                            todoList.Title = todoList.OriginalTitle;
                        }
                    }
                }

                if (!result.Succeeded)
                {
                    await ErrorDialog.ShowErrorsAsync(result.Errors);
                }
            }
        }
Exemplo n.º 10
0
        private async void DeleteAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            TodoListModel todoList = GetSelectedTodoList();

            HttpResult result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.DeleteTodoListAsync(todoList.TodoListId);
            }

            if (result.Succeeded)
            {
                TodoPageModel.TodoLists.Remove(todoList);
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
Exemplo n.º 11
0
        public void Init()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.MessageHandlers.Add(new RequestContextHandler()
            {
                Principal   = new GenericPrincipal(new GenericIdentity(username), null),
                OwinContext = new OwinContext()
            });
            WebApiConfig.Register(config);
            config.DependencyResolver = MockTodoRepository.CreateDependencyResolver();

            HttpServer server     = new HttpServer(config);
            HttpClient httpClient = new HttpClient(server)
            {
                BaseAddress = new Uri("http://localhost/")
            };

            client = new TodoClient(httpClient);
        }
Exemplo n.º 12
0
        private async void CheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox      checkBox = (CheckBox)sender;
            TodoItemModel todo     = GetDataContext <TodoItemModel>(sender);
            TodoItem      todoItem = new TodoItem()
            {
                TodoItemId = todo.TodoItemId, TodoListId = todo.TodoListId, IsDone = checkBox.IsChecked.Value
            };
            HttpResult result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.UpdateTodoAsync(todoItem);
            }

            if (!result.Succeeded)
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
Exemplo n.º 13
0
        private async void AddAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            HttpResult <TodoList> result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.AddTodoListAsync(new TodoList()
                {
                    Title = "New Todo List"
                });
            }

            if (result.Succeeded)
            {
                TodoPageModel.TodoLists.Add(new TodoListModel(result.Content));
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(result.Errors);
            }
        }
Exemplo n.º 14
0
        private async void DeleteTodoItemButton_Click(object sender, EventArgs e)
        {
            TodoItemModel todo = TodoPageModel.SelectedTodoItem;

            HttpResult result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.DeleteTodoAsync(todo.TodoItemId);
            }

            if (result.Succeeded)
            {
                TodoPageModel.SelectedTodoItem = null;
                GetSelectedTodoList().Todos.Remove(todo);
            }
            else
            {
                ErrorDialog.ShowErrors(result.Errors);
            }
        }
Exemplo n.º 15
0
        async Task GetTodoListsAsync()
        {
            TodoPageModel.TodoLists.Clear();
            HttpResult <TodoList[]> todoListResult;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                todoListResult = await todoClient.GetTodoListsAsync();
            }

            if (todoListResult.Succeeded)
            {
                foreach (TodoList todoList in todoListResult.Content)
                {
                    TodoPageModel.TodoLists.Add(new TodoListModel(todoList));
                }
            }
            else
            {
                await ErrorDialog.ShowErrorsAsync(todoListResult.Errors);
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            Program._configuration = setConfiguration();
            TodoClient TodoClient = new TodoClient(Program._configuration);

            try
            {
                System.Console.WriteLine("Hello World!");

                TodoItemPublic todo = new TodoItemPublic();
                todo.Name       = "a fresh one";
                todo.IsComplete = false;
                todo.User       = new TodoApi.Shared.User
                {
                    Id        = 4,
                    FirstName = "",
                    Fullname  = "",
                    LastName  = ""
                };
                var item = TodoClient.Create(todo).Result;
                System.Console.WriteLine(item.Name);


                List <TodoItemPublic> todos = TodoClient.Getall().Result;


                System.Console.WriteLine(" after get all new attempt");
                foreach (TodoItemPublic _todo in todos)
                {
                    System.Console.WriteLine(_todo.Name);
                }
                System.Console.WriteLine("Sleeping");
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception e) {
                System.Console.WriteLine(e.ToString());
            }
        }
Exemplo n.º 17
0
        private async void OkButton_Click(object sender, EventArgs e)
        {
            TodoList todoList = new TodoList()
            {
                Title = TitleTextBox.Text, UserId = "unknown"
            };

            HttpResult <TodoList> result;

            using (TodoClient todoClient = ClientFactory.CreateTodoClient())
            {
                result = await todoClient.AddTodoListAsync(todoList);
            }

            if (result.Succeeded)
            {
                this.NavigationService.GoBack();
            }
            else
            {
                ErrorDialog.ShowErrors(result.Errors);
            }
        }
Exemplo n.º 18
0
        private async void TextBox_LostFocus(object sender, RoutedEventArgs e)
        {
            deleteButton.IsEnabled = false;
            TextBox       textBox = (TextBox)sender;
            TodoItemModel todo    = GetSelectedTodoItem(sender);

            if (todoTitle != textBox.Text)
            {
                TodoItem todoItem = new TodoItem()
                {
                    TodoItemId = todo.TodoItemId, TodoListId = todo.TodoListId, Title = textBox.Text
                };
                HttpResult result;
                using (TodoClient todoClient = ClientFactory.CreateTodoClient())
                {
                    result = await todoClient.UpdateTodoAsync(todoItem);
                }

                if (!result.Succeeded)
                {
                    ErrorDialog.ShowErrors(result.Errors);
                }
            }
        }
Exemplo n.º 19
0
 public IndexModel(TodoClient todoClient)
 {
     _todoClient = todoClient;
 }
Exemplo n.º 20
0
 public ItemModel(TodoClient todoClient)
 {
     _todoClient = todoClient;
 }