Ejemplo n.º 1
0
        private bool EditContact(GetContactInfoByContactID_Result Model)
        {
            int siteCoID = siteusercompanyid;

            CommonRepository   repo    = new CommonRepository();
            CoContactCompanies company = null;

            if (!string.IsNullOrWhiteSpace(Model.ContactCompany))
            {
                company = repo.AddCompany(siteCoID, Model.ContactCompany);
            }
            if (company == null)
            {
                company = new CoContactCompanies()
                {
                    ContactCoID = 0
                };
            }

            CoContacts contact = db.CoContacts
                                 .Include(p => p.CoContactAddresses)
                                 .Include(p => p.CoContactEmails)
                                 .Where(p => p.ContactID == Model.ViewID).FirstOrDefault();

            contact.ContactID        = Model.ViewID;
            contact.SiteCoID         = siteCoID;
            contact.ContactTypeID    = Model.ContactTypeID ?? 0;
            contact.ContactSubtypeID = Model.ContactSubtypeID ?? 0;
            contact.ContactStatusID  = Model.ContactStatusID;
            contact.ContactFirstName = Model.ContactFirst;
            contact.ContactLastName  = Model.ContactLast;
            contact.ContactCoID      = company.ContactCoID;
            contact.ModifiedDate     = DateTime.Now;
            contact.ContactManager   = Model.ContactOwnerID;
            contact.Custom1          = Model.Custom1;
            contact.Custom2          = Model.Custom2;
            contact.Custom3          = Model.Custom3;
            contact.Custom4          = Model.Custom4;
            db.SaveChanges();

            repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Mobile, Model.Mobile, true);
            repo.UpdatePhone(Model.ViewID, (int)EnumWrapper.PhoneTypes.Phone, Model.Phone, true);
            repo.UpdateEmail(Model.ViewID, Model.ContactEmail, true);
            repo.UpdateAddress(Model.ViewID, new CoContactAddresses()
            {
                Address1      = Model.ContactAddress1,
                Address2      = Model.ContactAddress2,
                City          = Model.ContactCity,
                State         = Model.ContactState,
                Zip           = Model.ContactZip,
                CountryID     = Model.CountryID,
                AddressTypeID = (int)EnumWrapper.AddressTypes.Main
            });
            return(true);
        }
        private int SaveContact(PeopleModels.NewContact Model)
        {
            int siteCoID = siteusercompanyid;

            CommonRepository   repo    = new CommonRepository();
            CoContactCompanies company = null;

            if (!string.IsNullOrWhiteSpace(Model.Company))
            {
                company = repo.AddCompany(siteCoID, Model.Company);
            }
            if (company == null)
            {
                company = new CoContactCompanies()
                {
                    ContactCoID = 0
                };
            }

            var coContact = new CoContacts()
            {
                ContactID        = Model.ContactID ?? 0,
                SiteCoID         = siteCoID,
                ContactTypeID    = Model.TypeID ?? 0,
                ContactStatusID  = Model.StatusID,
                ContactFirstName = Model.First,
                ContactLastName  = Model.Last,
                ContactCoID      = company.ContactCoID,
                ModifiedDate     = DateTime.Now,
                ContactManager   = Model.OwnerID
            };

            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Mobile, Phone = Model.Mobile, IsDefault = true
            });
            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Phone, Phone = Model.Phone, IsDefault = true
            });
            coContact.CoContactEmails.Add(new CoContactEmails()
            {
                EmailAddress = Model.Email, IsDefault = true
            });
            coContact.CoContactAddresses.Add(new CoContactAddresses()
            {
                Address1      = Model.Address1,
                Address2      = Model.Address2,
                City          = Model.City,
                State         = Model.State,
                Zip           = Model.Zip,
                CountryID     = Model.CountryID,
                AddressTypeID = (int)EnumWrapper.AddressTypes.Main
            });

            int contactID = repo.AddContact(coContact);

            if (contactID > 0)
            {
                return(contactID);
            }
            else
            {
                return(0);
            }
        }
Ejemplo n.º 3
0
        private int SaveContact(GetContactInfoByContactID_Result Model)
        {
            int siteCoID = siteusercompanyid;

            CommonRepository   repo    = new CommonRepository();
            CoContactCompanies company = null;

            if (!string.IsNullOrWhiteSpace(Model.ContactCompany))
            {
                company = repo.AddCompany(siteCoID, Model.ContactCompany);
            }
            if (company == null)
            {
                company = new CoContactCompanies()
                {
                    ContactCoID = 0
                };
            }

            var coContact = new CoContacts()
            {
                ContactID        = Model.ViewID,
                SiteCoID         = siteCoID,
                ContactTypeID    = Model.ContactTypeID ?? 0,
                ContactSubtypeID = Model.ContactSubtypeID ?? 0,
                //When creating it needs to be set to 1 Active otherwise if they do Not it errors - REQUIRED
                ContactStatusID  = Model.ContactStatusID,
                ContactFirstName = Model.ContactFirst,
                ContactLastName  = Model.ContactLast,
                ContactCoID      = company.ContactCoID,
                ModifiedDate     = DateTime.Now,
                Custom1          = Model.Custom1,
                Custom2          = Model.Custom2,
                Custom3          = Model.Custom3,
                Custom4          = Model.Custom4,
                ContactManager   = Model.ContactOwnerID
            };

            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Mobile, Phone = Model.Mobile, IsDefault = true
            });
            coContact.CoContactPhones.Add(new CoContactPhones()
            {
                PhoneTypeID = (int)EnumWrapper.PhoneTypes.Phone, Phone = Model.Phone, IsDefault = true
            });
            coContact.CoContactEmails.Add(new CoContactEmails()
            {
                EmailAddress = Model.ContactEmail, IsDefault = true
            });
            coContact.CoContactAddresses.Add(new CoContactAddresses()
            {
                Address1      = Model.ContactAddress1,
                Address2      = Model.ContactAddress2,
                City          = Model.ContactCity,
                State         = Model.ContactState,
                Zip           = Model.ContactZip,
                CountryID     = Model.CountryID,
                AddressTypeID = (int)EnumWrapper.AddressTypes.Main
            });

            int contactID = repo.AddContact(coContact);

            if (contactID > 0)
            {
                return(contactID);
            }
            else
            {
                return(0);
            }
        }