Web api creation and unit testing

WEB API Creation Sample;

CreatePracticeLocationController :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Net.Http;

using System.Web.Http;

using System.Web.Http.Cors;

using CRMiPadApp.Log;

using CRMiPadApp.Models;

 

namespace CRMiPadApp.Controllers

{

public class CreatePracticeLocationController : ApiController

{

[ActionName(“CreatePracticeLocationRecord”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult CreatePracticeLocationRecord(IPADPracticeLocation inputJsonfromIos)

{

//Get wcf service interface and created one object.

CRMIPADCreatePractice.IPracticeLocation CreatePractice = new CRMIPADCreatePractice.IPracticeLocation();

outputClassCreate objnn = new outputClassCreate();

string ReturnMessage;

try

{

if (inputJsonfromIos != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

CreatePractice.AnnualRevenue = inputJsonfromIos.AnnualRevenue;

CreatePractice.BillingAddressCityID = inputJsonfromIos.BillingAddressCityID;

CreatePractice.BillingAddressCountryId = inputJsonfromIos.BillingAddressCountryId;

CreatePractice.BillingAddressFax = inputJsonfromIos.BillingAddressFax;

CreatePractice.BillingAddressLine1 = inputJsonfromIos.BillingAddressLine1;

CreatePractice.BillingAddressLine2 = inputJsonfromIos.BillingAddressLine2;

CreatePractice.BillingAddressPhone = inputJsonfromIos.BillingAddressPhone;

CreatePractice.BillingAddressStateID = inputJsonfromIos.BillingAddressStateID;

CreatePractice.BillingAddressZipID = inputJsonfromIos.BillingAddressZipID;

CreatePractice.MailingAddressCityID = inputJsonfromIos.MailingAddressCityID;

CreatePractice.MailingAddressCountryId = inputJsonfromIos.MailingAddressCountryId;

CreatePractice.MailingAddressCountyId = inputJsonfromIos.MailingAddressCountyId;

CreatePractice.MailingAddressFax = inputJsonfromIos.MailingAddressFax;

CreatePractice.MailingAddressLine1 = inputJsonfromIos.MailingAddressLine1;

CreatePractice.MailingAddressLine2 = inputJsonfromIos.MailingAddressLine2;

CreatePractice.MailingAddressPhone = inputJsonfromIos.MailingAddressPhone;

CreatePractice.MailingAddressStateID = inputJsonfromIos.MailingAddressStateID;

CreatePractice.MailingAddressZipID = inputJsonfromIos.MailingAddressZipID;

CreatePractice.NoofPhysicians = inputJsonfromIos.NoofPhysicians;

CreatePractice.NPI = inputJsonfromIos.NPI;

CreatePractice.PhysicalAddressCityID = inputJsonfromIos.PhysicalAddressCityID;

CreatePractice.PhysicalAddressCountryId = inputJsonfromIos.PhysicalAddressCountryId;

CreatePractice.PhysicalAddressCountyId = inputJsonfromIos.PhysicalAddressCountyId;

CreatePractice.PhysicalAddressFax = inputJsonfromIos.PhysicalAddressFax;

CreatePractice.PhysicalAddressLine1 = inputJsonfromIos.PhysicalAddressLine1;

CreatePractice.PhysicalAddressLine2 = inputJsonfromIos.PhysicalAddressLine2;

CreatePractice.PhysicalAddressPhone = inputJsonfromIos.PhysicalAddressPhone;

CreatePractice.PhysicalAddressStateID = inputJsonfromIos.PhysicalAddressStateID;

CreatePractice.PhysicalAddressZipID = inputJsonfromIos.PhysicalAddressZipID;

CreatePractice.PracticeID = inputJsonfromIos.PracticeID;

CreatePractice.PracticeLocationName = inputJsonfromIos.PracticeLocationName;

CreatePractice.PracticeLocationSubtype = inputJsonfromIos.PracticeLocationSubtype;

CreatePractice.PracticeLocationType = inputJsonfromIos.PracticeLocationType;

CreatePractice.PrimaryContactID = inputJsonfromIos.PrimaryContactID;

CreatePractice.PrimaryContactType = inputJsonfromIos.PrimaryContactType;

CreatePractice.SalesContactID = inputJsonfromIos.SalesContactID;

CreatePractice.Speciality = inputJsonfromIos.Speciality;

CreatePractice.TaxID = inputJsonfromIos.TaxID;

CreatePractice.TerritoryID = inputJsonfromIos.TerritoryID;

string Result = objCreatePractice.CreatePracticeLocationRecord(CreatePractice, out ReturnMessage, out objfault);

objnn.ReturnMessage = ReturnMessage;

if (Result == null)

{

if (!string.IsNullOrWhiteSpace(ReturnMessage))

{

return Ok(ReturnMessage);

}

else if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

ReturnMessage = Exec.ToString();

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(objnn);

}

[ActionName(“RetreivePracticeLocationTypes”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreivePracticeLocationTypes()

{

List<CRMIPADCreatePractice.OptionSetData> objLocationTypes = new List<CRMIPADCreatePractice.OptionSetData>();

try

{

if (objLocationTypes != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

objLocationTypes = objCreatePractice.RetreivePracticeLocationTypes(out objfault);

if (objLocationTypes == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(objLocationTypes);

}

[ActionName(“RetreivePracticeLocationSubTypes”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreivePracticeLocationSubTypes()

{

List<CRMIPADCreatePractice.OptionSetData> practicelocationsubtypes = new List<CRMIPADCreatePractice.OptionSetData>();

try

{

if (practicelocationsubtypes != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

practicelocationsubtypes = objCreatePractice.RetreivePracticeLocationSubTypes(out objfault);

if (practicelocationsubtypes == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(practicelocationsubtypes);

}

[ActionName(“RetreiveSpeciality”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveSpeciality()

{

List<CRMIPADCreatePractice.OptionSetData> RetreiveSpeciality = new List<CRMIPADCreatePractice.OptionSetData>();

try

{

if (RetreiveSpeciality != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveSpeciality = objCreatePractice.RetreiveSpeciality(out objfault);

if (RetreiveSpeciality == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveSpeciality);

}

[ActionName(“RetreiveSalesContacts”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveSalesContacts()

{

List<CRMIPADCreatePractice.PrimarySalesContactData> RetreiveSalesContacts = new List<CRMIPADCreatePractice.PrimarySalesContactData>();

try

{

if (RetreiveSalesContacts != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveSalesContacts = objCreatePractice.RetreiveSalesContacts(out objfault);

if (RetreiveSalesContacts == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveSalesContacts);

}

[ActionName(“RetreivePrimaryContacts”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreivePrimaryContacts(IpadPrimaryContactData inputJsonfromIos)

{

List<CRMIPADCreatePractice.PrimaryContactData> RetreivePrimaryContacts = new List<CRMIPADCreatePractice.PrimaryContactData>();

try

{

if (inputJsonfromIos != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreivePrimaryContacts = objCreatePractice.RetreivePrimaryContacts(inputJsonfromIos.PracticeLocationGuid, out objfault);

if (RetreivePrimaryContacts == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreivePrimaryContacts);

}

[ActionName(“RetreivePrimaryContactType”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreivePrimaryContactType()

{

CRMIPADCreatePractice.PrimaryContactData RetreivePrimaryContactType = new CRMIPADCreatePractice.PrimaryContactData();

string Result;

try

{

if (RetreivePrimaryContactType != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

Result = objCreatePractice.RetreivePrimaryContactType(RetreivePrimaryContactType, out objfault);

if (Result == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(Result);

}

[ActionName(“RetreiveZipCodes”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveZipCodes()

{

List<CRMIPADCreatePractice.ZipCodeData> RetreiveZipCodes = new List<CRMIPADCreatePractice.ZipCodeData>();

try

{

if (RetreiveZipCodes != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveZipCodes = objCreatePractice.RetreiveZipCodes(out objfault);

if (RetreiveZipCodes == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveZipCodes);

}

[ActionName(“RetreiveStates”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveStates()

{

List<CRMIPADCreatePractice.StateData> RetreiveStates = new List<CRMIPADCreatePractice.StateData>();

try

{

if (RetreiveStates != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveStates = objCreatePractice.RetreiveStates(out objfault);

if (RetreiveStates == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveStates);

}

[ActionName(“RetreiveCities”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveCities()

{

List<CRMIPADCreatePractice.CityData> RetreiveCities = new List<CRMIPADCreatePractice.CityData>();

try

{

if (RetreiveCities != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveCities = objCreatePractice.RetreiveCities(out objfault);

if (RetreiveCities == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveCities);

}

[ActionName(“RetreiveTerritory”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult RetreiveTerritory()

{

List<CRMIPADCreatePractice.TerritoryData> RetreiveTerritory = new List<CRMIPADCreatePractice.TerritoryData>();

try

{

if (RetreiveTerritory != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

RetreiveTerritory = objCreatePractice.RetreiveTerritory(out objfault);

if (RetreiveTerritory == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(RetreiveTerritory);

}

[ActionName(“FilterAddressByZip”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult FilterAddressByZip(CRMIPADCreatePractice.ZipCodeData FilterAddressByZip)

{

CRMIPADCreatePractice.StateData StateData = null;

CRMIPADCreatePractice.CityData CityData = null;

CRMIPADCreatePractice.CountryData CountryData = null;

CRMIPADCreatePractice.CountyData CountyData = null;

try

{

if (FilterAddressByZip != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

StateData = objCreatePractice.FilterAddressByZip(FilterAddressByZip, out CityData, out CountryData, out CountyData, out objfault);

if (FilterAddressByZip == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(StateData);

}

[ActionName(“FilterAddressByState”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult FilterAddressByState(CRMIPADCreatePractice.StateData FilterAddressByStat)

{

List<CRMIPADCreatePractice.ZipCodeData> objZipcodedata = new List<CRMIPADCreatePractice.ZipCodeData>();

List<CRMIPADCreatePractice.CityData> CityData = new List<CRMIPADCreatePractice.CityData>();

try

{

if (FilterAddressByStat != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

objZipcodedata = objCreatePractice.FilterAddressByState(FilterAddressByStat, out CityData, out objfault);

if (FilterAddressByStat == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(objZipcodedata);

}

[ActionName(“FilterAddressByCity”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult FilterAddressByCity(CRMIPADCreatePractice.CityData FilterAddressByCity)

{

CRMIPADCreatePractice.StateData objStaedata = new CRMIPADCreatePractice.StateData();

try

{

if (FilterAddressByCity != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

objStaedata = objCreatePractice.FilterAddressByCity(FilterAddressByCity, out objfault);

if (objStaedata == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(objStaedata);

}

[ActionName(“CheckIsDuplicateNPI”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult CheckIsDuplicateNPI(CheckDuplicateNPI inputJsonfromIos)

{

string ReturnMessage;

string Result;

try

{

if (inputJsonfromIos != null)

{

//Get wcf service and created object.

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

// Get data from wcf services.

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

Result = objCreatePractice.CheckIsDuplicateNPI(inputJsonfromIos.NPINo, out ReturnMessage, out objfault).ToString();

if (Result == null)

{

if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(Result);

}

[ActionName(“UpdatePracticeLocationRecord”)]

[EnableCors(origins: “*”, headers: “*”, methods: “*”)]

[AcceptVerbs(“GET”, “POST”)]

public IHttpActionResult UpdatePracticeLocationRecord(IPADPracticeLocation inputJsonfromIos)

{

CRMIPADCreatePractice.IPracticeLocation UpdatePracticelocation = new CRMIPADCreatePractice.IPracticeLocation();

IpadUpdatedata objinput = new IpadUpdatedata();

outputClassCreate objnn = new outputClassCreate();

string ReturnMessage;

try

{

if (inputJsonfromIos != null)

{

//Get wcf service and created object.

 

CRMiPadApp.CRMIPADCreatePractice.GeneralFaultContract objfault;

UpdatePracticelocation.AnnualRevenue = inputJsonfromIos.AnnualRevenue;

UpdatePracticelocation.BillingAddressCityID = inputJsonfromIos.BillingAddressCityID;

UpdatePracticelocation.BillingAddressCountryId = inputJsonfromIos.BillingAddressCountryId;

UpdatePracticelocation.BillingAddressFax = inputJsonfromIos.BillingAddressFax;

UpdatePracticelocation.BillingAddressLine1 = inputJsonfromIos.BillingAddressLine1;

UpdatePracticelocation.BillingAddressLine2 = inputJsonfromIos.BillingAddressLine2;

UpdatePracticelocation.BillingAddressPhone = inputJsonfromIos.BillingAddressPhone;

UpdatePracticelocation.BillingAddressStateID = inputJsonfromIos.BillingAddressStateID;

UpdatePracticelocation.BillingAddressZipID = inputJsonfromIos.BillingAddressZipID;

UpdatePracticelocation.MailingAddressCityID = inputJsonfromIos.MailingAddressCityID;

UpdatePracticelocation.MailingAddressCountryId = inputJsonfromIos.MailingAddressCountryId;

UpdatePracticelocation.MailingAddressCountyId = inputJsonfromIos.MailingAddressCountyId;

UpdatePracticelocation.MailingAddressFax = inputJsonfromIos.MailingAddressFax;

UpdatePracticelocation.MailingAddressLine1 = inputJsonfromIos.MailingAddressLine1;

UpdatePracticelocation.MailingAddressLine2 = inputJsonfromIos.MailingAddressLine2;

UpdatePracticelocation.MailingAddressPhone = inputJsonfromIos.MailingAddressPhone;

UpdatePracticelocation.MailingAddressStateID = inputJsonfromIos.MailingAddressStateID;

UpdatePracticelocation.MailingAddressZipID = inputJsonfromIos.MailingAddressZipID;

UpdatePracticelocation.NoofPhysicians = inputJsonfromIos.NoofPhysicians;

UpdatePracticelocation.NPI = inputJsonfromIos.NPI;

UpdatePracticelocation.PhysicalAddressCityID = inputJsonfromIos.PhysicalAddressCityID;

UpdatePracticelocation.PhysicalAddressCountryId = inputJsonfromIos.PhysicalAddressCountryId;

UpdatePracticelocation.PhysicalAddressCountyId = inputJsonfromIos.PhysicalAddressCountyId;

UpdatePracticelocation.PhysicalAddressFax = inputJsonfromIos.PhysicalAddressFax;

UpdatePracticelocation.PhysicalAddressLine1 = inputJsonfromIos.PhysicalAddressLine1;

UpdatePracticelocation.PhysicalAddressLine2 = inputJsonfromIos.PhysicalAddressLine2;

UpdatePracticelocation.PhysicalAddressPhone = inputJsonfromIos.PhysicalAddressPhone;

UpdatePracticelocation.PhysicalAddressStateID = inputJsonfromIos.PhysicalAddressStateID;

UpdatePracticelocation.PhysicalAddressZipID = inputJsonfromIos.PhysicalAddressZipID;

UpdatePracticelocation.PracticeID = inputJsonfromIos.PracticeID;

UpdatePracticelocation.PracticeLocationName = inputJsonfromIos.PracticeLocationName;

UpdatePracticelocation.PracticeLocationSubtype = inputJsonfromIos.PracticeLocationSubtype;

UpdatePracticelocation.PracticeLocationType = inputJsonfromIos.PracticeLocationType;

UpdatePracticelocation.PrimaryContactID = inputJsonfromIos.PrimaryContactID;

UpdatePracticelocation.PrimaryContactType = inputJsonfromIos.PrimaryContactType;

UpdatePracticelocation.SalesContactID = inputJsonfromIos.SalesContactID;

UpdatePracticelocation.Speciality = inputJsonfromIos.Speciality;

UpdatePracticelocation.TaxID = inputJsonfromIos.TaxID;

UpdatePracticelocation.TerritoryID = inputJsonfromIos.TerritoryID;

CRMIPADCreatePractice.CreatePracticeLocationClient objCreatePractice = new CRMIPADCreatePractice.CreatePracticeLocationClient();

var Result = objCreatePractice.UpdatePracticeLocationRecord(objinput.PracticeLocationId, objinput.PhysicalAddressId, objinput.BillingAddressId, objinput.MailingAddressId, UpdatePracticelocation, out ReturnMessage, out objfault);

objnn.ReturnMessage = ReturnMessage;

if (Result == null)

{

if (!string.IsNullOrWhiteSpace(ReturnMessage))

{

return Ok(ReturnMessage);

}

else if (objfault != null)

{

return Ok(objfault);

}

}

}

else

{

return NotFound();

}

}

catch (Exception Exec)

{

ReturnMessage = Exec.ToString();

APILogHelper.AddLog(Exec.ToString());

GeneralFaultInfo faultEx = APILogHelper.GetFaultContractForGeneralException(Exec);

return Ok(faultEx);

}

//List object convert to JSON and send to IPAD.

return Ok(objnn);

}

}

}

 

 

Routes Config :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

using System.Web.Routing;

 

namespace CRMiPadApp

{

public class RouteConfig

{

public static void RegisterRoutes(RouteCollection routes)

{

routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);

routes.MapRoute(

name: “Default”,

url: “{controller}/{action}/{id}”,

defaults: new { controller = “Values”, action = “Index”, id = UrlParameter.Optional }

);

}

}

}

 

WebApiConfig :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web.Http;

using System.Web.Http.Routing;

 

namespace CRMiPadApp

{

public static class WebApiConfig

{

public static void Register(HttpConfiguration config)

{

config.Routes.MapHttpRoute(

name: “DefaultApi”,

routeTemplate: “api/{controller}/{action}/{id}”,

defaults: new { id = RouteParameter.Optional }

);

}

}

}

 

Global.asax.cs :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Http;

using System.Web.Mvc;

using System.Web.Optimization;

using System.Web.Routing;

using CRMiPadApp;

 

namespace CRM

{

// Note: For instructions on enabling IIS6 or IIS7 classic mode,

// visit http://go.microsoft.com/?LinkId=9394801

 

public class WebApiApplication : System.Web.HttpApplication

{

protected void Application_Start()

{

AreaRegistration.RegisterAllAreas();

 

WebApiConfig.Register(GlobalConfiguration.Configuration);

FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

RouteConfig.RegisterRoutes(RouteTable.Routes);

BundleConfig.RegisterBundles(BundleTable.Bundles);

var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;

json.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;

 

}

}

}

 

Models:

 

CreatePractice .cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

 

namespace CRMiPadApp.Models

{

public class CreatePractice

{

 

}

public class IPADPracticeLocation

{

public decimal AnnualRevenue { get; set; }

public string BillingAddressCityID { get; set; }

public string BillingAddressCountryId { get; set; }

public string BillingAddressCountyId { get; set; }

public string BillingAddressFax { get; set; }

public string BillingAddressLine1 { get; set; }

public string BillingAddressLine2 { get; set; }

public string BillingAddressPhone { get; set; }

public string BillingAddressStateID { get; set; }

public string BillingAddressZipID { get; set; }

public string MailingAddressCityID { get; set; }

public string MailingAddressCountryId { get; set; }

public string MailingAddressCountyId { get; set; }

public string MailingAddressFax { get; set; }

public string MailingAddressLine1 { get; set; }

public string MailingAddressLine2 { get; set; }

public string MailingAddressPhone { get; set; }

public string MailingAddressStateID { get; set; }

public string MailingAddressZipID { get; set; }

public string NPI { get; set; }

public int NoofPhysicians { get; set; }

public string PhysicalAddressCityID { get; set; }

public string PhysicalAddressCountryId { get; set; }

public string PhysicalAddressCountyId { get; set; }

public string PhysicalAddressFax { get; set; }

public string PhysicalAddressLine1 { get; set; }

public string PhysicalAddressLine2 { get; set; }

public string PhysicalAddressPhone { get; set; }

public string PhysicalAddressStateID { get; set; }

public string PhysicalAddressZipID { get; set; }

public string PracticeID { get; set; }

public string PracticeLocationName { get; set; }

public int PracticeLocationSubtype { get; set; }

public int PracticeLocationType { get; set; }

public string PrimaryContactID { get; set; }

public string PrimaryContactType { get; set; }

public string SalesContactID { get; set; }

public int Speciality { get; set; }

public string TaxID { get; set; }

public string TerritoryID { get; set; }

}

public class IPracticeLocation

{

public decimal AnnualRevenue { get; set; }

public string BillingAddressCityID { get; set; }

public string BillingAddressCountryId { get; set; }

public string BillingAddressCountyId { get; set; }

public string BillingAddressFax { get; set; }

public string BillingAddressLine1 { get; set; }

public string BillingAddressLine2 { get; set; }

public string BillingAddressPhone { get; set; }

public string BillingAddressStateID { get; set; }

public string BillingAddressZipID { get; set; }

public string MailingAddressCityID { get; set; }

public string MailingAddressCountryId { get; set; }

public string MailingAddressCountyId { get; set; }

public string MailingAddressFax { get; set; }

public string MailingAddressLine1 { get; set; }

public string MailingAddressLine2 { get; set; }

public string MailingAddressPhone { get; set; }

public string MailingAddressStateID { get; set; }

public string MailingAddressZipID { get; set; }

public string NPI { get; set; }

public int NoofPhysicians { get; set; }

public string PhysicalAddressCityID { get; set; }

public string PhysicalAddressCountryId { get; set; }

public string PhysicalAddressCountyId { get; set; }

public string PhysicalAddressFax { get; set; }

public string PhysicalAddressLine1 { get; set; }

public string PhysicalAddressLine2 { get; set; }

public string PhysicalAddressPhone { get; set; }

public string PhysicalAddressStateID { get; set; }

public string PhysicalAddressZipID { get; set; }

public string PracticeID { get; set; }

public string PracticeLocationName { get; set; }

public int PracticeLocationSubtype { get; set; }

public int PracticeLocationType { get; set; }

public string PrimaryContactID { get; set; }

public string PrimaryContactType { get; set; }

public string SalesContactID { get; set; }

public int Speciality { get; set; }

public string TaxID { get; set; }

public string TerritoryID { get; set; }

}

 

public class outputClassCreate

{

public string PracticeLocationId { get; set; }

public string ReturnMessage { get; set; }

 

}

public class IpadOptionSetData

{

public string TextField { get; set; }

public int ValueField { get; set; }

}

public class PrimarySalesContactData

{

public string SalesContactGUID {get;set;}

public string SalesContactName  {get;set;}

}

 

public class PrimaryContactData

{

public string ContactGUID { get; set; }

public string ContactName { get; set; }

}

 

public class IpadPrimaryContactData

{

public string PracticeLocationGuid { get; set; }

}

public class IpadPrimaryContactData1

{

public string ContactGUID { get; set; }

public string ContactName { get; set; }

}

public class ZipCodeData

{

public string ZipCodeGUID{get;set;}

public string ZipCodeName { get; set; }

 

}

public class StateData

{

public string StateGUID{get;set;}

public string StateName { get; set; }

}

 

public class IpadUpdatedata

{

public string PracticeLocationId { get; set; }

public string PhysicalAddressId { get; set; }

public string BillingAddressId { get; set; }

public string MailingAddressId { get; set; }

}

public class CheckDuplicateNPI

{

public string NPINo { get; set; }

}

 

 

}

 

 

Unit Testing in web api Controller :

TestPracticeLocationsController.cs :

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Web.Http;

using System.Web.Http.Results;

using CRMiPadApp.Controllers;

using CRMiPadApp.Models;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Newtonsoft.Json;

 

namespace CRM_IPad_App.Test

{

[TestClass]

public class TestPracticeLocationsController

{

[TestMethod]

public void GetSearchPracticeLocation()

{

var testSearchPracticeLocation = GetTestSearchPracticeLocation();

var controller = new PracticeLocationController();

var Result = controller.SearchPracticeLocation(testSearchPracticeLocation);

Assert.IsNotNull(Result);

}

 

[TestMethod]

public void GetAllPracticeLocationNetworkLocations()

{

var testPracticeLocationNetworkLocations = GetPracticeLocationNetworkLocations();

var controller = new PracticeLocationController();

var Result = controller.PracticeLocationNetworkLocations(testPracticeLocationNetworkLocations);

Assert.IsNotNull(Result);

}

[TestMethod]

public void GetAllPracticeLocationContacts()

{

var testPracticeLocationContacts = GetPracticeLocationContacts();

var controller = new PracticeLocationController();

var Result = controller.PracticeLocationContacts(testPracticeLocationContacts);

Assert.IsNotNull(Result);

}

[TestMethod]

public void GetPracticeLocationSalesCallss()

{

var testPracticeLocationSalesCalls = GetPracticeLocationSalesCalls();

var controller = new PracticeLocationController();

var Result = controller.PracticeLocationSalesCalls(testPracticeLocationSalesCalls);

Assert.IsNotNull(Result);

}

[TestMethod]

public void GetPracticeLocationAddresss()

{

var testPracticeLocationAddress = GetPracticeLocationAddress();

var controller = new PracticeLocationController();

var Result = controller.PracticeLocationAddress(testPracticeLocationAddress);

Assert.IsNotNull(Result);

}

 

private IpadCollectionofPracticeLocationData GetTestSearchPracticeLocation()

{

var testSearchPracticeLocation = new IpadCollectionofPracticeLocationData();

testSearchPracticeLocation.SearchKey =”abc”;

return testSearchPracticeLocation;

}

private IpadCollectionofPrctLocNetworkLocations GetPracticeLocationNetworkLocations()

{

var testPracticeLocationNetworkLocations = new IpadCollectionofPrctLocNetworkLocations();

testPracticeLocationNetworkLocations.PracticeLocationId = “05328e64-d210-e511-bc74-005056c00008”;

return testPracticeLocationNetworkLocations;

}

private IpadCollectionofPrctLocContacts GetPracticeLocationContacts()

{

var testPracticeLocationContacts = new IpadCollectionofPrctLocContacts();

testPracticeLocationContacts.PracticeLocationId = “05328e64-d210-e511-bc74-005056c00008”;

return testPracticeLocationContacts;

}

private IpadCollectionofPrctLocSalesCalls GetPracticeLocationSalesCalls()

{

var testPracticeLocationSalesCalls = new IpadCollectionofPrctLocSalesCalls();

testPracticeLocationSalesCalls.PracticeLocationId = “05328e64-d210-e511-bc74-005056c00008”;

return testPracticeLocationSalesCalls;

}

private IpadCollectionofPrctLocAddress GetPracticeLocationAddress()

{

var testPracticeLocationAddress = new IpadCollectionofPrctLocAddress();

testPracticeLocationAddress.PracticeLocationId = “05328e64-d210-e511-bc74-005056c00008″;

return testPracticeLocationAddress;

}

}

}

 

 

Added APconfig file in test application:

<?xml version=”1.0″ encoding=”utf-8″ ?>

<configuration>

<!–<configSections>

–>

<!– For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 –>

<!–

<section name=”entityFramework” type=”System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />

</configSections>–>

<configSections>

<section name=”entityFramework” type=”System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />

<section name=”loggingConfiguration” type=”Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ requirePermission=”true” />

<!–<sectionGroup name=”applicationSettings” type=”System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ >

<section name=”FMS.BOTS.AdminService.Properties.Settings” type=”System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ requirePermission=”false” />

</sectionGroup>–>

</configSections>

 

<connectionStrings>

<add name=”DefaultConnection” providerName=”System.Data.SqlClient” connectionString=”Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-CRMiPadApp-20150605092225;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-CRMiPadApp-20150605092225.mdf” />

</connectionStrings>

<loggingConfiguration name=”” tracingEnabled=”true” defaultCategory=”General Activity”>

<listeners>

<add name=”General Activity Listener” type=”Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

listenerDataType=”Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

fileName=”C:\Logs\WEBAPI\QA\WEBAPI.Exceptions.log” formatter=”General Activity Formatter”

rollFileExistsBehavior=”Increment” rollInterval=”None” rollSizeKB=”1024″¬† header=”” footer=””

maxArchivedFiles=”10″ asynchronous=”true” ></add>

<add name=”Exception Listener” type=”Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

listenerDataType=”Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

fileName=”C:\Logs\BOTS\QA\BOTSAdminService.Exceptions.log” formatter=”Exception Formatter”

rollFileExistsBehavior=”Increment” rollInterval=”None” rollSizeKB=”1024″¬† header=”” footer=””

maxArchivedFiles=”10″ asynchronous=”true”/>

</listeners>

<formatters>

<add type=”Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

template=”{timestamp}: {appDomain} – {category} – {message}”

name=”General Activity Formatter” />

<add type=”Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″

template=”{timestamp}: {appDomain} – {category} – {message}{newline}Additional Information available: {dictionary({newline}{key} – {value})}”

name=”Exception Formatter” />

</formatters>

<categorySources>

<add switchValue=”All” name=”General Activity”>

<listeners>

<add name=”General Activity Listener” />

</listeners>

</add>

<add switchValue=”All” name=”FMS Exception”>

<listeners>

<add name=”Exception Listener” />

</listeners>

</add>

<add switchValue=”All” name=”FMS DAL Exception”>

<listeners>

<add name=”Exception Listener” />

</listeners>

</add>

</categorySources>

<specialSources>

<allEvents switchValue=”Off” name=”All Events”>

<listeners>

<add name=”General Activity Listener” />

</listeners>

</allEvents>

<notProcessed switchValue=”Off” name=”Unprocessed Category”>

<listeners>

<add name=”General Activity Listener” />

</listeners>

</notProcessed>

<errors switchValue=”Off” autoFlush=”true” name=”Logging Errors &amp; Warnings”>

<listeners>

<add name=”General Activity Listener” />

</listeners>

</errors>

</specialSources>

</loggingConfiguration>

<appSettings>

<add key=”webpages:Version” value=”2.0.0.0″ />

<add key=”webpages:Enabled” value=”false” />

<add key=”PreserveLoginUrl” value=”true” />

<add key=”ClientValidationEnabled” value=”true” />

<add key=”UnobtrusiveJavaScriptEnabled” value=”true” />

</appSettings>

<system.web>

<compilation debug=”true” targetFramework=”4.5″ />

<httpRuntime targetFramework=”4.5″ />

<authentication mode=”None” />

<pages>

<namespaces>

<add namespace=”System.Web.Helpers” />

<add namespace=”System.Web.Mvc” />

<add namespace=”System.Web.Mvc.Ajax” />

<add namespace=”System.Web.Mvc.Html” />

<add namespace=”System.Web.Optimization” />

<add namespace=”System.Web.Routing” />

<add namespace=”System.Web.WebPages” />

</namespaces>

</pages>

<profile defaultProvider=”DefaultProfileProvider”>

<providers>

<add name=”DefaultProfileProvider” type=”System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ connectionStringName=”DefaultConnection” applicationName=”/” />

</providers>

</profile>

<membership defaultProvider=”DefaultMembershipProvider”>

<providers>

<add name=”DefaultMembershipProvider” type=”System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ connectionStringName=”DefaultConnection” enablePasswordRetrieval=”false” enablePasswordReset=”true” requiresQuestionAndAnswer=”false” requiresUniqueEmail=”false” maxInvalidPasswordAttempts=”5″ minRequiredPasswordLength=”6″ minRequiredNonalphanumericCharacters=”0″ passwordAttemptWindow=”10″ applicationName=”/” />

</providers>

</membership>

<roleManager defaultProvider=”DefaultRoleProvider”>

<providers>

<add name=”DefaultRoleProvider” type=”System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ connectionStringName=”DefaultConnection” applicationName=”/” />

</providers>

</roleManager>

<sessionState mode=”InProc” customProvider=”DefaultSessionProvider”>

<providers>

<add name=”DefaultSessionProvider” type=”System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ connectionStringName=”DefaultConnection” />

</providers>

</sessionState>

</system.web>

<system.webServer>

<validation validateIntegratedModeConfiguration=”true” />

<handlers>

<remove name=”ExtensionlessUrlHandler-Integrated-4.0″ />

<remove name=”OPTIONSVerbHandler” />

<remove name=”TRACEVerbHandler” />

<add name=”ExtensionlessUrlHandler-Integrated-4.0″ path=”*.” verb=”*” type=”System.Web.Handlers.TransferRequestHandler” preCondition=”integratedMode,runtimeVersionv4.0″ />

</handlers>

</system.webServer>

<runtime>

<assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″>

<dependentAssembly>

<assemblyIdentity name=”System.Web.Helpers” publicKeyToken=”31bf3856ad364e35″ />

<bindingRedirect oldVersion=”1.0.0.0-2.0.0.0″ newVersion=”2.0.0.0″ />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name=”System.Web.Mvc” publicKeyToken=”31bf3856ad364e35″ />

<bindingRedirect oldVersion=”1.0.0.0-4.0.0.0″ newVersion=”4.0.0.0″ />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name=”System.Web.WebPages” publicKeyToken=”31bf3856ad364e35″ />

<bindingRedirect oldVersion=”1.0.0.0-2.0.0.0″ newVersion=”2.0.0.0″ />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name=”System.Web.Http” publicKeyToken=”31bf3856ad364e35″ culture=”neutral” />

<bindingRedirect oldVersion=”0.0.0.0-5.2.3.0″ newVersion=”5.2.3.0″ />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name=”System.Net.Http.Formatting” publicKeyToken=”31bf3856ad364e35″ culture=”neutral” />

<bindingRedirect oldVersion=”0.0.0.0-5.2.3.0″ newVersion=”5.2.3.0″ />

</dependentAssembly>

<dependentAssembly>

<assemblyIdentity name=”Newtonsoft.Json” publicKeyToken=”30ad4fe6b2a6aeed” culture=”neutral” />

<bindingRedirect oldVersion=”0.0.0.0-6.0.0.0″ newVersion=”6.0.0.0″ />

</dependentAssembly>

</assemblyBinding>

</runtime>

<entityFramework>

<defaultConnectionFactory type=”System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework”>

<parameters>

<parameter value=”v11.0″ />

</parameters>

</defaultConnectionFactory>

</entityFramework>

<system.serviceModel>

<bindings>

<basicHttpBinding>

<binding name=”BasicHttpBinding_ISearchPracticeLocation” />

</basicHttpBinding>

</bindings>

<client>

<endpoint address=”http://gsrcrm2:8055/SearchPracticeLocation.svc&#8221; binding=”basicHttpBinding” bindingConfiguration=”BasicHttpBinding_ISearchPracticeLocation” contract=”CRMIPADService.ISearchPracticeLocation” name=”BasicHttpBinding_ISearchPracticeLocation” />

</client>

</system.serviceModel>

</configuration>

WEB API CREATION

Controller creation :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.Cors;
using IPADDEMO.Models;
using Newtonsoft.Json;

namespace IPADDEMO.Controllers
{
public class ValuesController : ApiController
{
[ActionName(“RetreivePracticeType”)]
[EnableCors(origins: “*”, headers: “*”, methods: “*”)]
[AcceptVerbs(“GET”, “POST”)]
public IHttpActionResult RetreivePracticeType()
{
List<ServiceReference1.PracticeTypeData> listPracticetype = new List<ServiceReference1.PracticeTypeData>();
try
{
ServiceReference1.PracticeClient objRetreiveClient = new ServiceReference1.PracticeClient();
listPracticetype = objRetreiveClient.RetreivePracticeTypes();
}
catch (Exception Exec)
{
throw Exec;
}
return Ok(listPracticetype);
}

[ActionName(“CreatePractice”)]
[EnableCors(origins: “*”, headers: “*”, methods: “*”)]
[AcceptVerbs(“GET”, “POST”)]
public IHttpActionResult CreatePractice(IPadracticeCreation inputJsonfromIos)
{
//inputJsonfromIos = “{\”PracticeName\”:\”vinoth123\”,\”PracticeType\”:\”100000000\”, \”Description\”:\”Tom123\”}”;
outputClass objnn = new outputClass();
string Message;
string OutPracticeId;
try
{
if (inputJsonfromIos != null)
{
ServiceReference1.IPracticeCreation customerList = new ServiceReference1.IPracticeCreation();
customerList.Description = inputJsonfromIos.Description;
customerList.PracticeType = inputJsonfromIos.PracticeType;
customerList.PracticeName = inputJsonfromIos.PracticeName;
ServiceReference1.PracticeClient objclient = new ServiceReference1.PracticeClient();
var s = objclient.CreatePractice(customerList, out Message, out OutPracticeId);
objnn.Message = Message;
objnn.OutPracticeId = OutPracticeId;
}
else
{
return NotFound();
//string JsonError = “JSON input fields is null.”;
}
}
catch (Exception Exec)
{
Message = Exec.ToString();
string Errormessgae = “Unsccussfull”;
var ErrorResult = JsonConvert.SerializeObjectAsync(Errormessgae).Result;
return Ok(ErrorResult);
}
//var result = JsonConvert.SerializeObjectAsync(objnn).Result;
return Ok(objnn);
}

[ActionName(“Setdata”)]
[EnableCors(origins: “*”, headers: “*”, methods: “*”)]
[AcceptVerbs(“GET”, “POST”)]
public IHttpActionResult Setdata(string id, string Name)
{
id = “Testing”;
Name = “Coming SOON”;
List<string> ojlist = new List<string>();
ojlist.Add(id);
ojlist.Add(Name);
return Ok(ojlist);
}
}
}

Route Configuration :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace IPADDEMO
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);

routes.MapRoute(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Values”, action = “Index”, id = UrlParameter.Optional }
);
}
}
}

webapi config changes :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Routing;

namespace IPADDEMO
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: “DefaultApi”,
routeTemplate: “api/{controller}/{action}/{id}”,
defaults: new { id = RouteParameter.Optional }
);

//config.Routes.MapHttpRoute(“DefaultApiWithId”, “Api/{controller}/{id}”, new { id = RouteParameter.Optional }, new { id = @”\d+” });
//config.Routes.MapHttpRoute(“DefaultApiWithAction”, “Api/{controller}/{action}”);
//config.Routes.MapHttpRoute(“DefaultApiGet”, “Api/{controller}”, new { action = “Get” }, new { httpMethod = new HttpMethodConstraint(System.Net.Http.HttpMethod.Get) });
//config.Routes.MapHttpRoute(“DefaultApiPost”, “Api/{controller}”, new { action = “Post” }, new { httpMethod = new HttpMethodConstraint(System.Net.Http.HttpMethod.Post) });
}
}
}

 

class creation :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IPADDEMO.Models
{

public class IPracticeCreation
{
private string _practicenamename;
private int _practicetype;
private string _description;
private decimal _annualrevenue;

public string PracticeName
{
get { return _practicenamename; }
set { _practicenamename = value; }
}

public int PracticeType
{
get { return _practicetype; }
set { _practicetype = value; }
}

public string Description
{
get { return _description; }
set { _description = value; }
}
}
public class IPadracticeCreation
{
public string PracticeName { get; set; }
public int PracticeType { get; set; }
public string Description { get; set; }
}

public class PracticeTypeData
{
public string text { get; set; }
public int value { get; set; }
}

public class outputClass
{
public string Message { get; set; }
public string OutPracticeId { get; set; }

}
}

 

Web config changes implementing wcf services :

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name=”BasicHttpBinding_IPractice” />
</basicHttpBinding>
</bindings>
<client>
<endpoint address=”http://gsrcrm2:8055/Practice.svc&#8221; binding=”basicHttpBinding” bindingConfiguration=”BasicHttpBinding_IPractice” contract=”ServiceReference1.IPractice” name=”BasicHttpBinding_IPractice” />
</client>
</system.serviceModel>

WCF Rest Config changes

Step 1: Add svc file and write codes. Once adding svc file it generates codes in web.config under service model.

Step 2: Alter code in web.config under service model tag for REST Service

<!–Calling Rest service need to create endpoint and endpointbehaviours under system.servicemodel–>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled=”true” multipleSiteBindingsEnabled=”true”/>

<services>
<service behaviorConfiguration=”TvData.SPMS.RestServiceImplBehavior” name=”TvData.SPMS.RestServiceImpl”>
<!–If we add any service file from default endpoint has been created with binding as wsHttpBinding.
But using rest service we need to change wsHttpBinding to webHttpBinding and also add behaviourConfiguration and then create endpointBehaviours–>
<endpoint address=”” binding=”webHttpBinding” contract=”TvData.SPMS.IRestServiceImpl” behaviorConfiguration=”Web”>
</endpoint>
<endpoint address=”mex” binding=”mexHttpBinding” contract=”IMetadataExchange” />
<!–<host>
<baseAddresses>
<add baseAddress=”http://localhost:54055/spms/RestServiceImpl.svc&#8221; />
<add baseAddress=”” />
</baseAddresses>
</host>–>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name=”TvData.SPMS.RestServiceImplBehavior”>
<serviceMetadata httpGetEnabled=”true” />
<serviceDebug includeExceptionDetailInFaults=”false” />
</behavior>
</serviceBehaviors>
<!–Manully create this endpointBehaviour for Rest Service–>
<endpointBehaviors>
<behavior name=”Web”>
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>

SQL – Concatenate Column Values from Multiple Rows into a Single Column

CREATE TABLE #PRODUCTS
(
    CategoryId        INT,
    ProductName        VARCHAR(50)
)
GO
INSERT INTO #PRODUCTS VALUES(1, 'ONE - ONE')
INSERT INTO #PRODUCTS VALUES(1, 'ONE - TWO')
INSERT INTO #PRODUCTS VALUES(2, 'TWO - ONE')
INSERT INTO #PRODUCTS VALUES(2, 'TWO - TWO')
GO
WITH Ranked ( CategoryId, rnk, ProductName )
AS
(
    SELECT
        CategoryId,
        ROW_NUMBER() OVER( PARTITION BY CategoryId ORDER BY CategoryId ),
        CAST( ProductName AS VARCHAR(8000) )
    FROM #PRODUCTS
),
AnchorRanked ( CategoryId, rnk, ProductName )
AS
(
    SELECT
        CategoryId,
        rnk,
        ProductName
    FROM Ranked
    WHERE rnk = 1
),
RecurRanked ( CategoryId, rnk, ProductName )
AS
(
    SELECT
        CategoryId,
        rnk,
        ProductName
    FROM AnchorRanked
    UNION ALL
    SELECT
        Ranked.CategoryId,
        Ranked.rnk,
        RecurRanked.ProductName + ', ' + Ranked.ProductName
    FROM Ranked
    JOIN RecurRanked ON Ranked.CategoryId = RecurRanked.CategoryId AND Ranked.rnk = RecurRanked.rnk + 1
)
SELECT CategoryId, MAX( ProductName )
FROM RecurRanked
GROUP BY CategoryId;

– See more at: http://dotnet-assembly.blogspot.in/2012/08/sql-concatenate-column-values-from.html?utm_source=blog&utm_medium=gadget&utm_campaign=bp_slideout_plugin#sthash.TJJNEVfT.dpuf