public void UpdateNanny(Nanny n)
        {
            var updateNanny = (from nanny in Nannies.Elements()
                               where Convert.ToInt32(nanny.Element("ID").Value) == n.ID
                               select nanny).FirstOrDefault();

            if (updateNanny == null)
            {
                throw new Exception("No mother with the same id...");
            }
            var i = 0;

            foreach (var xElement in updateNanny.Elements())
            {
                if (xElement.Name.ToString() == "Schedule")
                {
                    foreach (var xElement1 in updateNanny.Element("Schedule").Elements("Day"))
                    {
                        xElement1.Element("IsWorking").Value = n.Schedule[i].IsWorking.ToString();
                        foreach (var element in xElement1.Element("Start").Elements())
                        {
                            switch (element.Name.ToString())
                            {
                            case "Hour":

                                element.Value = (!(n.Schedule[i].IsWorking))?"0": n.Schedule[i].StartTime.Hour.ToString();
                                break;

                            case "Minute":
                                element.Value = (!(n.Schedule[i].IsWorking)) ? "0" : n.Schedule[i].StartTime.Minute.ToString();
                                break;
                            }
                        }
                        foreach (var element in xElement1.Element("End").Elements())
                        {
                            switch (element.Name.ToString())
                            {
                            case "Hour":
                                element.Value = (!(n.Schedule[i].IsWorking)) ? "0" : n.Schedule[i].EndTime.Hour.ToString();
                                break;

                            case "Minute":
                                element.Value = (!(n.Schedule[i].IsWorking)) ? "0" : n.Schedule[i].EndTime.Minute.ToString();
                                break;
                            }
                        }
                        i++;
                    }
                }
                else
                {
                    updateNanny.Element(xElement.Name).Value = xElement.Value;
                }
            }

            SaveNannies();
        }
 public void AddNanny(Nanny nanny)
 {
     if (!idCheck(nanny.ID))
     {
         Nannies.Add(nanny.toXML());
         SaveNannies();
     }
     else
     {
         throw new Exception("ID already exists...");
     }
 }
        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);
        }
        public bool RemoveNanny(int id)
        {
            if (Contracts.Elements().Any(contract => Convert.ToInt32(contract.Element("NannyID")) == id))
            {
                throw new Exception("Nanny still has existing contracts...");
            }
            var temp = (from nanny in Nannies.Elements()
                        where Convert.ToInt32(nanny.Element("ID").Value) == id
                        select nanny).FirstOrDefault();

            if (temp == null)
            {
                throw new Exception("No nanny with same id was found... ");
            }
            temp.Remove();
            SaveNannies();
            return(true);
        }
 public Nanny GetNanny(int id)
 {
     return(((from nanny in Nannies.Elements()
              where Convert.ToInt32(nanny.Element("ID").Value) == id
              select nanny).FirstOrDefault()).ToNanny());
 }