Ejemplo n.º 1
0
        /// <summary>Seeds the database.</summary>

        /// <param name="source">The source.</param>

        public static void Seed(this IProductDatabase source)

        {
            source.Add(new Product()
            {
                Name = "iPhone X",

                IsDiscontinued = true,

                Price = 1500,
            });

            source.Add(new Product()
            {
                Name = "Windows Phone",

                IsDiscontinued = true,

                Price = 15,
            });

            source.Add(new Product()
            {
                Name = "Samsung S8",

                IsDiscontinued = false,

                Price = 800
            });
        }
Ejemplo n.º 2
0
 /// <summary>Initializes an instance of the <see cref="SeedMemoryProductDatabase"/> class.</summary>
 public static void WithSeedData(this IProductDatabase source)
 {
     source.Add(new Product()
     {
         Name = "Galaxy S7", Price = 650
     });
     source.Add(new Product()
     {
         Name = "Galaxy Note 7", Price = 150, IsDiscontinued = true
     });
     source.Add(new Product()
     {
         Name = "Windows Phone", Price = 100
     });
     source.Add(new Product()
     {
         Name = "iPhone X", Price = 1900, IsDiscontinued = true
     });
 }
Ejemplo n.º 3
0
        public ActionResult Create(ProductModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var product = model.ToDomain();
                    product = _database.Add(product);
                    return(RedirectToAction(nameof(Index)));
                }
                ;
            } catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Create(ProductModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new Exception("Model invalid");
            }

            try
            {
                var product = model.ToDomain();

                product = _database.Add(product);

                return(Json(product.ToModel(), JsonRequestBehavior.AllowGet));
            }catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
            }

            return(Json(ModelState, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 5
0
        private void OnProductAdd( object sender, EventArgs e )
        {
            var child = new ProductDetailForm("Product Details");
            if (child.ShowDialog(this) != DialogResult.OK)
                return;

            else
            {
                try
                {
                    _database.Add (child.Product);
                    UpdateList ();
                } catch (ArgumentException ex)
                {
                    MessageBox.Show (ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } catch (ValidationException ex)
                {
                    MessageBox.Show (ex.Message, "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                } catch (Exception)
                {
                    MessageBox.Show ("Save failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 6
0
 // FromBody tells the complier that the data is contained in the body of the request
 // Google how Http requests are made
 // There is a header/body of the message
 public IActionResult Post([FromBody] Product product)
 {
     _productDatabase.Add(product);
     return(Ok(product));
 }
Ejemplo n.º 7
0
 private void AddProduct(Product product)
 {
     _product.Add(product);
     UpdateList();
 }