Advertisement
Guest User

Adatbazis_kezeles

a guest
Sep 17th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1.  class Kolcsonzo
  2.     {
  3.         int? id; //Identity
  4.         string megnevezes;
  5.         string cim;
  6.         List<Jarmu> jarmuvek;
  7.  
  8.         public int? Id
  9.         {
  10.             get => id;
  11.             set
  12.             {
  13.                 //if (id == null)
  14.                 if (id == default)
  15.                 {
  16.                     id = value;
  17.                 }
  18.                 else
  19.                 {
  20.                     throw new InvalidOperationException("Az ID értéke csak egyszer változhat és nem módosítható!");
  21.                 }
  22.             }
  23.         }
  24.         public string Megnevezes
  25.         {
  26.             get => megnevezes;
  27.             set
  28.             {
  29.                 if (value.Length >= 3)
  30.                 {
  31.                     megnevezes = value;
  32.                 }
  33.                 else
  34.                 {
  35.                     throw new ArgumentException("A kölcsönző megnevezése minimum 3 karakteres kell legyen!");
  36.                 }
  37.             }
  38.         }
  39.         public string Cim { get => cim; /*set => cim = value;*/ }
  40.         internal List<Jarmu> Jarmuvek { get => jarmuvek; /*set => jarmuvek = value;*/ }
  41.  
  42.         //Az adatbázisból való felolvasáshoz
  43.         public Kolcsonzo(int? id, string megnevezes, string cim) : this(megnevezes, cim)
  44.         {
  45.             Id = id;
  46.         }
  47.  
  48.         //A programban való létrehozáshoz
  49.         public Kolcsonzo(string megnevezes, string cim)
  50.         {
  51.             Megnevezes = megnevezes;
  52.             this.cim = cim;
  53.         }
  54.  
  55.         public override string ToString()
  56.         {
  57.             //return base.ToString();
  58.             return megnevezes;
  59.         }
  60.  
  61.         public override bool Equals(object obj)
  62.         {
  63.             //return base.Equals(obj);
  64.             return obj is Kolcsonzo masik && masik.id == this.id;
  65.         }
  66.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement