public static Ledger LedgerFactory(string customer, int medID, int quan) { Medicine fetched; using (var ctx = new PharmaContext()) { fetched = ctx.Medicines.Where(m => m.MedicineID == medID).FirstOrDefault(); if (fetched.Stock >= quan) { Ledger newEntry = new Ledger(customer, fetched.MedicineID, quan); return newEntry; } else { return null; } } }
public Manufacturer(string name, string phone, string email, string address) { this.Name = name; this.Phone = phone; this.Email = email; this.Address = address; int max; using (var ctx = new PharmaContext()) { if (ctx.Manufacturers.Count() == 0) { max = 0; } else { max = (ctx.Manufacturers.Max(p => p.ManufacturerID)); } this.ManufacturerID = max + 1; ctx.Manufacturers.Add(this); ctx.SaveChanges(); System.Diagnostics.Debug.WriteLine("New Manufacturer"); } }
private Ledger(string customer, int medicineID, int quantity) { this.Customer = customer; this.Quantity = quantity; int max; using (var ctx = new PharmaContext()) { this.Medicine = ctx.Medicines.Where(m => m.MedicineID == medicineID).FirstOrDefault(); this.Amount = this.Medicine.Price * quantity; if (ctx.Ledgers.Count() == 0) { max = 0; } else { max = (ctx.Ledgers.Max(p => p.Entry)); } this.Medicine.Stock -= quantity; ctx.Ledgers.Add(this); ctx.SaveChanges(); } this.Entry = max + 1; }
public Dealer(string name, string phone, string email, string address) { this.Name = name; this.Phone = phone; this.Email = email; this.Address = address; int max; using (var ctx = new PharmaContext()) { if (ctx.Dealers.Count() == 0) { max = 0; } else { max = (ctx.Dealers.Max(p => p.DealerID)); } this.DealerID = max + 1; ctx.Dealers.Add(this); ctx.SaveChanges(); System.IO.File.WriteAllText(@"C:\ZDrive\hetulDebug.txt", "Dealer has been called"); } }
public Medicine(string name, double price, int stock, int dealerID, int manufacturerID) { this.Name = name; this.Price = price; this.Stock = stock; int max; using (var ctx = new PharmaContext()) { this.Dealer = ctx.Dealers.Where(d=>d.DealerID==dealerID).FirstOrDefault(); this.Manufacturer = ctx.Manufacturers.Where(m => m.ManufacturerID == manufacturerID).FirstOrDefault(); if (ctx.Medicines.Count() == 0) { max = 0; } else { max = (ctx.Medicines.Max(p => p.MedicineID)); } this.MedicineID = max + 1; ctx.Medicines.Add(this); ctx.SaveChanges(); } }