Beispiel #1
0
        public static ExternalMethodCallResult CopyBudgetDictionary(EntityMetadata metadata,
                                                                    Dictionary <string, string> parameters,
                                                                    IEnumerable <DynamicEntity> entities)
        {
            List <string> forms = null;
            List <string> trivialFormsToCopy = null;

            if (parameters.ContainsKey("Forms"))
            {
                forms = parameters["Forms"].Split(',').Select(c => c.Trim()).ToList();
                trivialFormsToCopy = forms.Where(f => !BusinessEntitiesCreations.ContainsKey(f)).ToList();
            }

            foreach (DynamicEntity e in entities)
            {
                var b = new Budget();

                var versions = DynamicRepository.GetByView("BudgetVersion",
                                                           FilterCriteriaSet.And.Equal(e.GetId(), "BudgetId").Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent")));
                if (versions.Count == 0)
                {
                    var v = DynamicRepository.NewByView("BudgetVersion");
                    v.Id        = Guid.NewGuid();
                    v.Name      = "1";
                    v.BudgetId  = e.GetId();
                    v.IsCurrent = true;
                    DynamicRepository.InsertByView("BudgetVersion", new List <dynamic>()
                    {
                        v
                    }, ExternalMethodsCallMode.None);
                }

                var filters = new Dictionary <string, FilterCriteriaSet>
                {
                    { "ContractForBudgetCopy", FilterCriteriaSet.And.Custom("ContractStatusId = 1") }
                };
                var replaces = b.CopyEntityByForms("BudgetId", CommonSettings.CurrentBudget.Id, e.GetId(), trivialFormsToCopy, filters);

                if (forms == null)
                {
                    continue;
                }

                foreach (var k in BusinessEntitiesCreations.Keys)
                {
                    if (!forms.Any(f => f.Equals(k)))
                    {
                        continue;
                    }

                    BusinessEntitiesCreations[k].Invoke(e.GetId(), CommonSettings.CurrentBudget.Id, replaces);
                }
            }

            return(new ExternalMethodCallResult(true));
        }
Beispiel #2
0
        public static ExternalMethodCallResult CopyBudgetDictionary(EntityMetadata metadata,
                                                                 Dictionary<string, string> parameters,
                                                                 IEnumerable<DynamicEntity> entities)
        {
            List<string> forms = null;
            List<string> trivialFormsToCopy = null;

            if (parameters.ContainsKey("Forms"))
            {
                forms = parameters["Forms"].Split(',').Select(c => c.Trim()).ToList();
                trivialFormsToCopy = forms.Where(f => !BusinessEntitiesCreations.ContainsKey(f)).ToList();
            }

            foreach (DynamicEntity e in entities)
            {
                var b = new Budget();

                var versions = DynamicRepository.GetByView("BudgetVersion",
                    FilterCriteriaSet.And.Equal(e.GetId(), "BudgetId").Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent")));
                if (versions.Count == 0)
                {
                    var v = DynamicRepository.NewByView("BudgetVersion");
                    v.Id = Guid.NewGuid();
                    v.Name = "1";
                    v.BudgetId = e.GetId();
                    v.IsCurrent = true;
                    DynamicRepository.InsertByView("BudgetVersion", new List<dynamic>() { v }, ExternalMethodsCallMode.None);
                }

                var filters = new Dictionary<string, FilterCriteriaSet>
                {
                    { "ContractForBudgetCopy", FilterCriteriaSet.And.Custom("ContractStatusId = 1") }
                };
                var replaces = b.CopyEntityByForms("BudgetId", CommonSettings.CurrentBudget.Id, e.GetId(), trivialFormsToCopy, filters);

                if (forms == null)
                    continue;

                foreach (var k in BusinessEntitiesCreations.Keys)
                {
                    if (!forms.Any(f => f.Equals(k)))
                        continue;

                    BusinessEntitiesCreations[k].Invoke(e.GetId(), CommonSettings.CurrentBudget.Id, replaces);
                }

            }

            return new ExternalMethodCallResult(true);
        }