Пример #1
0
        /// <summary>
        /// Добавляет новый сайт
        /// </summary>
        /// <param name="site">информация о сайте</param>
        /// <returns>информация о сайте</returns>
        internal static Site Save(Site site)
        {
            using (var scope = new QPConnectionScope())
            {
                if (QPContext.DatabaseType == DatabaseType.SqlServer)
                {
                    ChangeInsertAccessTriggerState(false);
                    ChangeInsertDefaultTriggerState(false);
                    DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Site, site);
                }

                var fieldValues = site.QpPluginFieldValues;
                var result      = DefaultRepository.Save <Site, SiteDAL>(site);

                CommonSecurity.CreateSiteAccess(scope.DbConnection, result.Id);
                CreateDefaultStatuses(result);
                CreateDefaultNotificationTemplate(result);
                CreateDefaultGroup(result);
                UpdatePluginValues(fieldValues, result.Id);

                if (QPContext.DatabaseType == DatabaseType.SqlServer)
                {
                    DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Site);
                    ChangeInsertAccessTriggerState(true);
                    ChangeInsertDefaultTriggerState(true);
                }

                return(result);
            }
        }
Пример #2
0
        internal static Field Save(Field item)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Field, item);
            var newItem = DefaultRepository.Save <Field, FieldDAL>(item);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Field);
            return(newItem);
        }
Пример #3
0
        /// <summary>
        /// Добавляет новый виртуальный контент
        /// </summary>
        internal static Content Save(Content content)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Content, content);
            var newContent = DefaultRepository.Save <Content, ContentDAL>(content);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Content);
            return(newContent);
        }
Пример #4
0
        internal static StatusType SaveProperties(StatusType statusType)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.StatusType);
            var result = DefaultRepository.Save <StatusType, StatusTypeDAL>(statusType);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.StatusType);
            return(result);
        }
Пример #5
0
        internal static Notification SaveProperties(Notification notification)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Notification, notification);
            var result = DefaultRepository.Save <Notification, NotificationsDAL>(notification);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Notification);
            return(result);
        }
Пример #6
0
        internal static VisualEditorStyle SaveStyleProperties(VisualEditorStyle visualEditorStyle)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorStyle, visualEditorStyle);
            var result = DefaultRepository.Save <VisualEditorStyle, VeStyleDAL>(visualEditorStyle);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorStyle);
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Добавляет новый сайт
        /// </summary>
        /// <param name="site">информация о сайте</param>
        /// <returns>информация о сайте</returns>
        internal static Site Save(Site site)
        {
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Site, site);
            var result = DefaultRepository.Save <Site, SiteDAL>(site);

            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Site);
            return(result);
        }
Пример #8
0
        internal static Workflow SaveProperties(Workflow workflow)
        {
            using (new QPConnectionScope())
            {
                var entities = QPContext.EFContext;
                UpdateRuleOrder(workflow);

                var forceIds = workflow.ForceRulesIds == null ? null : new Queue <int>(workflow.ForceRulesIds);
                workflow.LastModifiedBy = QPContext.CurrentUserId;
                workflow.Created        = Common.GetSqlDate(QPConnectionScope.Current.DbConnection);
                workflow.Modified       = workflow.Created;
                if (workflow.ForceId > 0)
                {
                    workflow.Id = workflow.ForceId;
                }


                var dal = MapperFacade.WorkflowMapper.GetDalObject(workflow);
                entities.Entry(dal).State = EntityState.Added;

                if (QPContext.DatabaseType == DatabaseType.SqlServer)
                {
                    DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Workflow, workflow);
                    ChangeInsertAccessTriggerState(false);
                }

                entities.SaveChanges();
                workflow.Id = (int)dal.Id;

                CommonSecurity.CreateWorkflowAccess(QPConnectionScope.Current.DbConnection, workflow.Id);

                if (QPContext.DatabaseType == DatabaseType.SqlServer)
                {
                    DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Workflow);
                    ChangeInsertAccessTriggerState(true);
                }

                foreach (var rule in workflow.WorkflowRules)
                {
                    rule.WorkflowId = workflow.Id;
                    if (forceIds != null)
                    {
                        rule.Id = forceIds.Dequeue();
                    }

                    var dalRule = MapperFacade.WorkFlowRuleMapper.GetDalObject(rule);
                    entities.Entry(dalRule).State = EntityState.Added;
                }

                DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.WorkflowRule);
                entities.SaveChanges();
                DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.WorkflowRule);

                return(MapperFacade.WorkflowMapper.GetBizObject(dal));
            }
        }
Пример #9
0
        internal static QpPlugin SaveProperties(QpPlugin plugin)
        {
            var      entities = QPContext.EFContext;
            DateTime timeStamp;

            using (var scope = new QPConnectionScope())
            {
                timeStamp = Common.GetSqlDate(scope.DbConnection);

                var dal = MapperFacade.QpPluginMapper.GetDalObject(plugin);
                dal.LastModifiedBy = QPContext.CurrentUserId;
                dal.Modified       = timeStamp;
                dal.Created        = timeStamp;

                entities.Entry(dal).State = EntityState.Added;

                DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.QpPlugin, plugin);
                if (plugin.ForceId != 0)
                {
                    dal.Id = plugin.ForceId;
                }

                entities.SaveChanges();
                DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.QpPlugin);

                Common.CreatePluginTables(scope.DbConnection, (int)dal.Id);

                var forceIds = plugin.ForceFieldIds == null ? null : new Queue <int>(plugin.ForceFieldIds);
                var fields   = new List <PluginFieldDAL>();
                foreach (var field in plugin.Fields)
                {
                    var dalField = MapperFacade.QpPluginFieldMapper.GetDalObject(field);
                    dalField.PluginId = dal.Id;
                    if (forceIds != null)
                    {
                        dalField.Id = forceIds.Dequeue();
                    }

                    entities.Entry(dalField).State = EntityState.Added;
                    fields.Add(dalField);
                }

                DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.QpPluginField);
                entities.SaveChanges();
                DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.QpPluginField);

                foreach (var field in fields)
                {
                    Common.AddPluginColumn(scope.DbConnection, field);
                }

                return(MapperFacade.QpPluginMapper.GetBizObject(dal));
            }
        }
Пример #10
0
        internal static VisualEditorPlugin SavePluginProperties(VisualEditorPlugin plugin)
        {
            var      entities = QPContext.EFContext;
            DateTime timeStamp;

            using (var scope = new QPConnectionScope())
            {
                timeStamp = Common.GetSqlDate(scope.DbConnection);
            }

            var dal = MapperFacade.VisualEditorPluginMapper.GetDalObject(plugin);

            dal.LastModifiedBy = QPContext.CurrentUserId;
            dal.Modified       = timeStamp;
            dal.Created        = timeStamp;

            entities.VePluginSet.AddObject(dal);

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorPlugin, plugin);
            if (plugin.ForceId != 0)
            {
                dal.Id = plugin.ForceId;
            }

            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorPlugin);

            var forceIds = plugin.ForceCommandIds == null ? null : new Queue <int>(plugin.ForceCommandIds);

            foreach (var command in plugin.VeCommands)
            {
                var dalCommand = MapperFacade.VisualEditorCommandMapper.GetDalObject(command);
                dalCommand.PluginId = dal.Id;
                if (forceIds != null)
                {
                    dalCommand.Id = forceIds.Dequeue();
                }

                dalCommand.LastModifiedBy = QPContext.CurrentUserId;
                dalCommand.Modified       = timeStamp;
                dalCommand.Created        = timeStamp;
                entities.VeCommandSet.AddObject(dalCommand);
            }

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorCommand);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorCommand);

            return(MapperFacade.VisualEditorPluginMapper.GetBizObject(dal));
        }
