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
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.
Code in Chapter 6-2 does not match code found in /SportsStore/ServerApp/Models/BindingTargets/ProductData.cs
From Book: 6-2
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.