internal void insertBirds(ArrayList birds) { using (BSPetShopEntities context = new BSPetShopEntities()) { var query = from b in context.BirdSet select b; foreach (var item in query) { context.BirdSet.Remove(item); } foreach (Bird b in birds) { context.BirdSet.Add(new BirdSet() { Age = (short)b.age, Family = b.family, Price = b.price, Type = b.type }); } context.SaveChanges(); } }
internal void insertReceipt(Receipt receip, Customer customer) { using (BSPetShopEntities context = new BSPetShopEntities()) { var customerWithID = from c in context.CustomerSet where c.PhoneNumber.Equals(customer.phonenumber) select c; context.ReceiptSet.Add(new ReceiptSet() { Totalprice = receip.totalPrice().ToString(), Date = receip.date, Customer_Id = customerWithID.Single().Id }); context.SaveChanges(); foreach (Animal a in receip.animals) { Type birdType = typeof(Bird); Type fishType = typeof(Fish); var receipt = from r in context.ReceiptSet where r.Date == receip.date && r.Customer_Id == customer.id select r; if (a.GetType() == birdType) { var query = from b in context.BirdSet where b.Id == a.id select b; foreach (BirdSet b in query) { b.Receipt_Id = receipt.Single().Id; } context.SaveChanges(); } else { var queryF = from f in context.FishSet where f.Id == a.id select f; foreach (FishSet f in queryF) { f.Receipt_Id = receipt.Single().Id; } context.SaveChanges(); } } } }
internal void newCustomer(string name, string adress, string phonenumber, string email) { using (BSPetShopEntities context = new BSPetShopEntities()) { context.CustomerSet.Add(new CustomerSet() { Name = name, Adress = adress, PhoneNumber = phonenumber, Email = email }); context.SaveChanges(); } }
internal void insertFish(ArrayList fish) { using (BSPetShopEntities context = new BSPetShopEntities()) { var query = from f in context.FishSet select f; foreach (var item in query) { context.FishSet.Remove(item); } foreach (Fish f in fish) { context.FishSet.Add(new FishSet() { Type = f.type.ToString(), Price = f.price, Aggressive = f.aggressive, Water = f.water }); } context.SaveChanges(); } }