Thursday, 12 May 2016

Execute SP in MVC with repository pattern

No comments
 var result = contactsRepository.ExecWithStoreProcedure("Search @CompanyName,@CountryName,@StateName,@CityName,@AddressType,@zip,@OrderId",
                new SqlParameter("CompanyName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(companyName) ? string.Empty : companyName
                },
                new SqlParameter("CountryName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(countryName) ? string.Empty : countryName
                },
                new SqlParameter("StateName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(stateName) ? string.Empty : stateName
                },
                new SqlParameter("CityName", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(cityName) ? string.Empty : cityName
                },
                new SqlParameter("AddressType", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(hdfAddressType) ? string.Empty : hdfAddressType
                },
                new SqlParameter("zip", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(zip) ? string.Empty : zip
                },
                new SqlParameter("OrderId", System.Data.SqlDbType.VarChar)
                {
                    Value = string.IsNullOrEmpty(orderId) ? string.Empty : orderId
                }
                ).ToList();