public static void LoadOperations() { OperationMapper.Update(User, OperationsGroups, Importances, Frequencies, TransactionTypes, TransferTypes); Operations = OperationMapper.ConvertToBusinessLogicEntitiesCollection(OperationAdapter.GetAll($"user_id={User.Id}")).ToList(); if (Operations.Count > 0) { var filter = ""; foreach (var operation in Operations) { filter += $"operation_id={operation.Id} OR "; } filter = filter.Substring(0, filter.Length - 4); RelationMapper.Update(Operations, Tags); var relations = RelationMapper.ConvertToBusinessLogicEntitiesCollection(OperationTagRelationAdapter.GetAll(filter)); var relTags = relations.Item1; var relOperations = relations.Item2; foreach (var operation in Operations) { operation.SetDetailsList(OperationDetailsMapper.ConvertToBusinessLogicEntitiesCollection(OperationDetailsAdapter.GetAll($"operation_id={operation.Id}"))); operation.SetTags(relTags.Where(r => r.RelatedId == operation.Id)); } foreach (var tag in Tags) { tag.SetOperations(relOperations.Where(r => r.TagId == tag.Id)); } } }
public List <ApiOperation> GetOperations(ApiUser user, List <ApiTransactionType> transactionTypes, List <ApiTransferType> transferTypes, List <ApiFrequency> frequencies, List <ApiImportance> importances, List <ApiTag> tags) { var operations = OperationAdapter.GetAll($"user_id={user.Id}"); var filter = ""; foreach (var operation in operations) { filter += $"operation_id={operation.Id} OR "; } if (filter.Length > 4) { filter = filter.Substring(0, filter.Length - 4); } var relations = OperationTagRelationAdapter.GetAll(filter).ToList(); var details = OperationDetailsAdapter.GetAll(filter).ToList(); OperationMapper.Update(importances, frequencies, transactionTypes, transferTypes, tags, user, relations, details); return(OperationMapper.ConvertToApiEntitiesCollection(operations).ToList()); }