Пример #11
0
        internal static Workflow SaveProperties(Workflow workflow)
        {
            var entities = QPContext.EFContext;

            UpdateRuleOrder(workflow);

            var forceIds = workflow.ForceRulesIds == null ? null : new Queue <int>(workflow.ForceRulesIds);
            var dal      = MapperFacade.WorkflowMapper.GetDalObject(workflow);

            dal.LastModifiedBy = QPContext.CurrentUserId;
            using (new QPConnectionScope())
            {
                dal.Created  = Common.GetSqlDate(QPConnectionScope.Current.DbConnection);
                dal.Modified = dal.Created;
            }

            entities.WorkflowSet.AddObject(dal);
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.Workflow, workflow);
            if (workflow.ForceId > 0)
            {
                dal.Id = workflow.ForceId;
            }

            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.Workflow);
            foreach (var rule in workflow.WorkflowRules)
            {
                var dalRule = MapperFacade.WorkFlowRuleMapper.GetDalObject(rule);
                if (forceIds != null)
                {
                    dalRule.Id = forceIds.Dequeue();
                }
                dalRule.WorkflowId = dal.Id;
                entities.WorkflowRulesSet.AddObject(dalRule);
            }

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.WorkflowRule);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.WorkflowRule);

            return(MapperFacade.WorkflowMapper.GetBizObject(dal));
        }
Пример #12
0
        internal static VisualEditorPlugin UpdatePluginProperties(VisualEditorPlugin plugin)
        {
            var      entities = QPContext.EFContext;
            DateTime timeStamp;

            using (var scope = new QPConnectionScope())
            {
                timeStamp = Common.GetSqlDate(scope.DbConnection);
            }

            var dal = MapperFacade.VisualEditorPluginMapper.GetDalObject(plugin);

            dal.LastModifiedBy        = QPContext.CurrentUserId;
            dal.Modified              = timeStamp;
            entities.Entry(dal).State = EntityState.Modified;
            UpdateCommands(plugin, entities, timeStamp);
            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.VisualEditorPlugin, plugin);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.VisualEditorPlugin);
            return(GetPluginPropertiesById(plugin.Id));
        }
Пример #13
0
        internal static CustomAction Save(CustomAction customAction)
        {
            var entities  = QPContext.EFContext;
            var actionDal = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action);

            entities.BackendActionSet.AddObject(actionDal);

            EntityObject.VerifyIdentityInserting(EntityTypeCode.BackendAction, actionDal.Id, customAction.ForceActionId);
            if (customAction.ForceActionId != 0)
            {
                actionDal.Id = customAction.ForceActionId;
            }

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.BackendAction);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.BackendAction);

            var customActionDal = MapperFacade.CustomActionMapper.GetDalObject(customAction);

            customActionDal.LastModifiedBy = QPContext.CurrentUserId;
            customActionDal.Action         = actionDal;
            using (new QPConnectionScope())
            {
                customActionDal.Created  = Common.GetSqlDate(QPConnectionScope.Current.DbConnection);
                customActionDal.Modified = customActionDal.Created;
            }

            entities.CustomActionSet.AddObject(customActionDal);

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.CustomAction, customAction);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.CustomAction);

            foreach (var t in MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList()))
            {
                t.ActionId = customActionDal.Action.Id;
                entities.ToolbarButtonSet.AddObject(t);
            }

            foreach (var c in MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList()))
            {
                c.ActionId = customActionDal.Action.Id;
                entities.ContextMenuItemSet.AddObject(c);
            }

            foreach (var s in MapperFacade.SiteMapper.GetDalList(customAction.Sites.ToList()))
            {
                entities.SiteSet.Attach(s);
                customActionDal.Sites.Add(s);
            }

            foreach (var s in MapperFacade.ContentMapper.GetDalList(customAction.Contents.ToList()))
            {
                entities.ContentSet.Attach(s);
                customActionDal.Contents.Add(s);
            }

            if (customAction.Action.IsInterface)
            {
                var refreshBtnDal = CreateRefreshButton(customActionDal.ActionId);
                entities.ToolbarButtonSet.AddObject(refreshBtnDal);
            }

            entities.SaveChanges();
            var contextMenuId = entities.EntityTypeSet.Single(t => t.Id == customAction.Action.EntityTypeId).ContextMenuId;

            SetBottomSeparator(contextMenuId);

            var updated = MapperFacade.CustomActionMapper.GetBizObject(customActionDal);

            BackendActionCache.Reset();
            return(updated);
        }
