public IHttpActionResult Delete(QueryDTO query) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var mtTypeRef = uow.MultiTenantObjectRepository.FindTypeReference(query.Name); var queryBuilder = MTSearchHelper.CreateQueryProvider(mtTypeRef.ClrType); queryBuilder.Delete( uow, User.Identity.GetUserId(), query.Criteria ); uow.SaveChanges(); return(Ok()); } }
public IHttpActionResult Query(QueryDTO query) { using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var mtTypeRef = uow.MultiTenantObjectRepository.FindTypeReference(query.Name); var queryBuilder = MTSearchHelper.CreateQueryProvider(mtTypeRef.ClrType); var foundObjects = queryBuilder.Query( uow, User.Identity.GetUserId(), query.Criteria ) .ToArray(); return(Ok(foundObjects)); } }
public override async Task Run() { using (var uow = _container.GetInstance <IUnitOfWork>()) { var selectedObjectId = Guid.Parse(ActivityUI.AvailableObjects.Value); var mtType = uow.MultiTenantObjectRepository.FindTypeReference(selectedObjectId); if (mtType == null) { throw new ApplicationException("Invalid object selected."); } var conditions = JsonConvert.DeserializeObject <List <FilterConditionDTO> >( ActivityUI.QueryBuilder.Value ); //////////DIRTY DIRTY NASTY HACK//////////// //cause we can't select upstream value on // //these controls yet // foreach (var condition in conditions) { if (condition.Value == "FromPayload") { foreach (var crate in Payload) { // skip system crates if (crate.IsOfType <OperationalStateCM>() || crate.IsOfType <CrateDescriptionCM>() || crate.IsOfType <ValidationResultsCM>()) { continue; } //GetValue() method is a copy of UpstreamValueExtractorBase<T>.GetValue var foundValue = GetValue(crate, condition.Field); if (foundValue != null) { condition.Value = Convert.ToString(foundValue); } } } } ////////////END OF HACK///////////////////// var manifestType = mtType.ClrType; var queryBuilder = MTSearchHelper.CreateQueryProvider(manifestType); var converter = CrateManifestToRowConverter(manifestType); var foundObjects = queryBuilder .Query( uow, CurrentUserId, conditions ) .ToArray(); var searchResult = new StandardTableDataCM(); if (foundObjects.Length > 0) { searchResult.FirstRowHeaders = true; var headerRow = new TableRowDTO(); var properties = uow.MultiTenantObjectRepository.ListTypePropertyReferences(mtType.Id); foreach (var mtTypeProp in properties) { headerRow.Row.Add( new TableCellDTO() { Cell = new KeyValueDTO(mtTypeProp.Name, mtTypeProp.Name) }); } searchResult.Table.Add(headerRow); } foreach (var foundObject in foundObjects) { searchResult.Table.Add(converter(foundObject)); } Payload.Add( Crate.FromContent( RunTimeCrateLabel, searchResult ) ); } await Task.Yield(); }
public override async Task Run() { var queryPicker = GetControl <RadioButtonGroup>("QueryPicker"); List <FilterConditionDTO> conditions; Guid?selectedObjectId = null; if (queryPicker.Radios[0].Selected) { var upstreamCrateChooser = (UpstreamCrateChooser)(queryPicker).Radios[0].Controls[0]; var selectedCrate = upstreamCrateChooser.SelectedCrates.FirstOrDefault(); StandardQueryCM queryCM = null; if (selectedCrate != null) { queryCM = Payload.CratesOfType <StandardQueryCM>().FirstOrDefault(x => x.Label == selectedCrate.Label.selectedKey)?.Content; } if (queryCM?.Queries == null || queryCM.Queries.Count == 0) { RaiseError("No upstream crate found"); return; } var query = queryCM.Queries[0]; conditions = query.Criteria ?? new List <FilterConditionDTO>(); selectedObjectId = ExtractUpstreamTypeId(query); } else { var filterPane = (FilterPane)queryPicker.Radios[1].Controls[1]; var availableObjects = (DropDownList)queryPicker.Radios[1].Controls[0]; var criteria = filterPane.Value == null ? null : JsonConvert.DeserializeObject <FilterDataDTO>(filterPane.Value); if (availableObjects.Value == null) { RaiseError("This action is designed to query the Fr8 Warehouse for you, but you don't currently have any objects stored there."); return; } Guid objectId; if (Guid.TryParse(availableObjects.Value, out objectId)) { selectedObjectId = objectId; } conditions = criteria == null || criteria.ExecutionType == FilterExecutionType.WithoutFilter ? new List <FilterConditionDTO>() : criteria.Conditions; } // If no object is found in MT database, return empty result. if (!selectedObjectId.HasValue) { var searchResult = new StandardPayloadDataCM(); Payload.Add(Crate.FromContent("Found MT Objects", searchResult)); Success(); return; } //STARTING NASTY CODE //TODO discuss this with Alex (bahadir) var envIdCondition = conditions.FirstOrDefault(c => c.Field == "EnvelopeId"); if (envIdCondition != null && envIdCondition.Value == "FromPayload") { envIdCondition.Value = GetCurrentEnvelopeId(); } //END OF NASTY CODE using (var uow = _container.GetInstance <IUnitOfWork>()) { var objectId = selectedObjectId.GetValueOrDefault(); var mtType = uow.MultiTenantObjectRepository.FindTypeReference(objectId); if (mtType == null) { RaiseError("Invalid object selected"); return; } Type manifestType = mtType.ClrType; var queryBuilder = MTSearchHelper.CreateQueryProvider(manifestType); var converter = CrateManifestToRowConverter(manifestType); var foundObjects = queryBuilder.Query(uow, CurrentUserId, conditions.ToList()).ToArray(); var searchResult = new StandardPayloadDataCM(); foreach (var foundObject in foundObjects) { searchResult.PayloadObjects.Add(converter(foundObject)); } Payload.Add(Crate.FromContent("Found MT Objects", searchResult)); } Success(); }