public List <TodosModel> GetTodosModel()
        {
            using (client)
            {
                var uri      = new Uri($"{url}/todos");
                var response = client.GetAsync(uri).Result;

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception(response.ToString());
                }

                var responseContent = response.Content;
                var responseString  = responseContent.ReadAsStringAsync().Result;

                dynamic todos = JArray.Parse(responseString) as JArray;

                foreach (var todo in todos)
                {
                    TodosModel tm = todo.ToObject <TodosModel>();
                    dtTodo.Add(tm);
                }
            }

            return(dtTodo);
        }
        public async Task <IActionResult> Post([FromBody] TodosModel todos)
        {
            var uri  = new Uri($"{url}/todos");
            var json = JsonConvert.SerializeObject(todos);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            var httpContext = await client.PostAsync(uri, data);

            var response = httpContext.Content.ReadAsStringAsync().Result;

            return(Ok(response));
        }
        public async Task <IActionResult> Put(int id, [FromBody] TodosModel todos)
        {
            var uri = new Uri($"{url}/todos/{id}");

            var json = JsonConvert.SerializeObject(todos.Equals(id));
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            var req = await client.PutAsync(uri, data);

            var response = req.Content.ReadAsStringAsync().Result;

            return(Ok(response));
        }
Esempio n. 4
0
 public IHttpActionResult Get(int id)
 {
     try
     {
         Todo todo = new TodosModel().GetTodoById(id);
         if (todo == null)
         {
             return(NotFound());
         }
         return(Ok(todo));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 5
0
 public IHttpActionResult Get()
 {
     try
     {
         List <Todo> todos = new TodosModel().GetTodos();
         if (todos.Count == 0)
         {
             return(NotFound());
         }
         return(Ok(todos));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 6
0
        // GET: Todo
        public ActionResult Index()
        {
            TodosModel todos = new TodosModel();

            var todaysTodos = from category in CurrentUser.Categories
                              from todo in category.Todos
                              where todo.StartDate.Date.Equals(DateTime.Today.Date)
                              select todo;
            var futureTodos = from category in CurrentUser.Categories
                              from todo in category.Todos
                              where todo.StartDate.Date > DateTime.Today.Date
                              select todo;

            todos.TodaysTodos.AddRange(todaysTodos);
            todos.FutureTodos.AddRange(futureTodos);
            return(View(todos));
        }