Exemplo n.º 1
0
        public IActionResult TodoUpdate(string Id)
        {
            if (User.Identity.IsAuthenticated)
            {
                _token = User.FindFirst("Token").Value;
            }
            TodoListModel todoList = apiRequest.GetTodoListById(Id, _token);

            TodoListsViewModel todoListsViewModel = new TodoListsViewModel();

            todoListsViewModel.title    = todoList.title;
            todoListsViewModel.content  = todoList.content;
            todoListsViewModel.listType = todoList.listType;

            ViewBag.listId = todoList.listId;

            todoListsViewModel.listTypes = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "普通", Value = "普通"
                },
                new SelectListItem {
                    Text = "急件", Value = "急件"
                }
            };

            return(View(todoListsViewModel));
        }
Exemplo n.º 2
0
        public TodoListModel TodoUpdate(string listId, TodoListsViewModel todoListsViewModel, string token)
        {
            string url = $"https://apicorepractice.herokuapp.com/api/todolists/{listId}";

            string postBody = JsonConvert.SerializeObject(todoListsViewModel);//將匿名物件序列化為json字串

            string resData = PostToBackApi(url, "PUT", token, postBody);

            if (string.IsNullOrEmpty(resData))
            {
                TodoListModel todoListModel = null;
                return(todoListModel);
            }

            return(JsonConvert.DeserializeObject <TodoListModel>(resData));
        }
Exemplo n.º 3
0
        public IActionResult TodoCreate()
        {
            TodoListsViewModel todoListsViewModel = new TodoListsViewModel();


            todoListsViewModel.listTypes = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "普通", Value = "普通"
                },
                new SelectListItem {
                    Text = "急件", Value = "急件"
                }
            };

            return(View(todoListsViewModel));
        }
        /// <summary>
        /// GET: TodoList/
        /// </summary>
        /// <param name="searchString">string to search for specific todo list by name</param>
        /// <returns></returns>
        public async Task <IActionResult> Index(string searchString)
        {
            using (var client = new HttpClient())
            {
                // add the appropriate properties on top of the client base address.
                client.BaseAddress = new Uri("http://todoapilab17.azurewebsites.net/");

                //the .Result is important for us to extract the result of the response from the call
                var listsResponse = client.GetAsync("/api/todolist/").Result;
                var itemsResponse = client.GetAsync("/api/todo/").Result;
                if (listsResponse.EnsureSuccessStatusCode().IsSuccessStatusCode &&
                    listsResponse.EnsureSuccessStatusCode().IsSuccessStatusCode)
                {
                    var stringListResult = await listsResponse.Content.ReadAsStringAsync();

                    var stringItemsResult = await itemsResponse.Content.ReadAsStringAsync();

                    List <TodoList> demTodoLists = JsonConvert.DeserializeObject <List <TodoList> >(stringListResult);
                    List <TodoItem> demTodoItems = JsonConvert.DeserializeObject <List <TodoItem> >(stringItemsResult);

                    var todoLists = from l in demTodoLists
                                    select l;

                    var todoItems = from i in demTodoItems
                                    select i;

                    if (!String.IsNullOrEmpty(searchString))
                    {
                        todoLists = todoLists.Where(s => s.Name.Contains(searchString));
                    }

                    var todoListsVM = new TodoListsViewModel();
                    todoListsVM.TodoLists = todoLists.ToList();
                    todoListsVM.TodoItems = todoItems.ToList();
                    return(View(todoListsVM));
                }
                return(View());
            }
        }
Exemplo n.º 5
0
        public IActionResult TodoCreate(TodoListsViewModel todoListsViewModel)
        {
            if (!ModelState.IsValid)
            {
                todoListsViewModel.listTypes = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "普通", Value = "普通"
                    },
                    new SelectListItem {
                        Text = "急件", Value = "急件"
                    }
                };
                return(View(todoListsViewModel));
            }
            if (User.Identity.IsAuthenticated)
            {
                _token = User.FindFirst("Token").Value;
            }
            TodoListModel todoList = apiRequest.TodoCreate(todoListsViewModel, _token);

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 6
0
        public IActionResult TodoUpdateInfo(string Id, TodoListsViewModel todoListsViewModel)
        {
            if (!ModelState.IsValid)
            {
                todoListsViewModel.listTypes = new List <SelectListItem>
                {
                    new SelectListItem {
                        Text = "普通", Value = "普通"
                    },
                    new SelectListItem {
                        Text = "急件", Value = "急件"
                    }
                };
                return(View(todoListsViewModel));
            }
            if (User.Identity.IsAuthenticated)
            {
                _token = User.FindFirst("Token").Value;
            }
            TodoListModel todoList = apiRequest.TodoUpdate(Id, todoListsViewModel, _token);

            return(RedirectToAction("TodoDetail", "Home", new { Id = Id }));
        }