public static List <Address> AddressList2() { using (var db = new AddressDbContext()) { List <Address> Addresses = new List <Address>(); foreach (var address in db.Addresses) { Addresses.Add(address); } return(Addresses); } }
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 List <String> AddressList() { using (var db = new AddressDbContext()) { List <String> Addresses = new List <String>(); foreach (var address in db.Addresses) { string temp; temp = "Nazwa firmy: " + address.Company + " Miasto: " + address.Town + " Ulica: " + address.Street + " Tel.:" + address.CompPhone; Addresses.Add(temp); } return(Addresses); } }
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(); } }