예제 #1
0
        public object GetAll()
        {
            var queryValues = Request.RequestUri.ParseQueryString();

            int    page  = Convert.ToInt32(queryValues["page"]);
            int    start = Convert.ToInt32(queryValues["start"]);
            int    limit = Convert.ToInt32(queryValues["limit"]);
            string id    = queryValues["id"];
            int    orden = Convert.ToInt32(queryValues["orden"]);


            #region Configuramos el orden de la consulta si se obtuvo como parametro
            string strOrder = !string.IsNullOrWhiteSpace(queryValues["sort"]) ? queryValues["sort"] : "";
            strOrder = strOrder.Replace('[', ' ');
            strOrder = strOrder.Replace(']', ' ');

            Sort sort;

            if (!string.IsNullOrWhiteSpace(strOrder))
            {
                sort = JsonConvert.DeserializeObject <Sort>(strOrder);
            }
            else
            {
                sort = new Sort();
            }
            #endregion

            string query = !string.IsNullOrWhiteSpace(queryValues["query"]) ? queryValues["query"] : "";

            int totalRecords = 0;

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    object           json;
                    string           msgError = "";
                    IList <Currency> lista;

                    lista = repository.GetList(query, sort, page, start, limit, ref totalRecords, ref msgError);

                    json = new
                    {
                        total   = totalRecords,
                        data    = lista,
                        success = true
                    };

                    return(json);
                }
                else
                {
                    string   msgError = "";
                    Currency estatus  = repository.Get(id, ref msgError);

                    object json = new
                    {
                        data    = estatus,
                        success = true,
                        message = msgError
                    };

                    return(json);
                }
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);

                object error = new { message = ex.Message };

                object json = new
                {
                    message = ex.Message,
                    success = false
                };

                return(json);
            }
        }
 public Currencies Get(Int64 ixCurrency) => _currenciesRepository.Get(ixCurrency);
예제 #3
0
 public PagedItems <Currency> Get(int pageNumber, int pageSize, string sortTerm, bool sortDesc, string searchTerm)
 {
     return(_currenciesRepo.Get(pageNumber, pageSize, sortTerm, sortDesc, searchTerm));
 }
 public Currency Get([FromRoute] long id)
 {
     return(repository.Get(id));
 }