public void CreateProductReturn(ProductReturn r)
        {
            //add preconditions later
            //if (r.Amount == null)
            //{
             
            //    throw new ArgumentNullException("Amount is not selected");
            //}

           
  
            new MessageDialog("Creating ProductReturn").ShowAsync();
            try
            {
                
                PersistencyService.InsertProductReturnAsync(r);

                // Add to ProductReturns
              
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
Exemple #2
0
        public void CreateProductReturn(Product p, ProductReturn r)
        {
            if (r.Amount < 1)
            {
                throw new ArgumentException("Du skal returnere mindst ét produkt");
            }

            if (r.Description == null)
            {
                throw new ArgumentException("Beskrivelse skal indtastes");
            }

            if (p.Stock < r.Amount)
            {
                throw new ArgumentException("Kan ikke returnere flere end antallet af vare på lager");
            }
            try
            {
                PersistencyService.InsertProductReturnAsync(r);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }

            // Reduce the product stock, as we return those products
            p.Stock -= r.Amount;

            // Update product with the new amount
            try
            {
                UpdateProduct(p);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                throw;
            }

            // Add ReturnProduct to the list of the corresponding product (the ReturnProduct owner)
            if (p.ProductReturns == null)
            {
                p.ProductReturns = new ObservableCollection <ProductReturn>();
            }

            p.ProductReturns.Add(r);
        }