private QueryNode AddPropertyNode(SingleQuery query, JProperty property) { var queryNode = GetQueryNode(property); query.AddNode(queryNode); return(queryNode); }
protected virtual async Task <bool> SingleDeleteCommand(SingleQuery <TEntity> entityQuery, CancellationToken cancellationToken = default(CancellationToken)) { var command = new EntityDeleteQuery <TEntity, TReadModel>(entityQuery, User); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(result); }
private static SingleQuery GetQuery(JToken jQuery) { var criteriaJson = jQuery.ToString(); SingleQuery singleQ = criteriaJson.ToSingleQuery(); return(singleQ); }
public FilterDefinition <T> RenderQueryFilter(SingleQuery query) { query = query.MakeCopy(); // Convert Id to masterId if needed query.ConvertIdToMasterId(); var filters = new List <FilterDefinition <T> >(); for (var queryNodeItem = query.NodesList.First; queryNodeItem != null; queryNodeItem = queryNodeItem.Next) { var queryNode = queryNodeItem.Value; if (queryNode.Type != QueryNodeType.Collection) { continue; } var collectionFilter = RenderCollection(queryNodeItem); filters.Add(collectionFilter); } var resultingFilter = filters.Any() ? filters.Aggregate((a, b) => a & b) : this.filterBuilder.Empty; return(resultingFilter); }
public void GetByType <T>(string eventType, MultiQuery <T> multiQuery, SingleQuery <T> singleQuery) where T : EventsResultData { using (var ctx = MockContext.Start(GetType().FullName, $"GetByType.{eventType}")) { var timespan = "P1D"; var top = 10; var client = GetClient(ctx); var events = multiQuery(client, timespan, top); Assert.NotNull(events); Assert.NotNull(events.Value); Assert.True(events.Value.Count >= 0); Assert.True(events.Value.Count <= top); foreach (var e in events.Value) { AssertEvent(e, eventType); } Assert.True(!string.IsNullOrEmpty(events.Value[0].Id)); var evnt = singleQuery(client, events.Value[0].Id, timespan); Assert.NotNull(evnt); Assert.NotNull(evnt.Value); Assert.True(evnt.Value.Count == 1); Assert.Equal(JsonConvert.SerializeObject(evnt.Value[0]), JsonConvert.SerializeObject(events.Value[0])); } }
/// <summary> Adds method "Delete" to last node in SingleQuery </summary> /// <param name="singleQuery"></param> /// <param name="actions"></param> /// <returns></returns> public static SingleQuery MethodDelete(this SingleQuery singleQuery, params Action <QueryNode>[] actions) { var newNode = singleQuery.NodesList.Last.MethodDelete(actions); return(singleQuery); }
/// <summary> Adds new criteria group to last node in SigleQuery </summary> /// <param name="singleQuery"></param> /// <param name="appender"></param> /// <param name="actions"></param> /// <returns> Newly created Criteria Group QueryNode </returns> public static QueryNode AddCriteriaGroup(this SingleQuery singleQuery, CriteriaAppendType appender, params Action <QueryNode>[] actions) { var newNode = singleQuery.NodesList.Last.Value.AddCriteriaGroup(appender, actions); return(newNode); }
public static SingleQuery SetPivot(this SingleQuery singleQuery, PivotType type, string mainValue, params string[] secondaryValues) { singleQuery.NodesList.SetPivot(type, mainValue, secondaryValues); return(singleQuery); }
/// <summary> Adds specified method to last node in SingleQuery </summary> /// <param name="singleQuery"></param> /// <param name="type">Method type to add</param> /// <param name="actions"></param> /// <returns></returns> public static SingleQuery AddMethod(this SingleQuery singleQuery, QueryMethodType type, params Action <QueryNode>[] actions) { var newNode = singleQuery.NodesList.Last.AddMethod(type, actions); return(singleQuery); }
private async Task <PaymentReadModel> PaymentTransaction(Guid attendeeId, Guid oldCourse, Guid newCourse, CancellationToken cancellationToken) { var search = Query <Data.Entities.PaymentTransaction> .Create(x => x.UserProfileId == attendeeId); search = search.And(Query <Data.Entities.PaymentTransaction> .Create(x => x.CourseId == oldCourse)); var query = new SingleQuery <Data.Entities.PaymentTransaction>(search); var command = new EntitySingleQuery <Data.Entities.PaymentTransaction, PaymentReadModel>(query); var result = await _mediator.Send(command, cancellationToken).ConfigureAwait(false); var map = _mapper.Map <PaymentUpdateModel>(result.Data); map.CourseId = newCourse; var updatecommand = new EntityUpdateCommand <Guid, PaymentTransaction, PaymentUpdateModel, PaymentReadModel>(result.Data.Id, map, null); var output = await _mediator.Send(updatecommand, cancellationToken).ConfigureAwait(false); var historymap = _mapper.Map <PaymentHistoryCreateModel>(result.Data); var createcommand = new EntityCreateCommand <Data.Entities.PaymentTransactionHistory, PaymentHistoryCreateModel, PaymentHistoryReadModel>(historymap, null); await _mediator.Send(createcommand, cancellationToken).ConfigureAwait(false); return(output); }
/// <summary> Adds property as last node </summary> /// <param name="singleQuery"></param> /// <param name="name"></param> /// <param name="actions"></param> /// <returns></returns> public static SingleQuery AddProperty(this SingleQuery singleQuery, string name, params Action <QueryNode>[] actions) { var newNode = singleQuery.NodesList.AddProperty(name, actions); return(singleQuery); }
public List <SingleQuery> GeneratePostQuery(SingleQuery path, JToken value, ModelElementObjectBase classDescription, IList <ModelElementObjectBase> allClassDescriptions) { return(FillSetQuery(path, value, classDescription, allClassDescriptions, true)); }
protected void bDelete_Click(object sender, ImageClickEventArgs e) { lock (Database.lockObjectDB) { object obj = null; Database.ExecuteScalar(String.Format("select count(*) from LogAction where UserId='{0}'", gvUsers.DataKeys[Convert.ToInt32(gvUsers.SelectedIndex)].Values["UserId"].ToString()), ref obj, null); if ((int)obj > 0) { MembershipUser mu = Membership.GetUser(gvUsers.DataKeys[Convert.ToInt32(gvUsers.SelectedIndex)].Values["UserName"].ToString()); mu.IsApproved = false; Membership.UpdateUser(mu); } else { using (SqlCommand comm = new SqlCommand()) { comm.Parameters.Add("@uid", SqlDbType.UniqueIdentifier).Value = new Guid(gvUsers.DataKeys[Convert.ToInt32(gvUsers.SelectedIndex)].Values["UserId"].ToString()); comm.CommandText = "delete a from AccountablePersonAccount a left join AccountablePerson b on a.id_accountableperson=b.id where b.UserId=(select id from aspnet_Users where UserID=@uid)"; SingleQuery.ExecuteNonQuery(comm); comm.CommandText = "delete a from [AccountablePerson_StorageDocs] a left join AccountablePerson b on a.id_person=b.id where b.UserId=((select id from aspnet_Users where UserID=@uid))"; SingleQuery.ExecuteNonQuery(comm); comm.CommandText = "delete from AccountablePerson where UserId=(select id from aspnet_Users where UserID=@uid)"; SingleQuery.ExecuteNonQuery(comm); } Membership.DeleteUser(gvUsers.DataKeys[Convert.ToInt32(gvUsers.SelectedIndex)].Values["UserName"].ToString()); } LoadUsers(); SelectRow(); } }
public IQueryable <JToken> ExecuteQuery(SingleQuery singleQuery, JToken dataSource, ExpandoObject services) { var result = new[] { dataSource }.AsQueryable(); result = ExecuteQuery(singleQuery, result, services); return(result); }
public override void EnterQuery(QueryLanguageParser.QueryContext context) { var newQuery = SingleQuery.InitiateQuery(CurrentQuery); queryStack.Push(newQuery); base.EnterQuery(context); }
/// <summary> Just adds specified QueryNode as last node to SingleQuery </summary> /// <param name="singleQuery"></param> /// <param name="queryNode"></param> /// <param name="actions"></param> /// <returns></returns> public static SingleQuery AddNode(this SingleQuery singleQuery, QueryNode queryNode, params Action <QueryNode>[] actions) { actions?.ForEach(x => x.Invoke(queryNode)); singleQuery.NodesList.AddLast(queryNode); return(singleQuery); }
public static SingleQuery AddCriteria(this SingleQuery singleQuery, CriteriaAppendType appender, SingleQuery subjectQuery, CriteriaComparator comparator, object value, params Action <QueryNode>[] actions) { singleQuery.NodesList.Last.AddCriteria(appender, subjectQuery, comparator, value, actions); return(singleQuery); }
public static SingleQuery RootCollection(this SingleQuery singleQuery, QueryRootType type, params Action <QueryNode>[] actions) { var rootNode = CreateRoot(QueryNodeType.Collection, type, actions); var newNode = singleQuery.NodesList.AddFirst(rootNode); return(singleQuery); }
public IFindFluent <T, T> RenderQuery(SingleQuery query, IMongoCollection <T> collection) { var filter = RenderQueryFilter(query); var findFluent = collection.Find(filter); var result = RenderQueryMethods(query, findFluent); return(result); }
public string getSingleQuery(ref bool searchPressed) { SingleQuery sq = new SingleQuery(); sq.ShowDialog(); searchPressed = sq.SearchPressed; string query = sq.Query; return(query); }
public async Task <IActionResult> Delete(CancellationToken cancellationToken, Guid id) { var search = Query <User> .Create(x => x.Id.Equals(id)); search.IncludeProperties = @"UserProfiles,UserRoles,ExamResults,UserTrainings"; var query = new SingleQuery <User>(search); var readModel = await SingleDeleteCommand(query, cancellationToken).ConfigureAwait(false); return(Ok(readModel)); }
/// <summary> Pregenerates Id for model initiates, possible occured in query </summary> /// <param name="query"></param> public static void GenerateIds(this SingleQuery query) { for (var queryNodeItem = query.NodesList.First; queryNodeItem != null; queryNodeItem = queryNodeItem.Next) { var queryNode = queryNodeItem.Value; /* * var shouldGenerate = queryNode.RootType == QueryRootType.Model || * queryNode.MethodType == QueryMethodType.Add; * * // TODO: more checks */ // Deeply iterate over queries foreach (var argument in queryNode.Arguments) { argument.ArgumentValueQuery?.GenerateIds(); } // Generate new id and set if needed var newId = Guid.NewGuid(); if (queryNode.MethodType == QueryMethodType.Add) { // Skip ID generation if we have ID already assigned in ._Add(id = xxx) if (queryNode.Arguments.Any(x => x.ArgumentSubjectQuery.NodesList.First().Name == ObjectHelper.IdPropName)) { continue; } queryNodeItem.AddArgument( x => x.ArgumentSubjectQuery = SingleQuery.CreateQuery.AddProperty(ObjectHelper.IdPropName), x => x.ArgumentValueConstant = newId); } else if (queryNode.RootType == QueryRootType.Model) { var tempQuery = SingleQuery.InitiateQuery() .RootProperty(QuerySource.API) .AddMethod(QueryMethodType.Set) .AddArgument( x => x.ArgumentSubjectQuery = SingleQuery.CreateQuery.AddProperty(ObjectHelper.IdPropName), x => x.ArgumentValueConstant = newId ); var newNode = tempQuery .NodesList .Last .Value; query.NodesList.AddAfter(queryNodeItem, newNode); } } }
protected override async Task <TrainingVideoReadModel> ProcessAsync(TrainingVideoGetCommand <Guid> message, CancellationToken cancellationToken) { var search = Query <TrainingVideoPic> .Create(x => x.Stream_id == message.Id); var query = new SingleQuery <TrainingVideoPic>(search); var command = new EntitySingleQuery <TrainingVideoPic, TrainingVideoReadModel>(query); var result = await Mediator.Send(command, cancellationToken).ConfigureAwait(false); return(result.Data); }
/// <summary> Convert Id to masterId if applicable </summary> /// <param name="singleQuery"></param> public static void ConvertIdToMasterId(this SingleQuery singleQuery) { for (var queryNodeItem = singleQuery.NodesList.First; queryNodeItem != null; queryNodeItem = queryNodeItem.Next) { var queryNode = queryNodeItem.Value; if (queryNode.Type == QueryNodeType.Collection) { queryNode.ConvertIdToMasterId(); } } }
public dynamic RenderQuery(SingleQuery query, dynamic value = null) { query = query.MakeCopy(); query.PivotsToCriterias(true); this.currentObject = this.jObject; for (var queryNodeItem = query.NodesList.First; queryNodeItem != null; queryNodeItem = queryNodeItem.Next) { var queryNode = queryNodeItem.Value; switch (queryNode.Type) { case QueryNodeType.Property: { if (queryNodeItem == query.NodesList.Last && value != null) { RenderProperty(queryNode, value); } else { RenderProperty(queryNode); } break; } case QueryNodeType.Collection: { RenderCollection(queryNode); break; } case QueryNodeType.Method: RenderMethod(queryNode); break; case QueryNodeType.MethodArgument: break; case QueryNodeType.Criteria: break; case QueryNodeType.Projection: break; default: throw new ArgumentOutOfRangeException(); } } return(this.jObject); }
private async Task <EntitySingleResult <TrainingBuildCoursesAttendeeReadModel> > GetAttendee( MapToCourseCommand <TrainingBuildCoursesAttendeeUpdateModel> message, CancellationToken cancellationToken) { var search = Query <Data.Entities.TrainingBuildCourseAttendee> .Create(x => x.Id == message.Id); search.IncludeProperties = "Course"; var query = new SingleQuery <Data.Entities.TrainingBuildCourseAttendee>(search); var command = new EntitySingleQuery <Data.Entities.TrainingBuildCourseAttendee, TrainingBuildCoursesAttendeeReadModel>(query); return(await _mediator.Send(command, cancellationToken).ConfigureAwait(false)); }
public void RootVisitor(JProperty property) { this.singleQuery = SingleQuery.CreateQuery.RootCollection(QueryRootType.InputData) .SetPivot(PivotType.Transaction, property.Name); var rootObject = property.Value as JObject; if (rootObject == null) { throw new Exception($"{property.Name} is not JObject"); } ProcessJObject(rootObject); }
public SingleQuery GeneratePutQuery(SingleQuery path, JToken value, ModelElementObjectBase classDescription, IList <ModelElementObjectBase> allClassDescriptions) { var add = path.MakeCopy(); FillAddQuery(add, value, classDescription, allClassDescriptions); var query = this.queryLanguageBuilder.RenderQuery(add); this.logger.Debug($"Generated query: {query}"); return(add); }
public static QueryNode AddCriteria(this QueryNode node, SingleQuery subjectQuery, params Action <QueryNode>[] actions) { var newNode = new QueryNode { Type = QueryNodeType.Criteria, // CriteriaValueConstant = value, // Comparator = comparator, CriteriaSubjectQuery = subjectQuery, }; actions?.ForEach(x => x.Invoke(newNode)); node.Criterias.Add(newNode); return(node); }
public async Task <IActionResult> Insert(CancellationToken cancellationToken, CourseCreateModel model) { var search = Query <TrainingCourse> .Create(x => x.Title.ToUpper().Contains(model.Title.ToUpper())); var query = new SingleQuery <TrainingCourse>(search); var isExists = await FirstOrDefaultQuery(query, cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(isExists.Data.Title)) { throw new DomainException(422, $"Course: '{model.Title}' is already exists."); } var readModel = await CreateCommand(model, cancellationToken).ConfigureAwait(false); Cache.Remove(CacheKey.TrainingCourses.ToString()); return(ObjectResult(readModel, StatusCodes.Status200OK)); }