Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.ComponentModel.DataAnnotations;
  5. using System.ComponentModel.DataAnnotations.Schema;
  6. using System.Data.Entity;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11. namespace Db.Model
  12. {
  13. public class Consumer : INotifyPropertyChanged
  14. {
  15. private String name;
  16. private String address;
  17. private ICollection<Meter> meters = new List<Meter>();
  18.  
  19. [Key]
  20. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  21. public int Id { get; set; }
  22. public String Name {
  23. get { return this.name; }
  24. set {
  25. if(this.name == value) { return; }
  26. this.name = value;
  27. Notify("Name");
  28. }
  29. }
  30. public String Address {
  31. get { return address; }
  32. set
  33. {
  34. if(this.address == value) { return; }
  35. this.address = value;
  36. Notify("Address");
  37. }
  38. }
  39.  
  40. public ICollection<Meter> Meters {
  41. get { return meters; }
  42. set
  43. {
  44. this.meters = value;
  45. Notify("Meters");
  46. }
  47. }
  48.  
  49. public Consumer() {
  50. }
  51.  
  52. public Consumer(String name, String address)
  53. {
  54. Name = name;
  55. Address = address;
  56. }
  57.  
  58. public event PropertyChangedEventHandler PropertyChanged;
  59.  
  60. protected void Notify(String propName)
  61. {
  62. if (this.PropertyChanged != null)
  63. {
  64. PropertyChanged(this, new PropertyChangedEventArgs(propName));
  65. }
  66. }
  67.  
  68. public override string ToString()
  69. {
  70. return Id + "\t" + Name + "\t\t\t" + Address + "\tMeters: " + Meters.Count;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement