示例#1
0
        public override IEnumerable <Contact> GetAll()
        {
            List <Contact> ContactsRetrieved = new List <Contact>();

            try
            {
                // Read XML file and get all contacts in memory
                XDocument ContactsDocument = XDocument.Load(_DataLocation);

                // Get the root (Contacts) of the document to add new contact with existing ones
                XElement ContactsRoot = ContactsDocument.Root;

                // Get the single contact by it's ID
                IEnumerable <XElement> RetrievedContacts =
                    (from AllContacts in ContactsRoot.Elements("Contact")
                     where XMLHelper.CheckElementActiveInActive(Convert.ToInt32(AllContacts.Element("Status").Value)) == true
                     orderby Convert.ToDateTime(AllContacts.Element("CreatedOn").Value) descending
                     select AllContacts);

                if (RetrievedContacts != null)
                {
                    foreach (var RetrievedContact in RetrievedContacts)
                    {
                        var finalContact = new Contact();

                        finalContact.ID = Convert.ToInt32(RetrievedContact.Attribute("ID").Value);

                        finalContact.Name = RetrievedContact.Element("Name").Value;

                        finalContact.Email = RetrievedContact.Element("EmailID").Value;

                        finalContact.Status = (Status)Convert.ToInt32(RetrievedContact.Element("Status").Value);

                        finalContact.CreatedOn = Convert.ToDateTime(RetrievedContact.Element("CreatedOn").Value).ToLocalTime();

                        if (!string.IsNullOrEmpty(RetrievedContact.Element("LastUpdatedOn").Value))
                        {
                            finalContact.LastUpdatedOn = Convert.ToDateTime(RetrievedContact.Element("LastUpdatedOn").Value).ToLocalTime();
                        }
                        else
                        {
                            finalContact.LastUpdatedOn = null;
                        }

                        ContactsRetrieved.Add(finalContact);
                    }

                    return(ContactsRetrieved);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public override IEnumerable <MailServer> GetAll()
        {
            List <MailServer> mailServers = new List <MailServer>();

            try
            {
                XDocument MailServerDocument = XDocument.Load(_mailServerXMLDataStorageLocation);

                XElement RootMailServers = MailServerDocument.Root;

                IEnumerable <XElement> SelectedServers =
                    (from AllMailServers in RootMailServers.Elements("Server")
                     where XMLHelper.CheckElementActiveInActive(Convert.ToInt32(AllMailServers.Element("Status").Value)) == true
                     orderby Convert.ToDateTime(AllMailServers.Element("CreatedOn").Value) descending
                     select AllMailServers);

                if (SelectedServers != null)
                {
                    foreach (var SingleMailServer in SelectedServers)
                    {
                        MailServer mailServer = new MailServer();

                        mailServer.ID = Convert.ToInt32(SingleMailServer.Attribute("ID").Value);

                        mailServer.Name = SingleMailServer.Element("Name").Value;

                        mailServer.Description = SingleMailServer.Element("Description").Value;

                        mailServer.Host = SingleMailServer.Element("Host").Value;

                        mailServer.Port = Convert.ToInt32(SingleMailServer.Element("Port").Value);

                        mailServer.Username = SingleMailServer.Element("Username").Value;

                        mailServer.Password = SingleMailServer.Element("Password").Value;

                        mailServer.FromAddress = SingleMailServer.Element("FromAddress").Value;

                        mailServer.IsSecured = Convert.ToBoolean(Convert.ToInt32(SingleMailServer.Element("IsSecured").Value));

                        mailServer.Status = (Status)Convert.ToInt32(SingleMailServer.Element("Status").Value);

                        mailServer.CreatedOn = Convert.ToDateTime(SingleMailServer.Element("CreatedOn").Value).ToLocalTime();

                        if (!string.IsNullOrEmpty(SingleMailServer.Element("LastUpdatedOn").Value))
                        {
                            mailServer.LastUpdatedOn = Convert.ToDateTime(SingleMailServer.Element("LastUpdatedOn").Value).ToLocalTime();
                        }
                        else
                        {
                            mailServer.LastUpdatedOn = null;
                        }

                        mailServers.Add(mailServer);
                    }

                    return(mailServers);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }