Ejemplo n.º 1
0
        //GET /api/pathologies?token=<string>&lang=<int>
        public PResponse getPathologies(string token, int lang)
        {
            PResponse result = new PResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            ICriteria         criteria = session.CreateCriteria <Pathology>();
                            IList <Pathology> pats     = criteria.List <Pathology>();
                            result.values = getPathologies(session, pats, lang);
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public PResponse Filtered(string token, int lang, string filter)
        {
            PResponse result = new PResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            string[] filters = filter.Split(' ');
                            var      query   = session.QueryOver <Translation>();
                            foreach (string filt in filters)
                            {
                                if (lang == 1)
                                {
                                    query = query.AndRestrictionOn(t => t.Original).IsInsensitiveLike(filt, MatchMode.Anywhere);
                                }
                                else
                                {
                                    query = query.AndRestrictionOn(t => t.Translationval).IsInsensitiveLike(filt, MatchMode.Anywhere);
                                }
                            }
                            var               resu  = query.List();
                            string[]          trans = query.Select(t => t.Original).List <string>().ToArray();
                            IList <Pathology> pats  = session.QueryOver <Pathology>().AndRestrictionOn(p => p.PScientificName).IsIn(trans).List();
                            result.values = getPathologies(session, pats, lang);
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }