public bool EmailExists(Contact contact)
 {
     var results = from c in _dal.Contacts()
                   where c.Email.ToLower() == contact.Email.ToLower()
                   select contact;
     return results.Any();
 }
        public void DeleteContact(Contact contact)
        {
            var doc = ContactDoc;
            var contactToDelete = (from c in doc.Descendants("Contact")
                                   where (int)c.Element("Id") == contact.Id
                                   select c).SingleOrDefault();
            contactToDelete.Remove();

            doc.Save(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Contacts.xml"));
        }
 public List<Contact> GetFriends(Contact contact)
 {
     var doc = this.FriendDoc;
     var results = from friend in doc.Descendants("Friend")
                   where (int)friend == contact.Id
                   select friend.Parent.Elements("Friend").Where(f => (int)f != contact.Id).Single();
     List<Contact> contacts = new List<Contact>();
     foreach (XElement elem in results)
         contacts.Add(new ContactBUS().GetContact(int.Parse(elem.Value)));
     return contacts;
 }
        public void CreateContact(Contact contact)
        {
            var doc = ContactDoc;
            var maxId = 0;
            if (doc.Descendants("Id").Count() > 0)
                maxId = (from id in doc.Descendants("Id")
                         select (int)id).Max();
            contact.Id = maxId + 1;

            doc.Element("Contacts").Add(MapFromContact(contact));

            doc.Save(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Contacts.xml"));
        }
 public void SetFriends(Contact contact, List<Contact> friends)
 {
     var doc = this.FriendDoc;
     var results = from friend in doc.Descendants("Friend")
                   where (int)friend == contact.Id
                   select friend.Parent;
     results.Remove();
     foreach (var friend in friends)
     {
         var elem = new XElement("FriendPair",
                                     new XElement("Friend", contact.Id),
                                     new XElement("Friend", friend.Id));
         doc.Descendants("Friends").Single().Add(elem);
     }
     doc.Save(System.Web.HttpContext.Current.Server.MapPath("~/App_Data/Friends.xml"));
 }
 public void EditContact(Contact contact)
 {
     _dal.EditContact(contact);
 }
 public void DeleteContact(Contact contact)
 {
     var friendsService = new FriendsBUS();
     friendsService.SetFriends(contact, new List<Contact>());
     _dal.DeleteContact(contact);
 }
 public void CreateContact(Contact contact)
 {
     _dal.CreateContact(contact);
 }
 public void SetFriends(Contact contact, List<Contact> friends)
 {
     friends.RemoveAll(f => f.Id == contact.Id);
     this._dal.SetFriends(contact, friends);
 }
示例#10
0
 public List<Contact> GetFriends(Contact contact)
 {
     return _dal.GetFriends(contact);
 }
 private XElement MapFromContact(Contact contact)
 {
     return new XElement("Contact",
                      new XElement("Id", contact.Id),
                      new XElement("FirstName", contact.FirstName),
                      new XElement("LastName", contact.LastName),
                      new XElement("Email", contact.Email),
                      new XElement("Username", contact.Username)
             );
 }