Пример #14
0
        internal static CustomAction Save(CustomAction customAction)
        {
            var entities  = QPContext.EFContext;
            var actionDal = MapperFacade.BackendActionMapper.GetDalObject(customAction.Action);

            entities.Entry(actionDal).State = EntityState.Added;

            EntityObject.VerifyIdentityInserting(EntityTypeCode.BackendAction, actionDal.Id, customAction.ForceActionId);
            if (customAction.ForceActionId != 0)
            {
                actionDal.Id = customAction.ForceActionId;
            }

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.BackendAction);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.BackendAction);

            var customActionDal = MapperFacade.CustomActionMapper.GetDalObject(customAction);

            customActionDal.LastModifiedBy = QPContext.CurrentUserId;
            customActionDal.Action         = actionDal;


            using (new QPConnectionScope())
            {
                customActionDal.Created  = Common.GetSqlDate(QPConnectionScope.Current.DbConnection);
                customActionDal.Modified = customActionDal.Created;
            }

            entities.Entry(customActionDal).State = EntityState.Added;

            DefaultRepository.TurnIdentityInsertOn(EntityTypeCode.CustomAction, customAction);
            entities.SaveChanges();
            DefaultRepository.TurnIdentityInsertOff(EntityTypeCode.CustomAction);

            var buttonsToInsert = MapperFacade.ToolbarButtonMapper.GetDalList(customAction.Action.ToolbarButtons.ToList());

            foreach (var item in buttonsToInsert)
            {
                item.ActionId = customActionDal.ActionId;
                entities.Entry(item).State = EntityState.Added;
            }

            var cmiToInsert = MapperFacade.ContextMenuItemMapper.GetDalList(customAction.Action.ContextMenuItems.ToList());

            foreach (var item in cmiToInsert)
            {
                item.ActionId = customActionDal.ActionId;
                entities.Entry(item).State = EntityState.Added;
            }

            customActionDal.SiteCustomActionBinds = new List <SiteCustomActionBindDAL>();
            foreach (var item in customAction.SiteIds)
            {
                var bind = new SiteCustomActionBindDAL {
                    SiteId = item, CustomAction = customActionDal
                };
                customActionDal.SiteCustomActionBinds.Add(bind);
            }

            customActionDal.ContentCustomActionBinds = new List <ContentCustomActionBindDAL>();
            foreach (var item in customAction.ContentIds)
            {
                var bind = new ContentCustomActionBindDAL {
                    ContentId = item, CustomAction = customActionDal
                };
                customActionDal.ContentCustomActionBinds.Add(bind);
            }

            if (customAction.Action.IsInterface)
            {
                var refreshBtnDal = CreateRefreshButton(customActionDal.ActionId);
                entities.Entry(refreshBtnDal).State = EntityState.Added;
            }

            entities.SaveChanges();
            var contextMenuId = entities.EntityTypeSet.Single(t => t.Id == customAction.Action.EntityTypeId).ContextMenuId;

            SetBottomSeparator(contextMenuId);

            var updated = MapperFacade.CustomActionMapper.GetBizObject(customActionDal);

            updated.Action = MapperFacade.BackendActionMapper.GetBizObject(actionDal);
            BackendActionCache.ResetForCustomerCode();
            return(updated);
        }