private bool EditProduct()
        {
            if (SelectedProduct != null)
            {
                if (SelectedProduct.IsValid())
                {
                    PharmacyProduct product = _uow.PharmacyProductRepo.Get(p => p.QtyOrdered == SelectedProduct.QtyOrdered).FirstOrDefault();
                    if (SelectedProduct.QtyOrdered != 0 && product == null)
                    {
                        SelectedProduct.DateOfOrder = DateTime.Now;
                    }

                    _uow.PharmacyProductRepo.Edit(SelectedProduct);
                    int ok = _uow.Save();
                    if (ok > 0)
                    {
                        return(true);
                    }
                    else
                    {
                        MessageBox.Show("De data is niet veranderd!", "Foutmelding", MessageBoxButton.OK, MessageBoxImage.Error);
                        return(false);
                    }
                }
                else
                {
                    MessageBox.Show(SelectedProduct.Error, "Foutmelding", MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
 private bool CanExecuteAddProduct()
 {
     if (SelectedProduct == null)
     {
         return(false);
     }
     else
     {
         return(SelectedProduct.IsValid());
     }
 }
        private async void SaveProduct()
        {
            if (SelectedProduct == null || !SelectedProduct.IsValid())
            {
                Error = "Product niet toegevoegd of gewijzigd, hou rekening met de meldingen.";
                return;
            }
            else
            {
                Error = "";
            }

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

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

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

                        SelectedProduct.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/product", new StringContent(input, Encoding.UTF8, "application/json"));

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