Example #1
0
        public IActionResult ViewType(int poiTypeId)
        {
            var model = new ViewTypeView();

            var type = _mappingService.GetTypeById(poiTypeId);

            if (type == null || type.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            model.Type = type;
            var address = _departmentSettingsService.GetBigBoardCenterAddressDepartment(DepartmentId);
            var center  = _departmentSettingsService.GetBigBoardCenterGpsCoordinatesDepartment(DepartmentId);

            if (center != null)
            {
                var points = center.Split(char.Parse(","));

                if (points != null && points.Length == 2)
                {
                    model.Latitude  = points[0];
                    model.Longitude = points[1];
                }
            }
            else if (address != null)
            {
                string coordinates =
                    _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3} {4}", address.Address1,
                                                                            address.City, address.State, address.PostalCode, address.Country));

                if (!String.IsNullOrEmpty(coordinates))
                {
                    double newLat;
                    double newLon;
                    var    coordinatesArr = coordinates.Split(char.Parse(","));
                    if (double.TryParse(coordinatesArr[0], out newLat) && double.TryParse(coordinatesArr[1], out newLon))
                    {
                        model.Latitude  = newLat.ToString();
                        model.Longitude = newLon.ToString();
                    }
                }
            }

            return(View(model));
        }