public IHttpActionResult GetEmails(long contactID, int?contactTypeID)
 {
     return(new HttpResult <Response <ContactEmailModel> >(_emailDataProvider.GetEmails(contactID, contactTypeID), Request));
 }
Пример #2
0
        /// <summary>
        /// Gets the contact.
        /// </summary>
        /// <param name="contactID">The contact identifier</param>
        /// <param name="contactTypeID">The contact type identifier</param>
        /// <returns>Response</returns>
        public virtual Response <Model> GetContact(long contactID, int?contactTypeID)
        {
            //var procsParameters = new List<SqlParameter> { new SqlParameter("ContactID", contactID) };
            var procsParameters = BuildContactGetParams(contactID, contactTypeID);

            var contactRepository = _unitOfWork.GetRepository <Model>(SchemaName.Registration);
            var contactResults    = contactRepository.ExecuteStoredProc(GetStoredProcedureName, procsParameters);

            if (contactResults == null || contactResults.ResultCode != 0)
            {
                return(contactResults);
            }

            if (contactResults.DataItems.Count == 0)
            {
                return(contactResults);
            }
            var addressResults = _addressDataProvider.GetAddresses(contactID, contactTypeID);

            if (addressResults.ResultCode != 0)
            {
                contactResults.ResultCode    = addressResults.ResultCode;
                contactResults.ResultMessage = addressResults.ResultMessage;
            }
            else
            {
                contactResults.DataItems.ForEach(m =>
                {
                    m.Addresses =
                        (addressResults.DataItems.Where(a => a.ContactID == m.ContactID).OrderByDescending(a => a.IsPrimary).ThenByDescending(a => a.ContactAddressID).Take(1).ToList());
                });
            }
            var phoneResults = _phoneDataProvider.GetPhones(contactID, contactTypeID);

            if (phoneResults.ResultCode != 0)
            {
                contactResults.ResultCode    = phoneResults.ResultCode;
                contactResults.ResultMessage = phoneResults.ResultMessage;
            }
            else
            {
                contactResults.DataItems.ForEach(m =>
                {
                    m.Phones = (phoneResults.DataItems.Where(a => a.ContactID == m.ContactID).OrderByDescending(a => a.IsPrimary).ThenByDescending(a => a.ContactPhoneID).Take(1).ToList());
                });
            }

            var emailResults = _emailDataProvider.GetEmails(contactID, contactTypeID);

            if (emailResults.ResultCode != 0)
            {
                contactResults.ResultCode    = emailResults.ResultCode;
                contactResults.ResultMessage = emailResults.ResultMessage;
            }
            else
            {
                contactResults.DataItems.ForEach(m =>
                {
                    m.Emails = (emailResults.DataItems.Where(a => a.ContactID == m.ContactID).OrderByDescending(a => a.IsPrimary).ThenByDescending(a => a.ContactEmailID).Take(1).ToList());
                });
            }

            var clientIdentifierResults = _clientIdentifierDataProvider.GetContactClientIdentifiers(contactID);

            if (clientIdentifierResults.ResultCode != 0)
            {
                contactResults.ResultCode    = clientIdentifierResults.ResultCode;
                contactResults.ResultMessage = clientIdentifierResults.ResultMessage;
            }
            else
            {
                contactResults.DataItems.ForEach(m =>
                {
                    m.ClientAlternateIDs = (clientIdentifierResults.DataItems.Where(a => a.ContactID == m.ContactID).ToList());
                });
            }


            return(contactResults);
        }