public IEnumerable <IModel> Get([FromUri] MunicipioFilter filter) { IEnumerable <IModel> municipios = null; if (filter.IdEstado == 0) { try { municipios = dao.GetAll(); } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } if (municipios.Count() <= 0) { throw new HttpResponseException(HttpStatusCode.NotFound); } } else { // Validar que esté solicitando un estado válido if (filter.IdEstado < 0 || filter.IdEstado > 32) { var response = new HttpResponseMessage() { StatusCode = (HttpStatusCode)422, //Entidad Inprocesable ReasonPhrase = "Estado Invalido" }; throw new HttpResponseException(response); } try { municipios = dao.GetByFilter(filter); } catch (Exception e) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } return(municipios); }
protected override SqlParameter[] BuildParameters(IFilter IFilter, string strCommand) { SqlParameter[] parametros = null; MunicipioFilter mpoFilter = (MunicipioFilter)IFilter; switch (strCommand) { case "sp_select_municipios_por_estado": SqlParameter IdEstadoParam = new SqlParameter("@id", SqlDbType.Int); IdEstadoParam.Direction = ParameterDirection.Input; IdEstadoParam.Value = mpoFilter.IdEstado; parametros = new SqlParameter[] { IdEstadoParam }; break; } return(parametros); }