public ActionResult Edit(string id) { var model = new StateViewModel(); model.Countries = HealthHelper.GetAllCountries(); if (id != "-1") { var svc = new GeoStateAppService(); var o = svc.GetGeoState(id); model.GeoCountryId = o.GeoCountryId; model.Name = o.Name; model.GeoStateId = o.GeoStateId; model.Latitude = o.Latitude; model.Longitude = o.Longitude; } else { model.Action = "-1"; model.Name = string.Empty; model.Latitude = 0; model.Longitude = 0; } return View(model); }
public JsonResult GetStatesByCountry(string id) { var svc = new GeoStateAppService(); List<GeoState> states = svc.GetGeoStateByCountryId(id); return Json(states, JsonRequestBehavior.AllowGet); }
public ActionResult Edit(StateViewModel model) { model.Countries = HealthHelper.GetAllCountries(); try { var svc = new GeoStateAppService(); var o = new GeoState { GeoStateId = model.GeoStateId, Name = model.Name, GeoCountryId = model.GeoCountryId, Latitude = model.Latitude, Longitude = model.Longitude }; if (model.Action == "-1") { var exist = svc.GetGeoState(model.GeoStateId) != null; if (!exist) { svc.AddGeoState(o); ViewBag.Feed = 0; } else { model.Action = "-1"; ViewBag.Feed = 3; return View(model); } } else { o.GeoStateId = model.GeoStateId; if (model.IsDeleteAction == 0) { svc.SaveGeoState(o); } else { svc.RemoveGeoState(model.GeoStateId); } ViewBag.Feed = 0; } } catch (Exception) { ViewBag.Feed = 1; } return View(model); }
public DataTablesResult<StateViewModel> GetAllStates(DataTablesParam dataTableParam) { var svc = new GeoStateAppService(); var lst = svc.GetAllGeoState(); var lstVm = new List<StateViewModel>(); foreach (var itm in lst) { var itmVm = new StateViewModel { GeoCountryName = itm.GeoCountry.Name, Name = itm.Name, GeoCountryId = itm.GeoCountry.GeoCountryId, GeoStateId = itm.GeoStateId }; 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", "State"); 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> Nuevo Estado/Provincia/Departamento</a></li>"); sb.AppendLine("<li><a href=\"" + editUrl + "?id=" + itmVm.GeoStateId + "\"><i class=\"fa fa-edit\"></i> 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); }