Beispiel #1
0
        /// <summary>
        /// Get a category, or create one if it doesn' exist.
        /// </summary>
        protected ContactCategoryModel GetCategory(string categoryTitle)
        {
            foreach (var category in AppViewModel.AllContacts.Contacts.Categories)
            {
                if (category.Title == categoryTitle)
                {
                    return(category);
                }
            }

            var newCategory = new ContactCategoryModel {
                Title = categoryTitle
            };

            AppViewModel.AllContacts.Contacts.Categories.Add(newCategory);

            return(newCategory);
        }
        public static void GetAllContacts(AppLevelModel appViewModel, ContactCollectionModel allContacts)
        {
            using (var db = new EventManagerDBContext())
            {
                var dict = new Dictionary <string, ContactCategoryModel>();
                foreach (var contact in db.Contacts)
                {
                    // Get contact category name
                    var catName = appViewModel.Settings.UserNameInStandardFormat.Value
                        ? contact.LastName[0].ToString().ToUpper() : contact.FirstName[0].ToString().ToUpper();

                    // Get category, or create one if it doesn't exist.
                    ContactCategoryModel category;
                    if (dict.ContainsKey(catName))
                    {
                        category = dict[catName];
                    }
                    else
                    {
                        category = new ContactCategoryModel {
                            Title = catName.ToUpper()
                        };
                        dict.Add(catName, category);
                        allContacts.Categories.Add(category);
                    }

                    // Add to list of contacts
                    allContacts.Add(new ContactItemModel(appViewModel)
                    {
                        ID            = contact.ContactID,
                        EmailAddress  = contact.EmailAddress,
                        EmailAddress2 = contact.EmailAddress2,
                        FirstName     = contact.FirstName,
                        LastName      = contact.LastName,
                        PhoneNumber   = contact.PhoneNumber,
                        PhoneNumber2  = contact.PhoneNumber2,
                        Category      = category,
                        ImagePath     = contact.ImagePath
                    });
                }
            }
        }