Esempio n. 1
0
 public IEnumerable <RegistrationSearchResult> SearchRegistrations(RegistrationQuery query)
 {
     using (var d = Connection.Make())
     {
         var qry   = d.QueryMultiple($"select name, id from users; {query.AsQueryString()}");
         var users = new User.Cache(qry.Read().ToDictionary(u => (Guid)u.id, u => (string)u.name));
         foreach (var e in qry.Read())
         {
             var registration = ((string)e.entity).Deserialized <Registration>();
             var responsible  = users[registration.ResponsibleId];
             var assignees    = registration.AssigneeIds.Select(a => users[a]).ToArray();
             yield return(new RegistrationSearchResult(registration, responsible, assignees));
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Parses queryObject into postgresql condition-expression
        /// </summary>
        public static string AsQueryString(this RegistrationQuery q)
        {
            var ands = new List <string>();



            if (q.ForUser != Guid.Empty)
            {
                ands.Add(string.Format("(entity @> '{{\"ResponsibleId\" :\"{0}\"}}' OR entity ->'AssigneeIds' ? '{0}')", q.ForUser));
            }


            if (ands.Count == 0)
            {
                return($"select entity from registrations");
            }
            return($"select entity from registrations where {string.Join(" and ",ands)}");
        }