/// <summary> /// Get 3 closet branches details for a single order /// </summary> /// <returns>List of OrderDetailWeb instances to Presentation layer</returns> public List<BranchViewModel> GetThreeClosetBranches() { List<BranchViewModel> webDetails = new List<BranchViewModel>(); try { BranchModel data = new BranchModel(); Dictionary<string, Object> dictionaryAddresses = new Dictionary<string, Object>(); dictionaryAddresses["lat"] = Latitude; dictionaryAddresses["long"] = Longitude; List<ClosestBranches> dataDetails = data.GetClosetBranches(dictionaryAddresses); // We return BranchViewModel instances as the Web layer should have // no knowledge of EF objects foreach (ClosestBranches d in dataDetails) { BranchViewModel brn = new BranchViewModel(); brn.BranchID = d.BranchID; brn.City = d.City; brn.Street = d.Street; brn.Region = d.Region; brn.Latitude = Convert.ToDouble(d.Latitude); brn.Longitude = Convert.ToDouble(d.Longitude); brn.Distance = Convert.ToDouble(d.DistanceFromAddress); webDetails.Add(brn); } } catch (Exception e) { ErrorRoutine(e, "BranchViewModel", "GetThreeClosestBranches"); } return webDetails; }
public JsonResult getJsonCloseBranches(string lat, string lng) { JsonResult jr; try { BranchViewModel branch = new BranchViewModel(); branch.Latitude = Convert.ToDouble(lat); branch.Longitude = Convert.ToDouble(lng); List<BranchViewModel> closeBranches = branch.GetThreeClosetBranches(); jr = this.Json(closeBranches, JsonRequestBehavior.AllowGet); } catch (Exception ex) { ViewBag.Message = ex.Message; jr = Json(ViewBag.Message); } return jr; }