Пример #1
0
 private bool CanExecuteAddEmployee()
 {
     if (SelectedEmployee == null)
     {
         return(false);
     }
     else
     {
         return(SelectedEmployee.IsValid());
     }
 }
Пример #2
0
        private async void SaveEmployee()
        {
            if (SelectedEmployee == null || !SelectedEmployee.IsValid())
            {
                Error = "Medewerker niet toegevoegd of gewijzigd, hou rekening met de meldingen.";
                return;
            }
            else
            {
                Error = "";
            }

            SelectedEmployee.Available = true;
            string input = JsonConvert.SerializeObject(SelectedEmployee);

            // check insert (no ID assigned) or update (already an ID assigned)
            if (SelectedEmployee.ID == 0)
            {
                using (HttpClient client = new HttpClient())
                {
                    client.SetBearerToken(ApplicationVM.token.AccessToken);
                    HttpResponseMessage response = await client.PostAsync("http://localhost:55853/api/employee", new StringContent(input, Encoding.UTF8, "application/json"));

                    if (response.IsSuccessStatusCode)
                    {
                        string output = await response.Content.ReadAsStringAsync();

                        SelectedEmployee.ID = Int32.Parse(output);
                    }
                    else
                    {
                        Console.WriteLine("error");
                    }
                }
            }
            else
            {
                using (HttpClient client = new HttpClient())
                {
                    client.SetBearerToken(ApplicationVM.token.AccessToken);
                    HttpResponseMessage response = await client.PutAsync("http://localhost:55853/api/employee", new StringContent(input, Encoding.UTF8, "application/json"));

                    if (!response.IsSuccessStatusCode)
                    {
                        Console.WriteLine("error");
                    }
                }
            }
        }