Esempio n. 1
0
        public ContactModel Create(Contact contact, bool includeSelectableGroup = false)
        {
            var result = new ContactModel
            {
                FirstName = contact.FirstName,
                LastName = contact.LastName,
                Pin = contact.Pin != null ? Convert.ToInt32(contact.Pin): 0,
                Phones = contact.ContactPhones.Select(c => Create(c)),
                EmailAddresses = contact.ContactEmails.Select(c => Create(c)),
                ContactGroupId = contact.ContactGroupId
            };

            if (includeSelectableGroup)
            {
                result.SelectableGroups = _repo.GetContactGroupForUser(_identityService.CurrentUser).Select(c => Create(c,false));
            }

            return result;
        }
Esempio n. 2
0
        public bool AddContact(string username, Contact entity)
        {
            try
            {
                var user = _contex.Users.SingleOrDefault(c => c.UserID == username);
                _contex.Contacts.Add(entity);

                if (SaveAll())
                    return true;
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }
Esempio n. 3
0
        public Contact Parse(ContactModel model, string username)
        {
            try
            {
                var contact = new Contact();

                contact.FirstName = model.FirstName;
                contact.LastName = model.LastName;
                contact.Pin = model.Pin;
                contact.ContactPhones = model.Phones.Select(c => Parse(c)).ToList();
                contact.ContactEmails = model.EmailAddresses.Select(c => Parse(c)).ToList();
                contact.ContactGroup = _repo.GetContactGroup(username, model.ContactGroupId);

                return contact;
            }
            catch (Exception)
            {
                return null;
            }
        }
Esempio n. 4
0
        public ContactModel Create(Contact contact)
        {
            var result = new ContactModel
            {
                Name = contact.FirstName,
                Id = contact.Id,
                ContactGroupId = contact.ContactGroupId,
                Phones = contact.ContactPhones.Select((c => Create(c)))
            };

            return result;
        }
Esempio n. 5
0
        public Contact Parse(ContactModel model, int contactGroupId)
        {
            try
            {
                var contact = new Contact
                {
                    FirstName = model.Name,
                    ContactGroupId = contactGroupId
                };

                foreach (var contactPhoneModel in model.Phones)
                {
                    contact.ContactPhones.Add(Parse(contactPhoneModel));
                }

                ////Below code is an example of how to get ID for url's pass in to the model
                //var uri = new Uri(model.URL);
                //var notificationId = int.Parse(uri.Segments.Last());

                return contact;
            }
            catch (Exception)
            {
                return null;
            }
        }
Esempio n. 6
0
        public bool EditContact(int contactId, Contact entity)
        {
            try
            {
                var contact = _contex.Contacts.SingleOrDefault(c => c.Id == contactId);

                if (contact != null)
                {
                    contact.FirstName = entity.FirstName;
                    contact.LastName = entity.LastName;
                    contact.Pin = entity.Pin;
                    contact.ContactPhones = entity.ContactPhones;
                    contact.ContactEmails = entity.ContactEmails;

                    if (SaveAll())
                        return true;
                }

                return false;

            }
            catch (Exception)
            {
                return false;

            }
        }