Beispiel #1
0
        /// <summary>
        /// DELETE /tables/TodoItem/{id}
        /// </summary>
        public static void DeleteTodo(TodoItem t)
        {
            WebClient client = new WebClient();
            try {
                // make it synchronous
                client.Headers.Add (HttpRequestHeader.Accept, "application/json");
                client.Headers.Add (HttpRequestHeader.ContentType, "application/json");
                client.Headers.Add ("X-ZUMO-APPLICATION", MobileServiceAppId);

                var payload = t.ToJson ();
                var response = client.UploadString (String.Format (DeleteUrl,t.Id), "DELETE", payload); // DELETE
                // ...and wait...
                var responseString = response;

                //var responseJson = JsonValue.Parse (responseString); //HACK:
                Console.WriteLine ("Delete Json response => " + responseString);

            } catch (System.Net.WebException e) {
                Console.WriteLine ("X-ZUMO-APPLICATION add failed" + e.Message);
            }
        }
Beispiel #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add, (s,e) =>{
                var task = new TodoItem() {Title="<new task>"};
                // Save to Azure
                var added = AzureWebService.AddTodo (task);
                tasks.Add (added);
                Reload (); // show the new task
            });
            NavigationItem.RightBarButtonItem = addButton;

            // UIBarButtonSystemItem.Refresh or http://barrow.io/posts/iphone-emoji/
            refreshButton = new UIBarButtonItem('\uE049'.ToString ()
            , UIBarButtonItemStyle.Plain
            , (s,e) => {
                tasks = AzureWebService.LoadTodos(Reload);
            });
            NavigationItem.LeftBarButtonItem = refreshButton;

            tasks = AzureWebService.LoadTodos(Reload);
        }
Beispiel #3
0
        /// <summary>
        /// POST /tables/TodoItem
        /// {"text":"new task text","complete":false}
        /// </summary>
        public static TodoItem AddTodo(TodoItem t)
        {
            WebClient client = new WebClient();
            try {
                // make it synchronous
                client.Headers.Add (HttpRequestHeader.Accept, "application/json");
                client.Headers.Add (HttpRequestHeader.ContentType, "application/json");
                client.Headers.Add ("X-ZUMO-APPLICATION", MobileServiceAppId);

                var payload = t.ToJson ();
                var response = client.UploadString (AddUrl, "POST", payload); // PATCH
                // ...and wait...
                var responseString = response;
                // RETURNS [{"id":1,"text":"Port to iOS and Android","complete":false}]
                Console.WriteLine ("Add Json response => " + responseString);

                var responseJson = JsonValue.Parse (responseString);
                return new TodoItem(responseJson);

            } catch (System.Net.WebException e) {
                Console.WriteLine ("X-ZUMO-APPLICATION add failed" + e.Message);
            }
            return null;
        }
Beispiel #4
0
 public TaskScreen(TodoItem t)
 {
     task = t;
 }
Beispiel #5
0
        /// <summary>
        /// GET /tables/TodoItem/{id}
        /// </summary>
        public static TodoItem GetTodo(int id)
        {
            TodoItem task = null;
            WebClient client = new WebClient();
            try {
                // make it synchronous
                client.Headers.Add (HttpRequestHeader.Accept, "application/json");
                client.Headers.Add ("X-ZUMO-APPLICATION", MobileServiceAppId);
                var response = client.DownloadData (String.Format (GetUrl, id)); // GET
                // ...and wait...
                var responseString = System.Text.Encoding.UTF8.GetString(response);
                // RETURNS [{"id":1,"text":"Port to iOS and Android","complete":false}]

                var responseJson = JsonValue.Parse (responseString);

                if (responseJson != null)
                {
                    for (var j = 0; j < responseJson.Count; j++) {
                        var t = responseJson[j];// as JsonValue;
                        task = new TodoItem(t);
                        break; // just one required :)
                    }
                }

                Console.WriteLine ("Json get response => " + responseString);

            } catch (System.Net.WebException e) {
                Console.WriteLine ("X-ZUMO-APPLICATION failed" + e.Message);
            }
            return task;
        }
Beispiel #6
0
        /// <summary>
        /// GET /tables/TodoItem
        /// </summary>
        public static List<TodoItem> LoadTodos(Action whenDone)
        {
            var tasks = new List<TodoItem>();
            WebClient client = new WebClient();
            try {
                // make it synchronous
                client.Headers.Add (HttpRequestHeader.Accept, "application/json");
                client.Headers.Add ("X-ZUMO-APPLICATION", MobileServiceAppId);
                var response = client.DownloadData (GetAllUrl); // GET
                // ...and wait...
                var responseString = System.Text.Encoding.UTF8.GetString(response);
                // RETURNS [{"id":1,"text":"Port to iOS and Android","complete":false}]

                var responseJson = JsonValue.Parse (responseString); //HACK:

                if (responseJson != null)
                {
                    tasks = new List<TodoItem>();
                    for (var j = 0;j <responseJson.Count; j++) {
                        var t = responseJson[j];// as JsonValue;
                        var task = new TodoItem(t);

                        tasks.Add (task);
                    }
                    whenDone();  // hacky to keep doing this...?
                }

                Console.WriteLine ("Json response => " + responseString);

            } catch (System.Net.WebException e) {
                Console.WriteLine ("X-ZUMO-APPLICATION failed" + e.Message);
            }
            return tasks;
        }