public void UpdateContact(int contactId, Contact entity)
 {
     var contactManager = new ContactManager(this);
     var originalContact = new Contact();
     originalContact = contactManager.GetContact(contactId);
     contactManager.Update(originalContact, entity);
 }
        public void RemoveContact(Contact entity, Int32 customerId, Int32 companyId)
        {
            var ccManager = new CustomerContactManager(this);
            var cc = new CustomerContact();
            cc.ContactId = entity.ContactId;
            cc.CustomerId = customerId;
            ccManager.Delete(cc);

            var contactManager = new ContactManager(this);
            contactManager.Delete(entity);
        }
        private void SaveContact()
        {
            contactManager = new ContactManager(this);
            contact = new DataClasses.Contact();
            var originalContact = new DataClasses.Contact();

            if (!String.IsNullOrEmpty(Request["ContactId"]))
            {
                originalContact = contactManager.GetContact(Convert.ToInt32(Request["ContactId"]));
                contact.CopyPropertiesFrom(originalContact);
            }
            else contact.UserId = User.Identity.UserId;

            contact.CompanyId = Company.CompanyId;
            contact.AddressComp = ucAddress.AddressComp;
            contact.AddressNumber = ucAddress.AddressNumber;
            contact.PostalCode = ucAddress.PostalCode;

            contact.CellPhone = txtCellPhone.Text;
            contact.Email = txtMail.Text;
            contact.Msn = txtMsn.Text;
            contact.Name = txtName.Text;
            contact.Observation = txtObservation.Text;
            contact.Phone = txtPhone.Text;
            contact.Phone2 = txtPhone2.Text;
            contact.Sector = txtSector.Text;
            contact.Skype = txtSkype.Text;


            if (!String.IsNullOrEmpty(Request["ContactId"]))
                contactManager.Update(originalContact, contact);
            else
            {
                contactManager.Insert(contact);

                if (Session["CustomerId"] != null)
                {
                    var customerContact = new CustomerContact();
                    customerContact.CompanyId = Company.CompanyId;
                    customerContact.CustomerId = Convert.ToInt32(Session["CustomerId"].ToString());
                    customerContact.ContactId = contact.ContactId;
                    contactManager.InsertCustomerContact(customerContact);
                }
                else
                {
                    var supplierContact = new SupplierContact();
                    supplierContact.CompanyId = Company.CompanyId;
                    supplierContact.SupplierId = Convert.ToInt32(Session["SupplierId"].ToString());
                    supplierContact.ContactId = contact.ContactId;
                    contactManager.InsertSupplierContact(supplierContact);
                }
            }
        }
        public void AddContact(Contact entity, Int32 companyId, Int32 customerId)
        {
            var contactManager = new ContactManager(this);
            entity.CompanyId = companyId;
            contactManager.Insert(entity);

            var ccManager = new CustomerContactManager(this);
            var cc = new CustomerContact();
            cc.CustomerId = customerId;
            cc.ContactId = entity.ContactId;
            cc.CompanyId = companyId;
            ccManager.Insert(cc);
        }
        private void ShowContact()
        {
            contactManager = new ContactManager(this);
            contact = contactManager.GetContact(Convert.ToInt32(Request["ContactId"]));

            txtName.Text = contact.Name;
            txtCellPhone.Text = contact.CellPhone;
            txtMail.Text = contact.Email;
            txtMsn.Text = contact.Msn;
            txtObservation.Text = contact.Observation;
            txtPhone.Text = contact.Phone;
            txtPhone2.Text = contact.Phone2;
            txtSector.Text = contact.Sector;
            txtSkype.Text = contact.Skype;

            ucAddress.AddressComp = contact.AddressComp;
            ucAddress.AddressNumber = contact.AddressNumber;
            ucAddress.PostalCode = contact.PostalCode;
        }
        /// <summary>
        /// this method add the administrator of new company as contact of host'customer
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="userId"></param>
        private void AddContactInHostCustomer(Int32 customerId, Int32 userId)
        {
            var contactManager = new ContactManager(this);
            var customerContactManager = new CustomerContactManager(this);
            var profileManager = new ProfileManager(this);
            Profile profile = profileManager.GetProfileByUser(userId);
            var contact = new Contact
                              {
                                  Name = profile.Name,
                                  Phone = profile.Phone,
                                  CellPhone = profile.CellPhone,
                                  Address = profile.Address,
                                  AddressComp = profile.AddressComp,
                                  AddressNumber = profile.AddressNumber,
                                  Email = profile.Email,
                                  PostalCode = profile.PostalCode
                              };

            contactManager.Insert(contact);

            var customerContact = new CustomerContact();
            customerContact.CompanyId = GetHostCompany().CompanyId;
            customerContact.ContactId = contact.ContactId;
            customerContact.CustomerId = customerId;
            customerContactManager.Insert(customerContact);
        }
        /// <summary>
        /// Basic Delete Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="supplierId"></param>
        /// <param name="companyId"></param>
        public void RemoveContact(Contact entity, Int32 supplierId, Int32 companyId)
        {
            var scManager = new SuppliersContactManager(this);
            var sc = new SupplierContact
                         {
                             SupplierId = supplierId,
                             ContactId = entity.ContactId
                         };
            scManager.Delete(sc);

            var contactManager = new ContactManager(this);
            contactManager.Delete(entity);
        }
        /// <summary>
        /// Basic Insert Method
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="companyId"></param>
        /// <param name="supplierId"></param>
        public void AddContact(Contact entity, Int32 companyId, Int32 supplierId)
        {
            var contactManager = new ContactManager(this);
            entity.CompanyId = companyId;
            contactManager.Insert(entity);

            var scManager = new SuppliersContactManager(this);
            var sc = new SupplierContact();
            sc.SupplierId = supplierId;
            sc.ContactId = entity.ContactId;
            sc.CompanyId = companyId;
            scManager.Insert(sc);
        }
        protected void txtContact_TextChanged(object sender, EventArgs e)
        {
            OnSelectingContact(this, new SelectingContactEventArgs() { ContactName = txtContact.Text });

            var contactManager = new ContactManager(this);
            contact = contactManager.GetContact(Page.Company.CompanyId, txtContact.Text);

            ShowContact(contact);
            //txtContact.Text = string.Empty;
        }
 public ClientResponse FindContacts(string q, int limit)
 {
     return new ClientResponse(() =>
     {
         using (var manager = new ContactManager(null))
             return manager.SearchContacts(Company.CompanyId, q, limit).ToArray();
     });
 }