public bool RemoveMother(int id) { var temp = (from mother in Mothers.Elements() where Convert.ToInt32(mother.Element("ID").Value) == id select mother).FirstOrDefault(); if (temp == null) { throw new Exception("No mother with the same id..."); } temp.Remove(); SaveMothers(); var kids = GetChildrenByMother(id).ToList(); foreach (Child kid in kids) { RemoveChild(kid.ID); } var contracts = GetContracts(c => c.MotherId == id).ToList(); foreach (var c in contracts) { RemoveContract(c.ContractNumber); } return(true); }
public Mother GetMother(int id) { var m = (from mother in Mothers.Elements() where Convert.ToInt32(mother.Element("ID").Value) == id select mother).FirstOrDefault().ToMother(); return(m); }
public void UpdateMother(Mother m) { XElement updateMother = (from mother in Mothers.Elements() where Convert.ToInt32(mother.Element("ID").Value) == m.ID select mother).FirstOrDefault(); if (updateMother == null) { throw new Exception("No mother with the same id..."); } int i = 0; foreach (var xElement in m.toXML().Elements()) { if (xElement.Name.ToString() == "Schedule") { foreach (var xElement1 in updateMother.Element("Schedule").Elements("Day")) { xElement1.Element("IsWorking").Value = m.Schedule[i].IsWorking.ToString(); foreach (var element in xElement1.Element("Start").Elements()) { switch (element.Name.ToString()) { case "Hour": element.Value = (!(m.Schedule[i].IsWorking)) ? "0" : m.Schedule[i].StartTime.Hour.ToString(); break; case "Minute": element.Value = (!(m.Schedule[i].IsWorking)) ? "0" : m.Schedule[i].StartTime.Minute.ToString(); break; } } foreach (var element in xElement1.Element("End").Elements()) { switch (element.Name.ToString()) { case "Hour": element.Value = (!(m.Schedule[i].IsWorking)) ? "0" : m.Schedule[i].EndTime.Hour.ToString(); break; case "Minute": element.Value = (!(m.Schedule[i].IsWorking)) ? "0" : m.Schedule[i].EndTime.Minute.ToString(); break; } } i++; } } else { updateMother.Element(xElement.Name).Value = xElement.Value; } } SaveMothers(); }
public bool idCheck(int id) { var check1 = (from mother in Mothers.Elements() where Convert.ToInt32(mother.Element("ID").Value) == id select mother).Any(); var check2 = (from nanny in Nannies.Elements() where Convert.ToInt32(nanny.Element("ID").Value) == id select nanny).Any(); var check3 = (from child in Children.Elements() where Convert.ToInt32(child.Element("ID").Value) == id select child).Any(); return(check3 || check2 || check1); }