public StoreDetails GetStoreDetails()
        {
            StoreDetails storeDetails = new StoreDetails();

            XmlNode rootNode = Document.DocumentElement;

            storeDetails.Name = rootNode.SelectSingleNode("name").InnerText;

            MapAddressInformation(rootNode.SelectSingleNode("address"), ref storeDetails);
            MapContactInformation(rootNode.SelectSingleNode("contact"), ref storeDetails);
            MapOpeningHours(rootNode.SelectSingleNode("openinghours"), ref storeDetails);

            return storeDetails;
        }
        public void Update(StoreDetails storeDetails)
        {
            Condition.Requires(storeDetails).IsNotNull();
            Condition.Requires(storeDetails.Name).IsNotNullOrWhiteSpace();
            Condition.Requires(storeDetails.OpeningHours).IsNotNull().HasLength(7);
            Condition.Requires(storeDetails.Contact).IsNotNull();
            Condition.Requires(storeDetails.Contact.Email).IsNotNullOrWhiteSpace();
            Condition.Requires(storeDetails.Contact.Telephone).IsNotNullOrWhiteSpace();
            Condition.Requires(storeDetails.Address).IsNotNull();
            Condition.Requires(storeDetails.Address.Town).IsNotNullOrWhiteSpace();
            Condition.Requires(storeDetails.Address.Postal).IsInRange(0, 9999);
            Condition.Requires(storeDetails.Address.Number).IsGreaterThan(0);

            Dependencies.StoreDetailsRepository.Update(storeDetails);
        }
        public ActionResult Update(IndexStoreDetailsViewModel requestedViewModel)
        {
            List<int> openingHours = new List<int>();
            ValidateOpeningHours(requestedViewModel.OpeningHour, "OpeningHour", ref openingHours);

            List<int> closingHours = new List<int>();
            ValidateOpeningHours(requestedViewModel.CloseingHour, "CloseingHour", ref closingHours);

            if (ModelState.IsValid)
            {
                StoreDetails storeDetails = new StoreDetails();

                storeDetails.Name = requestedViewModel.Name;

                storeDetails.Address = new StoreDetails.AddressInformation
               {
                   Number = requestedViewModel.Address.Number,
                   Postal = requestedViewModel.Address.Postal,
                   Road = requestedViewModel.Address.Road,
                   Town = requestedViewModel.Address.Town
               };

                storeDetails.Contact = new StoreDetails.ContactInformation
                {
                    Email = requestedViewModel.Contact.Email,
                    Mobilephone = requestedViewModel.Contact.Mobilephone,
                    Telephone = requestedViewModel.Contact.Telephone
                };

                for (int i = 0; i < 7; i++)
                {
                    storeDetails.OpeningHours.Add(new StoreDetails.OpeningHour
                    {
                        Day = i,
                        Closeing = closingHours.ElementAt(i),
                        Opening = openingHours.ElementAt(i)
                    });
                }

                StoreDetailService.Update(storeDetails);
            }

            return RedirectToAction("Index");
        }
        public void Update(StoreDetails storeDetails)
        {
            StringBuilder builder = new StringBuilder();
            XmlWriter writer = XmlWriter.Create(builder);

            writer.WriteStartElement("root");
            {
                writer.WriteStartElement("name");
                writer.WriteString(storeDetails.Name);
                writer.WriteEndElement();

                writer.WriteStartElement("address");
                {
                    writer.WriteStartElement("road");
                    writer.WriteString(storeDetails.Address.Road);
                    writer.WriteEndElement();

                    writer.WriteStartElement("town");
                    writer.WriteString(storeDetails.Address.Town);
                    writer.WriteEndElement();

                    writer.WriteStartElement("postal");
                    writer.WriteString(storeDetails.Address.Postal.ToString());
                    writer.WriteEndElement();

                    writer.WriteStartElement("number");
                    writer.WriteString(storeDetails.Address.Number.ToString());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteStartElement("contact");
                {
                    writer.WriteStartElement("telephone");
                    writer.WriteString(storeDetails.Contact.Telephone);
                    writer.WriteEndElement();

                    writer.WriteStartElement("mobilephone");
                    writer.WriteString(storeDetails.Contact.Mobilephone);
                    writer.WriteEndElement();

                    writer.WriteStartElement("email");
                    writer.WriteString(storeDetails.Contact.Email);
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteStartElement("openinghours");
                {
                    foreach (var item in storeDetails.OpeningHours)
                    {
                        writer.WriteStartElement("openinghour");
                        writer.WriteAttributeString("day", item.Day.ToString());
                        writer.WriteAttributeString("opening", item.Opening.ToString());
                        writer.WriteAttributeString("closeing", item.Closeing.ToString());
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
            }
            writer.WriteEndElement();

            writer.Flush();
            writer.Close();

            string xml = builder.ToString();
            Document.LoadXml(xml);
            Document.Save(XmlLocation);
        }
        private void MapOpeningHours(XmlNode node, ref StoreDetails storeDetails)
        {
            storeDetails.OpeningHours = new List<StoreDetails.OpeningHour>();

            foreach (XmlNode n in node.ChildNodes)
            {
                if (!n.Name.Equals("openinghour")) continue;

                storeDetails.OpeningHours.Add(new StoreDetails.OpeningHour
                {
                    Day = int.Parse(n.Attributes["day"].InnerText),
                    Closeing = int.Parse(n.Attributes["closeing"].InnerText),
                    Opening = int.Parse(n.Attributes["opening"].InnerText)
                });
            }
        }
 private void MapContactInformation(XmlNode node, ref StoreDetails storeDetails)
 {
     storeDetails.Contact = new StoreDetails.ContactInformation
     {
         Email = node.SelectSingleNode("email").InnerText,
         Mobilephone = node.SelectSingleNode("mobilephone").InnerText,
         Telephone = node.SelectSingleNode("telephone").InnerText
     };
 }
 private void MapAddressInformation(XmlNode node, ref StoreDetails storeDetails)
 {
     storeDetails.Address = new StoreDetails.AddressInformation
     {
         Number = int.Parse(node.SelectSingleNode("number").InnerText),
         Postal = int.Parse(node.SelectSingleNode("postal").InnerText),
         Road = node.SelectSingleNode("road").InnerText,
         Town = node.SelectSingleNode("town").InnerText
     };
 }