private void Button_Click(object sender, RoutedEventArgs e) { try { Entities db = new Entities(); int MaxP = 0; int Aid = Convert.ToInt32(ApId.SelectedItem); int Hid = Convert.ToInt32(HId.SelectedItem); int Lid = Convert.ToInt32(LId.SelectedItem); if (Price.Text != "") { MaxP = Convert.ToInt32(Price.Text); } agent fo = db.agents.Where(p => p.FirstName == AId.SelectedItem.ToString()).FirstOrDefault(); client of = db.clients.Where(p => p.FirstName == CId.SelectedItem.ToString()).FirstOrDefault(); var apnew = new supply(); apnew.Price = MaxP; apnew.AgentId = fo.Id; apnew.ClientId = of.Id; apnew.ApartmentId = Aid; apnew.HouseId = Hid; apnew.LandId = Lid; db.supplies.Add(apnew); db.SaveChanges(); } catch { } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { Entities db = new Entities(); var nub = Convert.ToInt32(IdD.Text); supply ap = db.supplies.Where(p => p.Id == nub).FirstOrDefault(); db.supplies.Remove(ap); db.SaveChanges(); } catch { } }