Mini Kabibi Habibi
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Activation;
using System.Collections.ObjectModel;
using System.Xml;
using System.Web;
namespace DevExpress.MailClient.DataService {
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactsService : IContactsService {
public ObservableCollection<ServerContact> GetContacts() {
XmlDocument doc = new XmlDocument();
ObservableCollection<ServerContact> contacts = new ObservableCollection<ServerContact>();
doc.Load(HttpContext.Current.Server.MapPath("~/App_Data/VideoRent.xml"));
XmlNodeList customers = doc.GetElementsByTagName("Customer");
XmlNodeList names = doc.GetElementsByTagName("Person");
ServerContact contact = null;
foreach(XmlNode customer in customers) {
contact = new ServerContact();
contact.MiddleName = customer["MiddleName"].InnerText;
contact.Email = customer["Email"].ChildNodes[0].Value;
contact.Email = contact.Email.Replace("dxvideorent.com", "dxmail.net");
contact.Address = customer["Address"].ChildNodes[0].Value;
contact.Phone = customer["Phone"].ChildNodes[0].Value;
if(customer["Photo"] != null)
contact.Photo = Convert.FromBase64String(customer["Photo"].ChildNodes[0].Value);
FillPersonInformation(contact, names, customer["Oid"].ChildNodes[0].Value);
contacts.Add(contact);
}
return contacts;
}
void FillPersonInformation(ServerContact contact, XmlNodeList names, string id) {
foreach(XmlNode customer in names) {
if(customer["Oid"].ChildNodes[0].Value == id) {
contact.FirstName = customer["FirstName"].ChildNodes[0].Value;
contact.LastName = customer["LastName"].ChildNodes[0].Value;
contact.Gender = customer["Gender"].ChildNodes[0].Value;
contact.BirthDate = customer["BirthDate"].ChildNodes[0].Value;
}
}
}
}
}