コード例 #1
0
        public ActionResult Edit(string id)
        {
            var model = new CityViewModel();
            model.Countries = HealthHelper.GetAllCountries();

            if (id != "-1")
            {
                var svc = new GeoCityAppService();
                var o = svc.GetGeoCity(id);
                model.GeoCityId = o.GeoCityId;
                model.GeoCountryId = o.GeoState.GeoCountryId;
                model.Name = o.Name;
                model.GeoStateId = o.GeoStateId;
                model.Latitude = o.Latitude;
                model.Longitude = o.Longitude;

            }
            else
            {


                model.Action = "-1";
                model.GeoCityId = string.Empty;
                model.Name = string.Empty;
                model.GeoStateId = "-1";
                model.Latitude = 0;
                model.Longitude = 0;
            }



            return View(model);
        }
コード例 #2
0
        public JsonResult GetCitiesByState(string id)
        {

            var svc = new GeoCityAppService();
            List<GeoCity> cities = svc.GetGeoCityByStateId(id);
            return Json(cities, JsonRequestBehavior.AllowGet);



        }
コード例 #3
0
        public JsonResult AutoCompleteCity(string term) {
            var svc = new GeoCityAppService();
            var lst = svc.GetGeoCityByTerm(term);
            var result = new List<SearchCityViewModel>();

            foreach (var p in lst){
                var s = new SearchCityViewModel();
                s.GeoCityId = p.GeoCityId;
                var name = string.Format("{0} ({1}-{2})", p.Name, p.GeoState.Name, p.GeoState.GeoCountry.Name);
                s.Name = name;

                result.Add(s);
            }

            var res = this.Json(result, JsonRequestBehavior.AllowGet);
            return res;
        }
コード例 #4
0
        public ActionResult Edit(CityViewModel model)
        {

            model.Countries = HealthHelper.GetAllCountries();
            try
            {
                var svc = new GeoCityAppService();

                var o = new GeoCity
                {
                    GeoCityId = model.GeoCityId,
                    Name = model.Name,
                    GeoStateId = model.GeoStateId,
                    Latitude = model.Latitude,
                    Longitude = model.Longitude

                };

                if (model.Action == "-1")
                {
                    var exist = svc.GetGeoCity(model.GeoCityId) != null;
                    if (!exist)
                    {

                        svc.AddGeoCity(o);

                    

                        ViewBag.Feed = 0;
                    }
                    else
                    {
                        model.Action = "-1";
                        ViewBag.Feed = 3;
                        return View(model);
                    }
                }
                else
                {
                    o.GeoCityId = model.GeoCityId;
                    if (model.IsDeleteAction == 0)
                    {

                        svc.SaveGeoCity(o);
                    }
                    else
                    {
                        svc.RemoveGeoCity(model.GeoCityId);
                    }
                    ViewBag.Feed = 0;
                }
            }
            catch (Exception)
            {
                ViewBag.Feed = 1;

            }

            return View(model);
        }
コード例 #5
0
        public DataTablesResult<CityViewModel> GetAllCities(DataTablesParam dataTableParam)
        {

            var svc = new GeoCityAppService();
            var lst = svc.GetAllGeoCity();
            var lstVm = new List<CityViewModel>();
            foreach (var itm in lst)
            {

                var itmVm = new CityViewModel
                {
                    GeoCountryName = itm.GeoState.GeoCountry.Name,
                    GeoStateName = itm.GeoState.Name,
                    Name = itm.Name,
                    GeoCountryId = itm.GeoState.GeoCountry.GeoCountryId,
                    GeoStateId = itm.GeoState.GeoStateId,
                    GeoCityId = itm.GeoCityId
                };

                if (itm.Latitude != null)
                {
                    itmVm.Latitude = itm.Latitude;
                    itmVm.LatitudeText = GeoAngle.FromDouble((double)itm.Latitude).ToString();
                }
                else
                {
                    itmVm.Latitude = 0;
                    itmVm.LatitudeText = "Sín Coordenadas";
                }



                if (itm.Longitude != null)
                {
                    itmVm.Longitude = 0;
                    itmVm.LongitudeText = GeoAngle.FromDouble((double)itm.Longitude).ToString();
                }
                else
                {
                    itmVm.Longitude = 0;
                    itmVm.LongitudeText = "Sín Coordenadas";
                }




                var sb = new StringBuilder();

                string editUrl = Url.Action("Edit", "City");
                sb.AppendLine("<div class=\"btn-group\">");
                sb.AppendLine(
                    "<button type=\"button\" class=\"btn btn-default dropdown-toggle\" data-toggle=\"dropdown\" aria-expanded=\"false\">");
                sb.AppendLine("Acciones <span class=\"caret\"></span>");
                sb.AppendLine("</button>");
                sb.AppendLine("<ul class=\"dropdown-menu\" role=\"menu\">");
                sb.AppendLine("<li><a href=\"" + editUrl + "?id=-1\"><i class=\"fa fa-plus\"></i>&nbsp;Nueva Ciudad</a></li>");
                sb.AppendLine("<li><a href=\"" + editUrl + "?id=" + itmVm.GeoCityId + "\"><i class=\"fa fa-edit\"></i>&nbsp;Editar " + itmVm.Name + "</a></li>");
                sb.AppendLine("</ul>");
                sb.AppendLine("</div>");




                var actionButton = sb.ToString();

                itmVm.ActionButton = actionButton;
                lstVm.Add(itmVm);

            }

            var lstVmQueryable = lstVm.AsQueryable();


            return DataTablesResult.Create(lstVmQueryable, dataTableParam);

        }