MODELLER
City, Town, Station, GasType, Users, Sales, Payment
PROPERTY
City: city
Town: town, city_id
Station: name,adress,phone, city,town
Gas: GasType, Prince , Stock, stationID
Users: UserName, Password, Rol, NameSurname, Phone, ProfileImage
Sales: PumpNo, GasId, Plate , UserId, Liter,TotalPrice
* Buradaki userID pompacı olarak benzini satan kişi
* Burada Satış yapıldığında Gastype tablosundan otomatik litre
miktarının stoktan düşürülmesi gerekir
* Eğer stokta kalmadıysa satış yapılamaz
Payment: PaymentType,PaymentDate, SalesId,UserID
*Buradaki userId ya kasadaki satıcı yada pompacı olarak görev yapan kullanıcı
İLİŞKİLER
il-ilce = bire çok
Gas-Station: bire-çok
Gas-Sales: bire-çok
Users-sales: bire-çok
Sales-Payment: bire-bir
Modellerimizi tasarladığımıza göre MODEL Katmanımıza model classlarını açalım. Her bir model için sağ tıklayıp class seçelim ve ilk harfi büyük olacak şekilde isim verelim. Ama bundan önce modellerimizde yer alan Rol, GasType,PaymentType propertyleri için Enums değerlerimizi oluşturalım. Enums altına her bir enum değeri için class açalım.:
ENUMS
Role.cs
public enum Role
{
Admin=1, Cashier = 2, Pumper = 3
}
GasType.cs
public enum GasType
{
Dizel=1, Benzin=2, Lpg=3
}
PaymentType.cs
public enum PaymentType
{
Cash=1, CreditCard=2
}
MODELS
İlişkili olan modellerde Örneğin bire çok ilişkili ise Bir olan tarafa diğer tablonun listeli olarak RelationProperty eklememiz gerekiyor, Ve diğer tablonun Foreign Key alanını, Çok olan tabloya ise bir olan tablonun tekli model olarak relation modelini eklememiz gerekiyor.
Town.cs
public class Town:BaseEntity
{
public string TownName { get; set; }
//foreignKey
public int CityID { get; set; }
//relation property
public virtual City City { get; set; }
}
City.cs
public class City:BaseEntity
{
public string CityName { get; set; }
//RelationProperty
public virtual List<Town> Towns { get; set; }
}
Gas.cs
public class Gas:BaseEntity
{
public Gas()
{
Prince = 0;
Stock = 0;
}
public GasType GasTypes { get; set; }
public float Prince { get; set; }
public float Stock { get; set; }
//Foreign Key
public int StationID { get; set; }
//RelationProperty
public Station Station { get; set; }
public List<Sales> Sales { get; set; }
}
Station.cs
public class Station: BaseEntity
{
public string StationName { get; set; }
public string Adress { get; set; }
public string Phone { get; set; }
public string City { get; set; }
public string Town { get; set; }
//RelationProperty
public List<Gas> Gases { get; set; }
}
User.cs
public class User:BaseEntity
{
public User()
{
Role = Role.Pumper;
}
public string UserName { get; set; }
public string Password { get; set; }
public Role Role { get; set; }
public string NameSurname { get; set; }
public string Phone { get; set; }
public string ProfileImage {get;set;}
//RelationProperty
public List<Sales> Sales { get; set; }
}
Sales.cs
public class Sales:BaseEntity
{
public string PumpNo { get; set; }
public string Plate { get; set; }
public float Liter { get; set; }
public float TotalPrice { get; set; }
//ForeignKey
public int GasID { get; set; }
public int UserID { get; set; }
//RelationProperty
public User User { get; set; }
public Gas Gas { get; set; }
public Payment Payment { get; set; }
}
Payment.cs
public class Payment:BaseEntity
{
public Payment()
{
PaymentDate = DateTime.Now;
}
public PaymentType Ptype { get; set; }
public DateTime PaymentDate { get; set; }
//foreign Key
public int UserID { get; set; }
public int SalesID { get; set; }
//RelationProperty
public Sales Sales { get; set; }
}
Modellerimizin yazımını bitirdik, Bir sonraki yazıda MetaDataType değerlerini ayarlayacağız, Model bazlı olan bu validasyonlarda formdan gelen veriler için uyraı yazabilecek ve sınırlandırabileceğiz, örneğin şifrenin 6 ve 10 hane olması, mailin geçerli olup olmadığı, bir propertynın zorunlu olması gibi..
Yazdığımız bu modellerin Db tanınması için DAL Katmanındaki MyDbContext dosyasına Dbset olarak bu modelleri eklememiz gerekiyor.
public DbSet<User> Users { get; set; }
public DbSet<City> Cities { get; set; }
public DbSet<Town> Towns { get; set; }
public DbSet<Gas> Gases { get; set; }
public DbSet<Payment> Payments { get; set; }
public DbSet<Sales> Sales { get; set; }
public DbSet<Station> Stations { get; set; }
Hiç yorum yok:
Yorum Gönder