void IDL.updateTester(int id, Tester updatedTester, bool[,] updatedSchedule)
        {
            XElement testerElement = (from item in TesterRoot.Elements()
                                      where int.Parse(item.Element("ID").Value) == id
                                      select item).FirstOrDefault();

            if (testerElement == null)
            {
                throw new TestersIdNotFoundException(id);
            }
            testerElement.Remove();
            TesterRoot.Add(updatedTester.ToXmlTester());
            TesterRoot.Save(TesterPath);

            XElement scheduleXelement =
                ScheduleRoot.Elements()
                .Where(item => item.Element("ID").Value == id.ToString())
                .FirstOrDefault();

            if (scheduleXelement != null)
            {
                scheduleXelement.Remove();
            }

            XElement testersId = new XElement("ID", id.ToString());

            ScheduleRoot.Add(new XElement("TesterSchedule", testersId, updatedSchedule.ToXmlSchedule()));
            ScheduleRoot.Save(SchedulePath);
        }
Esempio n. 2
0
        /// <summary>
        /// remove tester from the root
        /// </summary>
        /// <param name="id"></param>
        public void RemoveTester(string id)
        {
            var toRemove = (from tester in TesterRoot.Elements()
                            where tester.Element("id").Value == id
                            select tester).FirstOrDefault();

            toRemove.Remove();
            TesterRoot.Save(TesterPath);
        }
Esempio n. 3
0
        /// <summary>
        /// manual tester serialize
        /// </summary>
        /// <param name="tester"></param>
        public void AddTester(Tester tester)
        {
            XElement        ID                 = new XElement("id", tester.ID);
            XElement        FirstName          = new XElement("firstName", tester.Name.first);
            XElement        LastName           = new XElement("lastName", tester.Name.last);
            XElement        Name               = new XElement("name", LastName, FirstName);
            XElement        Street             = new XElement("street", tester.Address.street);
            XElement        BuildingNumber     = new XElement("bldNumber", tester.Address.buildingNumber);
            XElement        City               = new XElement("City", tester.Address.city);
            XElement        Address            = new XElement("Address", BuildingNumber, Street, City);
            XElement        phone              = new XElement("Phone", tester.PhoneNumber);
            XElement        email              = new XElement("Email", tester.Email);
            XElement        BirthDay           = new XElement("BirthDay", tester.BirthDay);
            XElement        sex                = new XElement("Gender", tester.Sex);
            XElement        CheckEmail         = new XElement("CheckEmail", tester.CheckEmail);
            XElement        AwaitingAdminReset = new XElement("AwaitingAdminReset", tester.AwaitingAdminReset);
            XElement        firstLogin         = new XElement("FirstLogin", tester.FirstLogIn);
            XElement        testingCarType     = new XElement("VehicleType", tester.testingCarType);
            XElement        MaxDistance        = new XElement("MaxDistance", tester.MaxDistance);
            XElement        ExpYears           = new XElement("ExpYears", tester.ExpYears);
            XElement        MaxWeeklyTests     = new XElement("MaxWeeklyTests", tester.MaxWeeklyTests);
            List <XElement> Days               = new List <XElement>();

            foreach (var item in tester.schedule.week)
            {
                string HourString = "";
                for (int i = 9; i < 15; i++)
                {
                    if (item.Value[i])
                    {
                        HourString += i.ToString() + ",";
                    }
                }
                if (HourString.Length > 0)
                {
                    HourString = HourString.Substring(0, HourString.Length - 1);
                }
                Days.Add(new XElement(item.Key.ToString(), HourString));
            }
            List <XElement> Notifications = new List <XElement>();

            foreach (var item in tester.notifications)
            {
                XElement Icon    = new XElement("Icon", item.Icon);
                XElement Time    = new XElement("Time", item.time);
                XElement Message = new XElement("Message", item.message);
                Notifications.Add(new XElement("Notification", Icon, Message, Time));
            }
            XElement Schedule = new XElement("Schedule", Days);
            XElement Tester   = new XElement("Tester", ID, Name, sex, phone, email,
                                             BirthDay, Address, CheckEmail, AwaitingAdminReset, firstLogin, testingCarType, MaxDistance,
                                             ExpYears, MaxWeeklyTests, Schedule, new XElement("Notifications", Notifications));

            TesterRoot.Add(Tester);
            TesterRoot.Save(TesterPath);
        }
        void IDL.removeTester(int id)
        {
            XElement testerElement = (from tester in TesterRoot.Elements()
                                      where int.Parse(tester.Element("ID").Value) == id
                                      select tester).FirstOrDefault();

            if (testerElement == null)
            {
                throw new TestNumberNotFoundException("thrown from: DL.Dal_XML_imp.removeTester");
            }
            testerElement.Remove();
            TesterRoot.Save(TesterPath);
        }
        void IDL.addTester(Tester tester, bool[,] schedule)
        {
            int id = (from item in TesterRoot.Elements()
                      where (int.Parse(item.Element("ID").Value) == tester.ID)
                      select(int.Parse(item.Element("ID").Value))).FirstOrDefault();

            if (id != 0)
            {
                throw new TestersIdAlreadyExistsException(tester.ID, tester.FirstName + " " + tester.LastName);
            }

            TesterRoot.Add(tester.ToXmlTester());
            TesterRoot.Save(TesterPath);

            XElement testersId = new XElement("ID", tester.ID.ToString());

            ScheduleRoot.Add(new XElement("TesterSchedule", testersId, schedule.ToXmlSchedule()));
            ScheduleRoot.Save(SchedulePath);
        }