Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private string name;
- private int minStock;
- private Category category;
- public Product()
- {
- Category = new Category();
- User = new User();
- }
- public int ProductId { get; set; }
- [Required]
- public string Name
- {
- get { return name; }
- set
- {
- name = value;
- OnPropertyChanged();
- }
- }
- [Required]
- public decimal SellPrice { get; set; }
- [Required]
- public int MinStock
- {
- get { return minStock; }
- set
- {
- minStock = value;
- OnPropertyChanged();
- }
- }
- public int Remove { get; set; }
- [Timestamp]
- public byte[] RowVersion { get; set; }
- #region Relationships
- public virtual Measurement Mesurement { get; set; }
- public virtual Category Category
- {
- get { return category; }
- set
- {
- category = value;
- OnPropertyChanged();
- }
- }
- public virtual User User { get; set; }
- #endregion
- using (MFSContext context = new MFSContext())
- {
- Product product = context.Products.Find(SelectedProduct.Id);
- product.Name = "Frank";
- context.Entry(product).State = EntityState.Modified;
- try
- {
- context.SaveChanges();
- }
- catch (DbEntityValidationException dbEx)
- {
- Exception raise = dbEx;
- foreach (var validationErrors in dbEx.EntityValidationErrors)
- {
- foreach (var validationError in validationErrors.ValidationErrors)
- {
- string message = string.Format("{0}:{1}",
- validationErrors.Entry.Entity.ToString(),
- validationError.ErrorMessage);
- // raise a new exception nesting
- // the current instance as InnerException
- raise = new InvalidOperationException(message, raise);
- }
- }
- throw raise;
- }
- context.SaveChanges();
- LoadCategories();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement