Ejemplo n.º 1
0
        public ActionResult GetEntityCaptionAttribute(string metaviewName)
        {
            DynamicEntityRepository repo     = new DynamicEntityRepository();
            EntityMetadata          metadata = repo.GetEntityMetadataByEntityName(metaviewName);

            string caption = metadata != null?OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(metadata).PropertyName : String.Empty;

            return(Content(ServiceStack.Text.JsonSerializer.SerializeToString(caption)));
        }
Ejemplo n.º 2
0
        public static List <Tuple <Guid, string, List <Tuple <Guid, string> > > > GetDependingEntityAccess(string metaviewName, Guid[] ids, int deep = 1)
        {
            DynamicEntityRepository           repo     = new DynamicEntityRepository();
            EntityMetadata                    metadata = repo.GetEntityMetadataByEntityName(metaviewName);
            List <Guid>                       dependingEntityMetadataIds = MetadataRepositoty.GetDependingEntityIds(new TableDescription(metadata.SchemaName, metadata.TableName));
            Dictionary <Guid, EntityMetadata> dependingMetadata          = dependingEntityMetadataIds.Select(id => new KeyValuePair <Guid, EntityMetadata>(id, repo.GetEntityMetadataByEntityId(id)))
                                                                           .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            var dependingEntities = new List <Tuple <Guid, string, List <Tuple <Guid, string> > > >();

            foreach (var entityMetadata in dependingMetadata)
            {
                FilterCriteriaSet    filters = FilterCriteriaSet.Empty;
                AttributeDescription entityCaptionAttribute = OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(entityMetadata.Value);

                List <FilterCriteriaSet> filterSets = entityMetadata.Value.PlainAttributes.Where(a => a.IsReference && a.ReferencedSchemaName == metadata.SchemaName && a.ReferencedTableName == metadata.TableName)
                                                      .Select(a => FilterCriteriaSet.And.In(ids.ToList(), entityMetadata.Value.GetColumn(a))).ToList();

                filterSets.ForEach(f => filters = filters != FilterCriteriaSet.Empty ? filters.Merge(f) : f);

                var entities = repo.GetEntitiesByMetadata(entityMetadata.Value, filters).Entities;
                if (entities == null || entities.Count() == 0)
                {
                    continue;
                }

                var dependingEntity = new Tuple <Guid, string, List <Tuple <Guid, string> > >(
                    entityMetadata.Key,
                    entityMetadata.Value.TableName,
                    new List <Tuple <Guid, string> >(entities.Select(e =>
                                                                     new Tuple <Guid, string>((Guid)e.Id, e.GetProperty(entityCaptionAttribute.PropertyName).ToString())
                                                                     ).ToList()));
                dependingEntities.Add(dependingEntity);

                if (deep > 0)
                {
                    dependingEntities.AddRange(GetDependingEntityAccess(dependingEntity.Item2, dependingEntity.Item3.Select(t => t.Item1).ToArray(), deep - 1));
                }
            }
            return(dependingEntities);
        }
Ejemplo n.º 3
0
        public static List<Tuple<Guid, string, List<Tuple<Guid, string>>>> GetDependingEntityAccess(string metaviewName, Guid[] ids, int deep = 1)
        {
            DynamicEntityRepository repo = new DynamicEntityRepository();
            EntityMetadata metadata = repo.GetEntityMetadataByEntityName(metaviewName);
            List<Guid> dependingEntityMetadataIds = MetadataRepositoty.GetDependingEntityIds(new TableDescription(metadata.SchemaName, metadata.TableName));
            Dictionary<Guid, EntityMetadata> dependingMetadata = dependingEntityMetadataIds.Select(id => new KeyValuePair<Guid, EntityMetadata>(id, repo.GetEntityMetadataByEntityId(id)))
                .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            var dependingEntities = new List<Tuple<Guid, string, List<Tuple<Guid, string>>>>();

            foreach (var entityMetadata in dependingMetadata)
            {
                FilterCriteriaSet filters = FilterCriteriaSet.Empty;
                AttributeDescription entityCaptionAttribute = OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(entityMetadata.Value);

                List<FilterCriteriaSet> filterSets = entityMetadata.Value.PlainAttributes.Where(a => a.IsReference && a.ReferencedSchemaName == metadata.SchemaName && a.ReferencedTableName == metadata.TableName)
                    .Select(a => FilterCriteriaSet.And.In(ids.ToList(), entityMetadata.Value.GetColumn(a))).ToList();

                filterSets.ForEach(f => filters = filters != FilterCriteriaSet.Empty ? filters.Merge(f) : f);

                var entities = repo.GetEntitiesByMetadata(entityMetadata.Value, filters).Entities;
                if (entities == null || entities.Count() == 0)
                    continue;

                var dependingEntity = new Tuple<Guid, string, List<Tuple<Guid, string>>>(
                    entityMetadata.Key,
                    entityMetadata.Value.TableName,
                    new List<Tuple<Guid, string>>(entities.Select(e =>
                        new Tuple<Guid, string>((Guid)e.Id, e.GetProperty(entityCaptionAttribute.PropertyName).ToString())
                        ).ToList()));
                dependingEntities.Add(dependingEntity);

                if (deep > 0)
                    dependingEntities.AddRange(GetDependingEntityAccess(dependingEntity.Item2, dependingEntity.Item3.Select(t => t.Item1).ToArray(), deep - 1));
            }
            return dependingEntities;
        }
Ejemplo n.º 4
0
        public static void CopyToNewBudgetVersion(object newBudgetId, object oldBudgetId, Dictionary<string, Dictionary<object, object>> replacesByTable)
        {
            var replaceIds = new Dictionary<object, object>();
            var changedDate = DateTime.Now;
            var repository = new DynamicEntityRepository();

            var newVersion = DynamicRepository.GetByEntity("BudgetVersion",
                FilterCriteriaSet.And.Equal(newBudgetId, "BudgetId")
                    .Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent"))).FirstOrDefault();

            var oldVersion = DynamicRepository.GetByEntity("BudgetVersion",
                FilterCriteriaSet.And.Equal(oldBudgetId, "BudgetId")
                    .Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent"))).FirstOrDefault();

            var newBudget = DynamicRepository.GetByEntity("Budget",
                FilterCriteriaSet.And.Equal(newBudgetId, "Id")).FirstOrDefault();

            bool internalTransaction = false;

            if (SharedCommunicationObjects.SharedTransaction == null)
            {
                SharedCommunicationObjects.CreateSharedTransaction();
                internalTransaction = true;
            }

            try
            {
                #region BudgetItems

                var biMetadata = repository.GetEntityMetadataByEntityName("BudgetItem");

                List<dynamic> records =
                    biMetadata.Get(
                        FilterCriteriaSet.And.Equal((Guid) oldVersion.Id, "BudgetVersionId")
                            .NotEqual(true, "IsDeleted")
                            .NotEqual("Deleted", "State")
                            .NotEqual(true, "IsPrevPeriod"));

                foreach (dynamic r in records)
                {
                    var oldId = r.Id;
                    r.Id = Guid.NewGuid();
                    r.BudgetVersionId = newVersion.Id;
                    r.WasBack = false;
                    r.State = "Draft";
                    r.StateName = "Draft";
                    r.EntityRouteId = null;
                    r.ChangedDate = changedDate;

                    //Заменяем ссылки на скопированные в новый бюджет справочники

                    ReplaceToNewIds(replacesByTable, biMetadata, r);

                    replaceIds.Add(oldId, r.Id);
                }

                var dynamicEntities = records.ConvertAll(d=> d as DynamicEntity);

                PrimaryKeyGenerator.SPGenerateKey(biMetadata, dynamicEntities,
                    new Dictionary<string, string>
                    {
                        {"StoredProcedure", "data_get_sequence"},
                        {"ColumnName", "NumberId"},
                        {"Value", "Value"},
                        {"Code", "BudgetItem"}
                    });

                //Перерасчет остатков
                //BudgetItemMethods.InitResidual(biMetadata, null, dynamicEntities);
                DWKitHelper.EMExecute("BudgetItem.InitResidual", biMetadata, null, dynamicEntities);

                DynamicRepository.InsertByEntity("BudgetItem", records);

                #endregion

                //Словарь со всеми заменами Id-ов
                var allReplaces = replacesByTable.Select(replaces => replaces.Value).ToList();
                allReplaces.Add(replaceIds);

                #region Depends
                var tableList = new Dictionary<string, string>
                {
                    {"BudgetItemAllocation", "BudgetItemId"}
                };

                var b = new Budget();
                foreach (var t in tableList)
                {
                    var replaceByPropertyName = new Dictionary<string, Dictionary<object, object>> { { t.Value, replaceIds } };

                    var tMetadata = repository.GetEntityMetadataByEntityName(t.Key);

                    foreach (var att in tMetadata.PlainAttributes.Where(a=>a.IsReference))
                    {
                        if (!replacesByTable.ContainsKey(att.ReferencedTableName))
                            continue;

                        var replace = replacesByTable[att.ReferencedTableName];

                        replaceByPropertyName.Add(att.PropertyName, replace);
                    }

                    var tmpFilter = FilterCriteriaSet.And.Custom(string.Format("{0} in (select Id from BudgetItem WHERE BudgetVersionId = '{1}')", t.Value, (Guid)oldVersion.Id));
                    var replaces = b.CopyDependsEntity(t.Key, (t.Value == "Id" ? null : "Id"), tmpFilter,
                        replaceByPropertyName, true);

                    allReplaces.Add(replaces);

                }
                #endregion

                #region UploadedFiles
                CopyUploadedFiles(replaceIds);
                #endregion

                #region EntityAccess

                //Все замены в один словарь
                var allReplacesDictionary = allReplaces.SelectMany(dict => dict)
                         .ToDictionary(pair => pair.Key, pair => pair.Value);

                CopyEntityAccess(oldVersion, newVersion, allReplacesDictionary);
                #endregion

                #region Created PrevPeriod BudgetItems

                var biIdsForReclc = BudgetItem.SyncFutureBudgetItem((int)newBudget.Name, replaceIds);
                VtbRestCalculator.Calc.RecalculateAccount(biIdsForReclc, newBudget.Id);

                #endregion

                if (internalTransaction)
                    SharedCommunicationObjects.CommitSharedTransaction();
            }
            catch (Exception ex)
            {
                if (internalTransaction)
                    SharedCommunicationObjects.RollbackSharedTransaction();
                throw ex;
            }
            finally
            {
                if (internalTransaction)
                    SharedCommunicationObjects.DestroySharedTransaction();
            }
        }
Ejemplo n.º 5
0
        public ActionResult GetEntityCaptionAttribute(string metaviewName)
        {
            DynamicEntityRepository repo = new DynamicEntityRepository();
            EntityMetadata metadata = repo.GetEntityMetadataByEntityName(metaviewName);

            string caption = metadata != null ? OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(metadata).PropertyName : String.Empty;
            return Content(ServiceStack.Text.JsonSerializer.SerializeToString(caption));
        }
Ejemplo n.º 6
0
        private static EntityContainer GetCurrencies()
        {
            DynamicEntityRepository rep = new DynamicEntityRepository();

            return(rep.GetEntitiesByMetadata(rep.GetEntityMetadataByEntityName("Currency"), FilterCriteriaSet.Empty));
        }
Ejemplo n.º 7
0
 private static EntityContainer GetCurrencies()
 {
     DynamicEntityRepository rep = new DynamicEntityRepository();
     return rep.GetEntitiesByMetadata(rep.GetEntityMetadataByEntityName("Currency"), FilterCriteriaSet.Empty);
 }