Apress / esntl-angular-for-asp.net-core-mvc-3

Source Code for 'Essential Angular for ASP.NET Core MVC 3' by Adam Freeman
Other
38 stars 39 forks source link

Chapter 6-2 Code does not match git code #3

Open ProducerBill opened 4 years ago

ProducerBill commented 4 years ago

Code in Chapter 6-2 does not match code found in /SportsStore/ServerApp/Models/BindingTargets/ProductData.cs

using System.ComponentModel.DataAnnotations;

namespace ServerApp.Models.BindingTargets {

    public class ProductData {

        [Required]
        public string Name {
            get => Product.Name; set => Product.Name = value;
        }

        [Required]
        public string Category {
            get => Product.Category; set => Product.Category = value;
        }

        [Required]
        public string Description {
            get => Product.Description; set => Product.Description = value;
        }

        [Range(1, int.MaxValue, ErrorMessage = "Price must be at least 1")]
        public decimal Price {
            get => Product.Price; set => Product.Price = value;
        }

        public long? Supplier {
            get => Product.Supplier?.SupplierId ?? null;
            set {
                if (!value.HasValue) {
                    Product.Supplier = null;
                } else {
                    if (Product.Supplier == null) {
                        Product.Supplier = new Supplier();
                    }
                    Product.Supplier.SupplierId = value.Value;
                }
            }
        }

        public Product Product { get; set; } = new Product();
    }
}

From Book: 6-2 image

When I ran the example after the Put section it nulled out the product id=1 causing the whole system to stop because Price requires >1 and a Description is required.

Side note: As a person trying to teach via this book this is borderline irresponsible to make such a change without at least some comments explaining the change in the source code.

simonprice33 commented 4 years ago

I am under the impression from the book that this is completed code on github which is stated at the start of each chapter