Ejemplo n.º 1
0
        internal ContactDetailViewModel GetFirst(string key = "Phone")
        {
            var model       = new ContactDetailViewModel();
            var contactType = ContactType.GetFirst(key);

            if (contactType != null)
            {
                model.ContactTypeId = contactType.Id;
                model.ContactText   = contactType.Name;
                model.IsDeleted     = contactType.IsDeleted;
            }

            return(model);
        }
Ejemplo n.º 2
0
        public AddressBookViewModel(AddressBook addressBook = null) : this()
        {
            if (addressBook == null)
            {
                var newContact = new ContactDetailViewModel();
                this.ContactDetails.Add(newContact.GetFirst());
                return;
            }

            ApplicationDbContext db = new ApplicationDbContext();

            Mapper.Initialize(cfg => { cfg.CreateMap <AddressBook, AddressBookViewModel>(); });
            Mapper.Map <AddressBook, AddressBookViewModel>(addressBook, this);

            var contactDetails = db.ContactDetails.Where(x => x.AddressBookId == addressBook.Id);

            if (!contactDetails.Any())
            {
                var newContact = new ContactDetailViewModel();
                this.ContactDetails.Add(newContact.GetFirst());
                return;
            }

            foreach (var item in contactDetails)
            {
                var contactDetail = new ContactDetailViewModel()
                {
                    Id            = item.Id,
                    ContactTypeId = item.ContactTypeId,
                    ContactText   = item.ContactText,
                    IsDeleted     = item.IsDeleted
                };
                this.ContactDetails.Add(contactDetail);
            }

            return;
        }