示例#1
0
        public int Add(Models.ModelContact value)
        {
            var entity = new Contact
            {
                Id        = value.Id,
                Name      = value.Name,
                DateAdded = DateTime.UtcNow
            };

            if (value.Phones != null)
            {
                foreach (var phone in value.Phones)
                {
                    entity.ContactPhones.Add(new ContactPhone
                    {
                        PhoneNumber = phone.Number,
                        PhoneType   = phone.PhoneType.ToString()
                    });
                }
            }

            db.Contacts.Add(entity);

            db.SaveChanges();

            return(entity.Id);
        }
示例#2
0
        public void UpdateById(int id, Models.ModelContact value)
        {
            var entity = db.Contacts.SingleOrDefault(t => t.Id == id);

            if (entity != null)
            {
                entity.Name = value.Name;
                //contact.Phones = value.Phones;

                db.SaveChanges();
            }
        }