Esempio n. 1
0
        public List <Dictionary <string, object> > GetSubPageRecords(int subPageId, int recordId, String token)
        {
            SelectQueryResult result = Call <SelectQueryResult>(token,
                                                                platformClient => platformClient.GetSubpageRecords(subPageId, recordId, string.Empty, string.Empty, 0));

            return(MPFormatConversion.MPFormatToList(result));
        }
        private static Dictionary <string, object> MpFormatToDictionary(SelectQueryResult mpObject)
        {
            var ret = new Dictionary <string, object>();

            foreach (var dataitem in mpObject.Data)
            {
                foreach (var mpField in mpObject.Fields)
                {
                    ret.Add(mpField.Name, dataitem[mpField.Index]);
                }
            }
            return(ret);
        }
        private static List <Dictionary <string, object> > MpFormatToList(SelectQueryResult mpObject)
        {
            var list = new List <Dictionary <string, object> >();


            foreach (var dataitem in mpObject.Data)
            {
                var ret = new Dictionary <string, object>();
                foreach (var mpField in mpObject.Fields)
                {
                    ret.Add(mpField.Name, dataitem[mpField.Index]);
                }
                list.Add(ret);
            }
            return(list);
        }
        public ICommandResult Select([FromBody] SelectCommand cmd)
        {
            try
            {
                connectionString = GetConexao(Request.Host.Host);
                using (SqlConnection db = new SqlConnection(connectionString))
                {
                    db.Open();

                    var retorno = new SelectQueryResult();

                    if (cmd.Total)
                    {
                        string queryTotal = "";
                        int    z          = cmd.Query.ToUpper().IndexOf("ORDER") - cmd.Query.ToUpper().IndexOf("FROM");
                        if (cmd.Query.ToUpper().Contains("ORDER"))
                        {
                            queryTotal = "SELECT COUNT(*)" + cmd.Query.Substring(cmd.Query.ToUpper().IndexOf(" FROM "), z);
                        }
                        else
                        {
                            queryTotal = "SELECT COUNT(*)" + cmd.Query.Substring(cmd.Query.ToUpper().IndexOf(" FROM "));
                        }
                        retorno.Total = db.Query <int>(queryTotal).FirstOrDefault();
                    }

                    retorno.Itens = db.Query(cmd.Query).ToList();

                    db.Close();

                    return(new CommandResult(true, "Consulta realizada com sucesso.", new { retorno }));
                }
            }
            catch (System.Exception)
            {
                return(new CommandResult(false, "Dados inválidos", new Notification("DataBase", "Erro ao pesquisar na base")));
            }
        }