public IActionResult GetAllUsers([FromQuery] UsersQueryOptions options) { using (var db = ArangoDatabase.CreateWithSetting()) { var query = from u in db.Query <User>() select new { u.Key, u.Username, u.RealName, u.Email, u.Description, u.Occupation, birthday = AQL.DateFormat(u.Birthday, "%dd/%mm/%yyyy") }; if (options.Name != null) { query = query.Where(u => AQL.Contains(AQL.Lower(u.Username), AQL.Lower(options.Name))); } if (options.Email != null) { query = from u in query where AQL.Lower(u.Email) == AQL.Lower(options.Email) select u; } if (options.Limit.HasValue) { query = query.Take(options.Limit.Value); } if (options.Sorted.HasValue && options.Sorted.Value == true) { query = query.OrderBy(user => user.Username); } var defaultValue = query.FirstOrDefault(); var queryCount = query.Count(); if (query.Count() >= 250 || options.Page.HasValue) { var skipValue = (options.Page ?? 0) * 250; query = query.Skip(skipValue).Take(250).Select(u => u); } if (options.MaxElements.HasValue && options.MaxElements.Value > 0) { query = query.Take(options.MaxElements.Value); } return(Ok(query)); } }
public void Create(ConcreteSyntaxEntity syntaxEntity) { var syntax = _mapper.Map <ConcreteSyntax>(syntaxEntity); using (var db = GetDatabase(_config)) { if (!db.ListCollections().Any(c => c.Name == "ConcreteSyntax")) { db.CreateCollection("ConcreteSyntax"); } if (db.Query <ConcreteSyntax>().Where(p => AQL.Contains(p.FullName, syntax.FullName)).Count() == 0) { db.Insert <ConcreteSyntax>(syntax); } } }
private string GetLoginFromName(string name) { name = name.ToLower(); if (string.IsNullOrEmpty(name)) { throw new ArgumentException(); } string[] parts = name.Split(' '); if (parts.Length != 2) { throw new ArgumentException(); } string userName = parts[0][0].ToString() + "." + parts[1]; int repeats = databaseManager.Database.Query <Credential>() .Where(c => AQL.Contains(c.Key, userName)).Count(); return(userName + Convert.ToString(repeats)); }