Nopcommerce数据访问层

时间:2015-04-08 17:16:40

标签: c# asp.net-mvc entity-framework nopcommerce

在我的〜/ Presentation / Nop.Web / Controllers / ProductController.cs中,我创建了一个使用googleMapsApi进行过滤的方法,如下所示:

// GET: /Product/StoreLocatorResults
    public ActionResult StoreLocatorResults(string address)
    {
        // Make sure we have an address - if not, send user back to /Product/StoreLocator
        if (string.IsNullOrEmpty(address))
            return RedirectToAction("StoreLocator");

        // Get the lat/long info about the address
        var results = GoogleMapsAPIHelpersCS.GetGeocodingSearchResults(address);

        // Determine the lat & long parameters
        var lat = Convert.ToDecimal(results.Element("result").Element("geometry").Element("location").Element("lat").Value, NumberFormatInfo.InvariantInfo);
        var lng = Convert.ToDecimal(results.Element("result").Element("geometry").Element("location").Element("lng").Value, NumberFormatInfo.InvariantInfo);



       // var vendors = _vendorService.GetAllVendors();
        // Get those locations near the store
       TyrePromosContext context = new TyrePromosContext();
        var nearbyStores = from store in context.contextVendors
                           where Math.Abs(decimal.Parse(store.Latitude) - lat) < 0.25M &&
                                 Math.Abs(decimal.Parse(store.Longitude) - lng) < 0.25M
                           select new NearbyStoreLocation()
                           {
                               Id = store.Id,
                               VendorAddress = store.VendorAddress,
                               City = store.City,
                               PostalCode = store.PostalCode,
                               Latitude = store.Latitude,
                               Longitude = store.Longitude,
                               AddressLatitude = lat,
                               AddressLongitude = lng
                           };

        // Order the results from nearest to farthest
        var nearbySortedStores = nearbyStores.ToList().OrderBy(s => s.DistanceFromAddress).ToList();

        return View(nearbySortedStores);
    }

我创建了一个名为TyrePromosContext的上下文,它似乎连接得很好,因为我没有得到任何构建错误,并且Web项目运行正常,但是当一个地址字符串被解析为上面的StoreLocatorResults方法时,我收到此错误消息

错误消息: 类型&#39; System.Data.SqlClient.SqlException&#39;的例外情况发生在EntityFramework.dll中但未在用户代码中处理

其他信息:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确以及SQL

现在我的问题是如何使用服务层以这种方式获取所有供应商:

var vendors = _vendorService.GetAllVendors(model.SearchName, command.Page - 1, command.PageSize, true); 
像在里面一样 ~Presentation / Nop.Web / Administration / Controllers / VendorController.cs?

0 个答案:

没有答案
相关问题