public ContactResults GetContactByPartyId(int partyId, string baseUrl)
        {
            SqlConnection cn = Connect();
            DataSet       ds = new DataSet();

            try
            {
                using (SqlCommand cmd = new SqlCommand("GetContactByPartyId", cn))
                {
                    cmd.Parameters.AddWithValue("@PartyId", partyId);
                    cmd.CommandType = CommandType.StoredProcedure;
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(ds);
                    }
                }

                DataTable t = FirstTable(ds);

                if (t == null)
                {
                    return(null);
                }

                ContactResults cr = new ContactResults();

                foreach (DataRow r in t.Rows)
                {
                    int    contactId = Convert.ToInt32(r["id"]);
                    string type      = Convert.ToString(r["sub_type"]);
                    string detail    = Convert.ToString(r["detail"]);
                    string link      = string.Format("{0}contact/{1}",
                                                     baseUrl, contactId);

                    cr.ContactList.Add
                        (new ContactSummary(contactId, type, detail, link));
                }

                return(cr);
            }
            finally
            {
                Disconnect(cn);
            }
        }
        public ContactResults GetContactByPartyId(int partyId, string baseUrl)
        {
            using (PartyEntities context = new PartyEntities(this.connectionString))
            {
                ContactResults contactResults = new ContactResults();

                var contactQuery = context.ExecuteStoreQuery <ContactSummary>(
                    "execute dbo.GetContactByPartyId {0}", partyId);

                foreach (ContactSummary contactSummary in contactQuery)
                {
                    contactSummary.Link =
                        string.Format("{0}contact/{1}", baseUrl, contactSummary.Id);
                    contactResults.ContactList.Add(contactSummary);
                }

                return(contactResults);
            }
        }
Example #3
0
        public ContactResults GetContactsByParty(string idStr)
        {
            try
            {
                int    id;
                string baseUrl = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.BaseUri.AbsoluteUri;

                if (!int.TryParse(idStr, out id))
                {
                    throw (new WebFaultException <Error>(
                               new Error(string.Format("'{0}' is not a valid party identifier", idStr)),
                               HttpStatusCode.OK));
                }

                ContactResults contactResults = database.GetContactByPartyId(id, baseUrl);

                return(contactResults);
            }
            catch (Exception ex)
            {
                throw MakeWebFaultException(ex);
            }
        }
        public ContactResults GetContactByPartyId(int partyId, string baseUrl)
        {
            SqlConnection cn = Connect();
            DataSet ds = new DataSet();
            try
            {

                using (SqlCommand cmd = new SqlCommand("GetContactByPartyId", cn))
                {
                    cmd.Parameters.AddWithValue("@PartyId", partyId);
                    cmd.CommandType = CommandType.StoredProcedure;
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        da.Fill(ds);
                    }
                }

                DataTable t = FirstTable(ds);

                if (t == null) { return null; }

                ContactResults cr = new ContactResults();

                foreach (DataRow r in t.Rows)
                {
                    int contactId = Convert.ToInt32(r["id"]);
                    string type = Convert.ToString(r["sub_type"]);
                    string detail = Convert.ToString(r["detail"]);
                    string link = string.Format("{0}contact/{1}",
                        baseUrl, contactId);

                    cr.ContactList.Add
                        (new ContactSummary(contactId, type, detail, link));
                }

                return cr;

            }
            finally
            {
                Disconnect(cn);
            }
        }
        public ContactResults GetContactByPartyId(int partyId, string baseUrl)
        {
            using (PartyEntities context = new PartyEntities(this.connectionString))
            {
                ContactResults contactResults = new ContactResults();

                var contactQuery = context.ExecuteStoreQuery<ContactSummary>(
                    "execute dbo.GetContactByPartyId {0}", partyId);

                foreach (ContactSummary contactSummary in contactQuery)
                {
                    contactSummary.Link =
                        string.Format("{0}contact/{1}", baseUrl, contactSummary.Id);
                    contactResults.ContactList.Add(contactSummary);
                }

                return contactResults;
            }
        }