public static void AddAddress(string compName, string townName, string stName, int compPhon) { using (var db = new AddressDbContext()) { var address = new Address { Company = compName, Town = townName, Street = stName, CompPhone = compPhon }; db.Addresses.Add(address); db.SaveChanges(); } }
public static void DeleteAddress(int id) { using (var db = new AddressDbContext()) { int counter = 1; foreach (var address in db.Addresses) { if (counter == id) { db.Addresses.Remove(address); break; } ++counter; } db.SaveChanges(); } }
public static void EditAddress(int id, string compName, string townName, string stName, int compPhon) { using (var db = new AddressDbContext()) { int counter = 1; foreach (var address in db.Addresses) { if (counter == id) { address.Company = compName; address.Town = townName; address.Street = stName; address.CompPhone = compPhon; break; } ++counter; } db.SaveChanges(); } }