public int Set(Contact entity)
        {
            var result = 0;

             // Load object into context (entity framework)
             var loadedEntity = _dbContext.Contacts.Where(c => c.Id== entity.Id).FirstOrDefault();

             // Modify the context
             if (loadedEntity == null)
             { //not found?
            // Add
            this._dbContext.Contacts.AddObject(entity);
             }
             else
             {
            // Update
            this._dbContext.Contacts.ApplyCurrentValues(entity);
             }

             // Save in data access (entity framework)
             result = this._dbContext.SaveChanges();

             // 2/25/2012 return entity.Id if add
             //return result;
             return loadedEntity == null ? entity.Id : result;
        }
 public int SaveContact(string Id, Contact addEditContact)
 {
     int result = 0;
      ContactBusinessEntities.Contact contact = new ContactBusinessEntities.Contact();
      contact.Id = addEditContact.Id;
      contact.FirstName = addEditContact.FirstName;
      contact.LastName = addEditContact.LastName;
      contact.Email = addEditContact.Email;
      result = _contactService.SaveContact(contact);
      return result;
 }
        public int SaveContact(string Id, Contact addEditContact)
        {
            int result = 0;

            ContactBusinessEntities.Contact contact = new ContactBusinessEntities.Contact();
            contact.Id        = addEditContact.Id;
            contact.FirstName = addEditContact.FirstName;
            contact.LastName  = addEditContact.LastName;
            contact.Email     = addEditContact.Email;
            result            = _contactService.SaveContact(contact);
            return(result);
        }
        public ContactList GetContact(string Id)
        {
            ContactList contactList = new ContactList();
             ContactView contactView = null;
             Contact contact = new Contact();

             contactView = _contactService.GetContactView(int.Parse(Id));
             contact.Id = contactView.Id;
             contact.FirstName = contactView.FirstName.Trim();
             contact.LastName = contactView.LastName.Trim();
             contact.Email = contactView.Email.Trim();
             contactList.Add(contact);

             return contactList;
        }
        public int SaveContact(Contact entity)
        {
            int result = 0;

             // Validation
             this.Errors.Clear();

             try
             {
            // Data access
            if (!this.HasErrors)
            {
               // Save
               result = this._repository.Set(entity);
            }
             }
             catch (System.Data.UpdateException ex)
             {
            if (ex.InnerException != null && ex.InnerException is System.Data.SqlClient.SqlException
               && ((System.Data.SqlClient.SqlException)ex.InnerException).ErrorCode == 8152)
               Errors.Add(ResourceStrings.ErrorMaxLength);
            else
               Errors.Add(ex.Message);
             }

             return result;
        }
 public static Contact GetModel()
 {
     var entity = new Contact();
      return entity;
 }
 private ContactView CreateContactView(Contact contact)
 {
     ContactView contactView = new ContactView();
      contactView.Id = contact.Id;
      contactView.FirstName = contact.FirstName;
      contactView.LastName = contact.LastName;
      contactView.Email = contact.Email;
      return contactView;
 }