public void DeleteEnd() { //var deleteOrderDetails = // from details in lContext.Persons // where details.Id == this.Id // select details; DataSource.Person lUpdatePerson = lContext.Persons.SingleOrDefault(p => p.Id == this.Id); if (lUpdatePerson != null) { lContext.Persons.DeleteOnSubmit(lUpdatePerson); try { lContext.SubmitChanges(); } catch (Exception e) { Console.WriteLine(e); // Provide for exceptions. } } }
public void EndEdit() { DataSource.Person lUpdatePerson = lContext.Persons.SingleOrDefault(p => p.Id == this.Id); if (lUpdatePerson == null) { DataSource.Person newPerson = new DataSource.Person { FirstName = this.FirstName, LastName = this.LastName, Address1 = this.Address2, Address2 = this.Address2, Phone1 = this.Phone1, Phone2 = this.Phone2, Email1 = this.Email1, Email2 = this.Email2, DOB = this.DOB // Gender = this.Gender }; // Add the new object to the Orders collection. lContext.Persons.InsertOnSubmit(newPerson); // Submit the change to the database. try { lContext.SubmitChanges(); this.Id = newPerson.Id; } catch (Exception e) { Console.WriteLine(e); } } else { lUpdatePerson.FirstName = this.FirstName; lUpdatePerson.LastName = this.LastName; lUpdatePerson.Address1 = this.Address1; lUpdatePerson.Address2 = this.Address2; lUpdatePerson.Phone1 = this.Phone1; lUpdatePerson.Phone2 = this.Phone2; lUpdatePerson.Email1 = this.Email1; lUpdatePerson.Email2 = this.Email2; lUpdatePerson.DOB = this.DOB; lContext.SubmitChanges(); } }