Ejemplo n.º 1
0
        private void TaskEntryOk_Click(object sender, RoutedEventArgs e)
        {
            List <Room> rooms;

            using (var client = new HttpClient())
            {
                var  response = "";
                Task task     = Task.Run(async() =>
                {
                    response = await client.GetStringAsync(new Uri("http://localhost:52285/api/Rooms"));
                });
                task.Wait();
                rooms = JsonConvert.DeserializeObject <List <Room> >(response);
            }

            Int32.TryParse(TaskEntryRoomNumber.Text, out int roomNo);
            try
            {
                Room        foundRoom = rooms.Where(room => room.RoomNumber == roomNo).First <Room>();
                ServiceTask st        = new ServiceTask
                {
                    TypeOfService = CurrentServiceType,
                    Status        = "Pending",
                    TimeIssued    = DateTime.Now,
                    TimeCompleted = null,
                    RoomId        = foundRoom.RoomId,
                    Description   = TaskEntryDescription.Text
                };

                var newServiceTask = JsonConvert.SerializeObject(st);
                var buffer         = System.Text.Encoding.UTF8.GetBytes(newServiceTask);
                var byteContent    = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                using (var client = new HttpClient())
                {
                    Task task = Task.Run(async() =>
                    {
                        await client.PostAsync(new Uri("http://localhost:52285/api/ServiceTasks"), byteContent);
                    });
                    task.Wait();
                }
                UpdateServiceTaskList();
                TaskEntryDescription.Text = "";
                TaskEntryRoomNumber.Text  = "";
            } catch (Exception ex)
            {
            }
        }
Ejemplo n.º 2
0
        private void DeleteTaskButton_Click(object sender, RoutedEventArgs e)
        {
            if (TaskListView.SelectedItem != null)
            {
                ServiceTask st = TaskListView.SelectedItem as ServiceTask;

                using (var client = new HttpClient())
                {
                    Task task = Task.Run(async() =>
                    {
                        await client.DeleteAsync(new Uri(String.Format("http://localhost:52285/api/ServiceTasks/{0}", st.TaskId)));
                    });
                    task.Wait();
                }
                UpdateServiceTaskList();
            }
        }
Ejemplo n.º 3
0
        private void BeginTaskButton_Click(object sender, RoutedEventArgs e)
        {
            if (TaskListView.SelectedItem != null)
            {
                ServiceTask st = TaskListView.SelectedItem as ServiceTask;
                st.Status = "In Progress";

                var newServiceTask = JsonConvert.SerializeObject(st);
                var buffer         = System.Text.Encoding.UTF8.GetBytes(newServiceTask);
                var byteContent    = new ByteArrayContent(buffer);
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                using (var client = new HttpClient())
                {
                    Task task = Task.Run(async() =>
                    {
                        await client.PutAsync(new Uri(String.Format("http://localhost:52285/api/ServiceTasks/{0}", st.TaskId)), byteContent);
                    });
                    task.Wait();
                }
                UpdateServiceTaskList();
            }
        }