예제 #1
0
        public HostingUnit RecieveHostingUnit(int key)
        {
            HostingUnitRoot = XElement.Load(HostingUnitPath);
            HostingUnitXML hostingUnitXML = new HostingUnitXML();

            try
            {
                hostingUnitXML = (from HU in HostingUnitRoot.Elements()
                                  where int.Parse(HU.Element("Key").Value) == key
                                  select new HostingUnitXML()
                {
                    Key = int.Parse(HU.Element("Key").Value),
                    Owner = int.Parse(HU.Element("Owner").Value),
                    PricePerNight = int.Parse(HU.Element("PricePerNight").Value),
                    HostingUnitName = HU.Element("HostingUnitName").Value,
                    Area = (DO.Location)Enum.Parse(typeof(DO.Location), HU.Element("Area").Value),
                    Diary_XML = (from boolean in HU.Element("Diary").Elements()
                                 select bool.Parse(boolean.Value)).ToArray(),
                    Status = (DO.Status)Enum.Parse(typeof(DO.Status), HU.Element("Status").Value),
                    WIFI = bool.Parse(HU.Element("WIFI").Value),
                    SwimmingPool = bool.Parse(HU.Element("SwimmingPool").Value),
                    Kitchen = bool.Parse(HU.Element("Kitchen").Value),
                    TV = bool.Parse(HU.Element("TV").Value),
                    Jacuzzi = bool.Parse(HU.Element("Jacuzzi").Value),
                    ImageLink1 = HU.Element("ImageLink1").Value,
                    ImageLink2 = HU.Element("ImageLink2").Value,
                    ImageLink3 = HU.Element("ImageLink3").Value
                }).FirstOrDefault();
            }
            catch
            {
                return(null);
            }
            return(hostingUnitXML == null ? null : hostingUnitXML.ConvertToDO());
        }
예제 #2
0
        public void AddHostingUnit(HostingUnit hosting)
        {
            HostingUnitXML hostingUnit = hosting.ConvertToHostingUnitXML();
            XElement       area        = new XElement("Area", hostingUnit.Area);
            XElement       diary       = new XElement("Diary");

            foreach (var item in hostingUnit.Diary_XML)
            {
                diary.Add(new XElement("bool", item));
            }
            XElement hostingunitname = new XElement("HostingUnitName", hostingUnit.HostingUnitName);
            XElement link            = new XElement("ImageLink1", hostingUnit.ImageLink1);
            XElement link2           = new XElement("ImageLink2", hostingUnit.ImageLink2);
            XElement link3           = new XElement("ImageLink3", hostingUnit.ImageLink3);
            XElement jacuzzi         = new XElement("Jacuzzi", hostingUnit.Jacuzzi);
            XElement key             = new XElement("Key", hostingUnit.Key);
            XElement kitchen         = new XElement("Kitchen", hostingUnit.Kitchen);
            XElement wifi            = new XElement("WIFI", hostingUnit.WIFI);
            XElement pricepernight   = new XElement("PricePerNight", hostingUnit.PricePerNight);
            XElement owner           = new XElement("Owner", hostingUnit.Owner);
            XElement status          = new XElement("Status", hostingUnit.Status);
            XElement swimmingpool    = new XElement("SwimmingPool", hostingUnit.SwimmingPool);
            XElement tv = new XElement("TV", hostingUnit.TV);
            XElement HU = new XElement("HostingUnit", key, hostingunitname, area, link, link2, link3, jacuzzi, diary, kitchen, wifi, pricepernight, owner, status, swimmingpool, tv);

            HostingUnitRoot.Add(HU);
            HostingUnitRoot.Save(HostingUnitPath);
        }
예제 #3
0
        public static HostingUnitXML ConvertToHostingUnitXML(this HostingUnit hostingUnit)
        {
            HostingUnitXML hostingUnitXML = new HostingUnitXML()
            {
                HostingUnitName = hostingUnit.HostingUnitName,
                Key             = hostingUnit.Key,
                Owner           = hostingUnit.Owner,
                Status          = (DO.Status)hostingUnit.Status,
                Area            = (DO.Location)hostingUnit.Area,
                ImageLink1      = hostingUnit.ImageLink1,
                ImageLink2      = hostingUnit.ImageLink2,
                ImageLink3      = hostingUnit.ImageLink3,
                Jacuzzi         = hostingUnit.Jacuzzi,
                Kitchen         = hostingUnit.Kitchen,
                SwimmingPool    = hostingUnit.SwimmingPool,
                TV            = hostingUnit.TV,
                WIFI          = hostingUnit.WIFI,
                PricePerNight = hostingUnit.PricePerNight,
                Diary         = hostingUnit.Diary
            };

            return(hostingUnitXML);
        }
예제 #4
0
        public static HostingUnit ConvertToDO(this HostingUnitXML hostingUnitXML)
        {
            HostingUnit hostingUnit = new HostingUnit()
            {
                Diary           = hostingUnitXML.Diary,
                HostingUnitName = hostingUnitXML.HostingUnitName,
                Key             = hostingUnitXML.Key,
                Owner           = hostingUnitXML.Owner,
                Status          = (DO.Status)hostingUnitXML.Status,
                Area            = (DO.Location)hostingUnitXML.Area,
                ImageLink1      = hostingUnitXML.ImageLink1,
                ImageLink2      = hostingUnitXML.ImageLink2,
                ImageLink3      = hostingUnitXML.ImageLink3,
                Jacuzzi         = hostingUnitXML.Jacuzzi,
                Kitchen         = hostingUnitXML.Kitchen,
                SwimmingPool    = hostingUnitXML.SwimmingPool,
                TV            = hostingUnitXML.TV,
                WIFI          = hostingUnitXML.WIFI,
                PricePerNight = hostingUnitXML.PricePerNight
            };

            return(hostingUnit);
        }
예제 #5
0
        public IEnumerable <HostingUnit> GetHostingUnitsList(Func <HostingUnit, bool> predicate)
        {
            HostingUnitXML hostingUnit = new HostingUnitXML();

            return(XML.GetHostingunits().Select(x => x.ConvertToDO()).Where(predicate));
        }