Пример #1
0
        public void InitializeSystemEntities()
        {
            EntityResponse response = null;
            FieldResponse fieldResponse = null;
            EntityManager entMan = new EntityManager();
            EntityRelationManager rm = new EntityRelationManager();
            RecordManager recMan = new RecordManager(true);

            using (var connection = DbContext.Current.CreateConnection())
            {
                //setup necessary extensions
                DbRepository.CreatePostgresqlExtensions();

                try
                {
                    connection.BeginTransaction();

                    CheckCreateSystemTables();

                    DbSystemSettings storeSystemSettings = DbContext.Current.SettingsRepository.Read();

                    Guid systemSettingsId = new Guid("F3223177-B2FF-43F5-9A4B-FF16FC67D186");
                    SystemSettings systemSettings = new SystemSettings();
                    systemSettings.Id = systemSettingsId;

                    int currentVersion = 0;
                    if (storeSystemSettings != null)
                    {
                        systemSettings = new SystemSettings(storeSystemSettings);
                        currentVersion = systemSettings.Version;
                    }

                    //tmp code - during debug only
                    //entityManager.DeleteEntity(SystemIds.UserEntityId);
                    //entityManager.DeleteEntity(SystemIds.RoleEntityId);
                    //rm.Delete(SystemIds.UserRoleRelationId);
                    //currentVersion = 0;

                    if (currentVersion < 150508)
                    {
                        systemSettings.Version = 150508;

                        List<Guid> allowedRoles = new List<Guid>();
                        allowedRoles.Add(SystemIds.AdministratorRoleId);

                        #region << create user entity >>
                        {

                            InputEntity userEntity = new InputEntity();
                            userEntity.Id = SystemIds.UserEntityId;
                            userEntity.Name = "user";
                            userEntity.Label = "User";
                            userEntity.LabelPlural = "Users";
                            userEntity.System = true;
                            userEntity.RecordPermissions = new RecordPermissions();
                            userEntity.RecordPermissions.CanCreate = new List<Guid>();
                            userEntity.RecordPermissions.CanRead = new List<Guid>();
                            userEntity.RecordPermissions.CanUpdate = new List<Guid>();
                            userEntity.RecordPermissions.CanDelete = new List<Guid>();
                            userEntity.RecordPermissions.CanCreate.Add(SystemIds.GuestRoleId);
                            userEntity.RecordPermissions.CanCreate.Add(SystemIds.AdministratorRoleId);
                            userEntity.RecordPermissions.CanRead.Add(SystemIds.GuestRoleId);
                            userEntity.RecordPermissions.CanRead.Add(SystemIds.RegularRoleId);
                            userEntity.RecordPermissions.CanRead.Add(SystemIds.AdministratorRoleId);
                            userEntity.RecordPermissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                            userEntity.RecordPermissions.CanDelete.Add(SystemIds.AdministratorRoleId);
                            var systemItemIdDictionary = new Dictionary<string, Guid>();
                            systemItemIdDictionary["id"] = new Guid("8e438549-fd30-4766-95a9-061008cee48e");
                            systemItemIdDictionary["created_on"] = new Guid("6fda5e6b-80e6-4d8a-9e2a-d983c3694e96");
                            systemItemIdDictionary["created_by"] = new Guid("825e8367-3be1-4022-ba66-6494859d70d9");
                            systemItemIdDictionary["last_modified_on"] = new Guid("5a975d33-47c6-4ba6-83c8-c24034206879");
                            systemItemIdDictionary["last_modified_by"] = new Guid("cafc8cda-1a1d-43e4-9406-6acf8ba8fa8d");
                            response = entMan.CreateEntity(userEntity, false, false, systemItemIdDictionary);

                            InputTextField firstName = new InputTextField();

                            firstName.Id = new Guid("DF211549-41CC-4D11-BB43-DACA4C164411");
                            firstName.Name = "first_name";
                            firstName.Label = "First Name";
                            firstName.PlaceholderText = "";
                            firstName.Description = "First name of the user";
                            firstName.HelpText = "";
                            firstName.Required = false;
                            firstName.Unique = false;
                            firstName.Searchable = false;
                            firstName.Auditable = false;
                            firstName.System = true;
                            firstName.DefaultValue = "";

                            firstName.MaxLength = 200;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, firstName, false);

                            InputTextField lastName = new InputTextField();

                            lastName.Id = new Guid("63E685B1-B2C6-4961-B393-2B6723EBD1BF");
                            lastName.Name = "last_name";
                            lastName.Label = "Last Name";
                            lastName.PlaceholderText = "";
                            lastName.Description = "Last name of the user";
                            lastName.HelpText = "";
                            lastName.Required = false;
                            lastName.Unique = false;
                            lastName.Searchable = false;
                            lastName.Auditable = false;
                            lastName.System = true;
                            lastName.DefaultValue = "";

                            lastName.MaxLength = 200;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, lastName, false);

                            InputTextField userName = new InputTextField();
                            userName.Id = new Guid("263c0b21-88c1-4c2b-80b4-db7402b0d2e2");
                            userName.Name = "username";
                            userName.Label = "User Name";
                            userName.PlaceholderText = "";
                            userName.Description = "screen name for the user";
                            userName.HelpText = "";
                            userName.Required = true;
                            userName.Unique = true;
                            userName.Searchable = true;
                            userName.Auditable = false;
                            userName.System = true;
                            userName.DefaultValue = string.Empty;
                            userName.MaxLength = 200;
                            fieldResponse = entMan.CreateField(userEntity.Id.Value, userName, false);

                            InputEmailField email = new InputEmailField();

                            email.Id = new Guid("9FC75C8F-CE80-4A64-81D7-E2BEFA5E4815");
                            email.Name = "email";
                            email.Label = "Email";
                            email.PlaceholderText = "";
                            email.Description = "Email address of the user";
                            email.HelpText = "";
                            email.Required = true;
                            email.Unique = true;
                            email.Searchable = true;
                            email.Auditable = false;
                            email.System = true;
                            email.DefaultValue = string.Empty;

                            email.MaxLength = 255;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, email, false);

                            InputPasswordField password = new InputPasswordField();

                            password.Id = new Guid("4EDE88D9-217A-4462-9300-EA0D6AFCDCEA");
                            password.Name = "password";
                            password.Label = "Password";
                            password.PlaceholderText = "";
                            password.Description = "Password for the user account";
                            password.HelpText = "";
                            password.Required = true;
                            password.Unique = false;
                            password.Searchable = false;
                            password.Auditable = false;
                            password.System = true;
                            password.MinLength = 6;
                            password.MaxLength = 24;
                            password.Encrypted = true;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, password, false);

                            InputDateTimeField lastLoggedIn = new InputDateTimeField();

                            lastLoggedIn.Id = new Guid("3C85CCEC-D526-4E47-887F-EE169D1F508D");
                            lastLoggedIn.Name = "last_logged_in";
                            lastLoggedIn.Label = "Last Logged In";
                            lastLoggedIn.PlaceholderText = "";
                            lastLoggedIn.Description = "";
                            lastLoggedIn.HelpText = "";
                            lastLoggedIn.Required = false;
                            lastLoggedIn.Unique = false;
                            lastLoggedIn.Searchable = false;
                            lastLoggedIn.Auditable = true;
                            lastLoggedIn.System = true;
                            lastLoggedIn.DefaultValue = null;

                            lastLoggedIn.Format = "dd MMM yyyy HH:mm:ss";
                            lastLoggedIn.UseCurrentTimeAsDefaultValue = true;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, lastLoggedIn, false);

                            InputCheckboxField enabledField = new InputCheckboxField();

                            enabledField.Id = new Guid("C0C63650-7572-4252-8E4B-4E25C94897A6");
                            enabledField.Name = "enabled";
                            enabledField.Label = "Enabled";
                            enabledField.PlaceholderText = "";
                            enabledField.Description = "Shows if the user account is enabled";
                            enabledField.HelpText = "";
                            enabledField.Required = true;
                            enabledField.Unique = false;
                            enabledField.Searchable = false;
                            enabledField.Auditable = false;
                            enabledField.System = true;
                            enabledField.DefaultValue = false;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, enabledField, false);

                            InputCheckboxField verifiedUserField = new InputCheckboxField();

                            verifiedUserField.Id = new Guid("F1BA5069-8CC9-4E66-BCC3-60E33C79C265");
                            verifiedUserField.Name = "verified";
                            verifiedUserField.Label = "Verified";
                            verifiedUserField.PlaceholderText = "";
                            verifiedUserField.Description = "Shows if the user email is verified";
                            verifiedUserField.HelpText = "";
                            verifiedUserField.Required = true;
                            verifiedUserField.Unique = false;
                            verifiedUserField.Searchable = false;
                            verifiedUserField.Auditable = false;
                            verifiedUserField.System = true;
                            verifiedUserField.DefaultValue = false;

                            fieldResponse = entMan.CreateField(userEntity.Id.Value, verifiedUserField, false);

                            #region << image >>
                            {
                                InputImageField imageField = new InputImageField();
                                imageField.Id = new Guid("bf199b74-4448-4f58-93f5-6b86d888843b");
                                imageField.Name = "image";
                                imageField.Label = "Image";
                                imageField.PlaceholderText = "";
                                imageField.Description = "";
                                imageField.HelpText = "";
                                imageField.Required = false;
                                imageField.Unique = false;
                                imageField.Searchable = false;
                                imageField.Auditable = false;
                                imageField.System = true;
                                imageField.DefaultValue = string.Empty;
                                imageField.EnableSecurity = false;
                                {
                                    var createResponse = entMan.CreateField(SystemIds.UserEntityId, imageField, false);
                                    if (!createResponse.Success)
                                        throw new Exception("System error 10060. Entity: user. Field: image" + " Message:" + createResponse.Message);
                                }
                            }
                            #endregion
                        }

                        #endregion

                        #region << create role entity >>

                        {
                            InputEntity roleEntity = new InputEntity();
                            roleEntity.Id = SystemIds.RoleEntityId;
                            roleEntity.Name = "role";
                            roleEntity.Label = "Role";
                            roleEntity.LabelPlural = "Roles";
                            roleEntity.System = true;
                            roleEntity.RecordPermissions = new RecordPermissions();
                            roleEntity.RecordPermissions.CanCreate = new List<Guid>();
                            roleEntity.RecordPermissions.CanRead = new List<Guid>();
                            roleEntity.RecordPermissions.CanUpdate = new List<Guid>();
                            roleEntity.RecordPermissions.CanDelete = new List<Guid>();
                            roleEntity.RecordPermissions.CanCreate.Add(SystemIds.GuestRoleId);
                            roleEntity.RecordPermissions.CanCreate.Add(SystemIds.AdministratorRoleId);
                            roleEntity.RecordPermissions.CanRead.Add(SystemIds.RegularRoleId);
                            roleEntity.RecordPermissions.CanRead.Add(SystemIds.GuestRoleId);
                            roleEntity.RecordPermissions.CanRead.Add(SystemIds.AdministratorRoleId);
                            roleEntity.RecordPermissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                            roleEntity.RecordPermissions.CanDelete.Add(SystemIds.AdministratorRoleId);
                            var systemItemIdDictionary = new Dictionary<string, Guid>();
                            systemItemIdDictionary["id"] = new Guid("37fd9c4f-5413-4f3a-aa2f-d831cc106d03");
                            systemItemIdDictionary["created_on"] = new Guid("64047bab-dc73-4175-a744-e5d565e8adbb");
                            systemItemIdDictionary["created_by"] = new Guid("0ccd806b-715c-42d4-a580-f3f11f55d937");
                            systemItemIdDictionary["last_modified_on"] = new Guid("c4522433-1c67-44f9-b461-e85d4d363b70");
                            systemItemIdDictionary["last_modified_by"] = new Guid("a4489db4-9d76-4d5a-8940-6ef2da562c25");
                            systemItemIdDictionary["user_role_created_by"] = new Guid("c6151e80-9dce-4c0b-ae5f-4798e14cff4c");
                            systemItemIdDictionary["user_role_modified_by"] = new Guid("f3efaefe-32d2-4840-ac06-bc5723e323d0");
                            response = entMan.CreateEntity(roleEntity, false, false, systemItemIdDictionary);

                            InputTextField nameRoleField = new InputTextField();

                            nameRoleField.Id = new Guid("36F91EBD-5A02-4032-8498-B7F716F6A349");
                            nameRoleField.Name = "name";
                            nameRoleField.Label = "Name";
                            nameRoleField.PlaceholderText = "";
                            nameRoleField.Description = "The name of the role";
                            nameRoleField.HelpText = "";
                            nameRoleField.Required = true;
                            nameRoleField.Unique = false;
                            nameRoleField.Searchable = false;
                            nameRoleField.Auditable = false;
                            nameRoleField.System = true;
                            nameRoleField.DefaultValue = "";
                            nameRoleField.MaxLength = 200;
                            nameRoleField.EnableSecurity = true;
                            nameRoleField.Permissions = new FieldPermissions();
                            nameRoleField.Permissions.CanRead = new List<Guid>();
                            nameRoleField.Permissions.CanUpdate = new List<Guid>();
                            //READ
                            nameRoleField.Permissions.CanRead.Add(SystemIds.AdministratorRoleId);
                            nameRoleField.Permissions.CanRead.Add(SystemIds.RegularRoleId);
                            //UPDATE
                            nameRoleField.Permissions.CanUpdate.Add(SystemIds.AdministratorRoleId);

                            fieldResponse = entMan.CreateField(roleEntity.Id.Value, nameRoleField, false);

                            InputTextField descriptionRoleField = new InputTextField();

                            descriptionRoleField.Id = new Guid("4A8B9E0A-1C36-40C6-972B-B19E2B5D265B");
                            descriptionRoleField.Name = "description";
                            descriptionRoleField.Label = "Description";
                            descriptionRoleField.PlaceholderText = "";
                            descriptionRoleField.Description = "";
                            descriptionRoleField.HelpText = "";
                            descriptionRoleField.Required = true;
                            descriptionRoleField.Unique = false;
                            descriptionRoleField.Searchable = false;
                            descriptionRoleField.Auditable = false;
                            descriptionRoleField.System = true;
                            descriptionRoleField.DefaultValue = "";

                            descriptionRoleField.MaxLength = 200;

                            fieldResponse = entMan.CreateField(roleEntity.Id.Value, descriptionRoleField, false);
                        }

                        #endregion

                        #region << create user - role relation >>
                        {
                            var userEntity = entMan.ReadEntity(SystemIds.UserEntityId).Object;
                            var roleEntity = entMan.ReadEntity(SystemIds.RoleEntityId).Object;

                            EntityRelation userRoleRelation = new EntityRelation();
                            userRoleRelation.Id = SystemIds.UserRoleRelationId;
                            userRoleRelation.Name = "user_role";
                            userRoleRelation.Label = "User-Role";
                            userRoleRelation.System = true;
                            userRoleRelation.RelationType = EntityRelationType.ManyToMany;
                            userRoleRelation.TargetEntityId = userEntity.Id;
                            userRoleRelation.TargetFieldId = userEntity.Fields.Single(x => x.Name == "id").Id;
                            userRoleRelation.OriginEntityId = roleEntity.Id;
                            userRoleRelation.OriginFieldId = roleEntity.Fields.Single(x => x.Name == "id").Id;
                            {
                                var result = rm.Create(userRoleRelation);
                                if (!result.Success)
                                    throw new Exception("CREATE USER-ROLE RELATION:" + result.Message);
                            }
                        }
                        #endregion

                        #region << create system records >>

                        {
                            EntityRecord user = new EntityRecord();
                            user["id"] = SystemIds.SystemUserId;
                            user["first_name"] = "Local";
                            user["last_name"] = "System";
                            user["password"] = Guid.NewGuid().ToString();
                            user["email"] = "*****@*****.**";
                            user["username"] = "******";
                            user["created_by"] = SystemIds.SystemUserId;
                            user["last_modified_by"] = SystemIds.SystemUserId;
                            user["created_on"] = DateTime.UtcNow;
                            user["enabled"] = true;

                            QueryResponse result = recMan.CreateRecord("user", user);
                            if (!result.Success)
                                throw new Exception("CREATE SYSTEM USER RECORD:" + result.Message);
                        }

                        {
                            EntityRecord user = new EntityRecord();
                            user["id"] = SystemIds.FirstUserId;
                            user["first_name"] = "WebVella";
                            user["last_name"] = "Erp";
                            user["password"] = "******";
                            user["email"] = "*****@*****.**";
                            user["username"] = "******";
                            user["created_by"] = SystemIds.SystemUserId;
                            user["last_modified_by"] = SystemIds.SystemUserId;
                            user["created_on"] = DateTime.UtcNow;
                            user["enabled"] = true;

                            QueryResponse result = recMan.CreateRecord("user", user);
                            if (!result.Success)
                                throw new Exception("CREATE FIRST USER RECORD:" + result.Message);
                        }

                        {
                            EntityRecord adminRole = new EntityRecord();
                            adminRole["id"] = SystemIds.AdministratorRoleId;
                            adminRole["name"] = "administrator";
                            adminRole["description"] = "";
                            adminRole["created_by"] = SystemIds.SystemUserId;
                            adminRole["last_modified_by"] = SystemIds.SystemUserId;
                            adminRole["created_on"] = DateTime.UtcNow;

                            QueryResponse result = recMan.CreateRecord("role", adminRole);
                            if (!result.Success)
                                throw new Exception("CREATE ADMINITRATOR ROLE RECORD:" + result.Message);
                        }

                        {
                            EntityRecord regularRole = new EntityRecord();
                            regularRole["id"] = SystemIds.RegularRoleId;
                            regularRole["name"] = "regular";
                            regularRole["description"] = "";
                            regularRole["created_by"] = SystemIds.SystemUserId;
                            regularRole["last_modified_by"] = SystemIds.SystemUserId;
                            regularRole["created_on"] = DateTime.UtcNow;

                            QueryResponse result = recMan.CreateRecord("role", regularRole);
                            if (!result.Success)
                                throw new Exception("CREATE REGULAR ROLE RECORD:" + result.Message);
                        }

                        {
                            EntityRecord guestRole = new EntityRecord();
                            guestRole["id"] = SystemIds.GuestRoleId;
                            guestRole["name"] = "guest";
                            guestRole["description"] = "";
                            guestRole["created_by"] = SystemIds.SystemUserId;
                            guestRole["last_modified_by"] = SystemIds.SystemUserId;
                            guestRole["created_on"] = DateTime.UtcNow;

                            QueryResponse result = recMan.CreateRecord("role", guestRole);
                            if (!result.Success)
                                throw new Exception("CREATE GUEST ROLE RECORD:" + result.Message);
                        }

                        {
                            QueryResponse result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.AdministratorRoleId, SystemIds.SystemUserId);
                            if (!result.Success)
                                throw new Exception("CREATE SYSTEM-USER <-> ADMINISTRATOR ROLE RELATION RECORD:" + result.Message);

                        }

                        {
                            QueryResponse result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.AdministratorRoleId, SystemIds.FirstUserId);
                            if (!result.Success)
                                throw new Exception("CREATE FIRST-USER <-> ADMINISTRATOR ROLE RELATION RECORD:" + result.Message);

                            result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.RegularRoleId, SystemIds.FirstUserId);
                            if (!result.Success)
                                throw new Exception("CREATE FIRST-USER <-> REGULAR ROLE RELATION RECORD:" + result.Message);

                        }

                        #endregion

                        #region << create Area entity >>
                        {
                            InputEntity areaEntity = new InputEntity();
                            areaEntity.Id = SystemIds.AreaEntityId;
                            areaEntity.Name = "area";
                            areaEntity.Label = "Area";
                            areaEntity.LabelPlural = "areas";
                            areaEntity.System = true;
                            areaEntity.IconName = "folder";
                            areaEntity.Weight = 10;
                            areaEntity.RecordPermissions = new RecordPermissions();
                            areaEntity.RecordPermissions.CanCreate = new List<Guid>();
                            areaEntity.RecordPermissions.CanRead = new List<Guid>();
                            areaEntity.RecordPermissions.CanUpdate = new List<Guid>();
                            areaEntity.RecordPermissions.CanDelete = new List<Guid>();
                            areaEntity.RecordPermissions.CanCreate.Add(SystemIds.AdministratorRoleId);
                            areaEntity.RecordPermissions.CanRead.Add(SystemIds.RegularRoleId);
                            areaEntity.RecordPermissions.CanRead.Add(SystemIds.AdministratorRoleId);
                            areaEntity.RecordPermissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                            areaEntity.RecordPermissions.CanDelete.Add(SystemIds.AdministratorRoleId);

                            var systemItemIdDictionary = new Dictionary<string, Guid>();
                            systemItemIdDictionary["id"] = new Guid("19f16bdb-56e6-46bf-8310-2b42fd78be2a");
                            systemItemIdDictionary["created_on"] = new Guid("3e6be69e-8f25-40e4-9f21-86b0d1404230");
                            systemItemIdDictionary["created_by"] = new Guid("16fbba6c-6282-4828-9873-86b8fef745d4");
                            systemItemIdDictionary["last_modified_on"] = new Guid("5f076d8b-e587-4201-9481-67e19789ff6c");
                            systemItemIdDictionary["last_modified_by"] = new Guid("721b27b3-741d-4414-8783-a0245a4eec58");
                            systemItemIdDictionary["user_area_created_by"] = new Guid("5fe5fdc4-ee10-4661-93e7-25ea2a61e710");
                            systemItemIdDictionary["user_area_modified_by"] = new Guid("bb52122c-a354-4668-9423-71dfdc3d9f36");
                            {
                                var createResponse = entMan.CreateEntity(areaEntity, false, false, systemItemIdDictionary);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10330. Message:" + createResponse.Message);
                            }

                            InputTextField color = new InputTextField();
                            color.Id = new Guid("2B4AACD9-3C34-4C44-B3A3-8AFF1520CFF6");
                            color.Name = "color";
                            color.Label = "Color";
                            color.PlaceholderText = "";
                            color.Description = "";
                            color.HelpText = "";
                            color.Required = true;
                            color.Unique = false;
                            color.Searchable = false;
                            color.Auditable = false;
                            color.System = true;
                            color.DefaultValue = "teal";
                            color.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, color, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputTextField label = new InputTextField();
                            label.Id = new Guid("F050E7A1-AFB7-4346-B57B-1F12B2BD5AE5");
                            label.Name = "label";
                            label.Label = "Label";
                            label.PlaceholderText = "";
                            label.Description = "";
                            label.HelpText = "";
                            label.Required = true;
                            label.Unique = false;
                            label.Searchable = false;
                            label.Auditable = false;
                            label.System = true;
                            label.DefaultValue = "Default";
                            label.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, label, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputTextField iconName = new InputTextField();
                            iconName.Id = new Guid("5EA0C872-D219-4D94-9EFA-C5DA978D316B");
                            iconName.Name = "icon_name";
                            iconName.Label = "Icon Name";
                            iconName.PlaceholderText = "";
                            iconName.Description = "";
                            iconName.HelpText = "";
                            iconName.Required = true;
                            iconName.Unique = false;
                            iconName.Searchable = false;
                            iconName.Auditable = false;
                            iconName.System = true;
                            iconName.DefaultValue = "database";
                            iconName.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, iconName, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputNumberField weight = new InputNumberField();
                            weight.Id = new Guid("9B169431-6C31-4141-80EB-5844B8333E63");
                            weight.Name = "weight";
                            weight.Label = "Weight";
                            weight.PlaceholderText = "";
                            weight.Description = "";
                            weight.HelpText = "";
                            weight.Required = true;
                            weight.Unique = false;
                            weight.Searchable = false;
                            weight.Auditable = false;
                            weight.System = true;
                            weight.DefaultValue = 10;
                            weight.MinValue = 0;
                            weight.DecimalPlaces = 2;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, weight, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputTextField attachments = new InputTextField();
                            attachments.Id = new Guid("288EA657-C12C-4AC1-B701-81D6F9F39363");
                            attachments.Name = "attachments";
                            attachments.Label = "Attachments JSON String";
                            attachments.PlaceholderText = "";
                            attachments.Description = "Stringified Array of attached objects";
                            attachments.HelpText = "";
                            attachments.Required = false;
                            attachments.Unique = false;
                            attachments.Searchable = false;
                            attachments.Auditable = false;
                            attachments.System = true;
                            attachments.DefaultValue = null;
                            attachments.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, attachments, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputTextField name = new InputTextField();
                            name.Id = new Guid("F297577B-073E-4D18-81F3-675C1AFB466D");
                            name.Name = "name";
                            name.Label = "Name";
                            name.PlaceholderText = "";
                            name.Description = "";
                            name.HelpText = "";
                            name.Required = true;
                            name.Unique = false;
                            name.Searchable = false;
                            name.Auditable = false;
                            name.System = true;
                            name.DefaultValue = "default";
                            name.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, name, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            InputTextField roles = new InputTextField();
                            roles.Id = new Guid("8E486F76-D0C1-4D0E-8617-9EF868BF1C55");
                            roles.Name = "roles";
                            roles.Label = "Roles JSON String";
                            roles.PlaceholderText = "";
                            roles.Description = "Stringified Array of roles that have access to this area";
                            roles.HelpText = "";
                            roles.Required = false;
                            roles.Unique = false;
                            roles.Searchable = false;
                            roles.Auditable = false;
                            roles.System = true;
                            roles.DefaultValue = null;
                            roles.MaxLength = null;
                            {
                                var createResponse = entMan.CreateField(SystemIds.AreaEntityId, roles, false);
                                if (!createResponse.Success)
                                    throw new Exception("System error 10340. Message:" + createResponse.Message);
                            }

                            #region << folder >>
                            {
                                InputTextField textboxField = new InputTextField();
                                textboxField.Id = new Guid("6a0fdf14-2d2b-4c6c-b2f1-4d846c7d5ab8");
                                textboxField.Name = "folder";
                                textboxField.Label = "folder";
                                textboxField.PlaceholderText = "";
                                textboxField.Description = "";
                                textboxField.HelpText = "";
                                textboxField.Required = false;
                                textboxField.Unique = false;
                                textboxField.Searchable = false;
                                textboxField.Auditable = false;
                                textboxField.System = true;
                                textboxField.DefaultValue = string.Empty;
                                textboxField.MaxLength = null;
                                textboxField.EnableSecurity = true;
                                textboxField.Permissions = new FieldPermissions();
                                textboxField.Permissions.CanRead = new List<Guid>();
                                textboxField.Permissions.CanUpdate = new List<Guid>();
                                //READ
                                textboxField.Permissions.CanRead.Add(SystemIds.AdministratorRoleId);
                                //UPDATE
                                textboxField.Permissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                                {
                                    var createResponse = entMan.CreateField(SystemIds.AreaEntityId, textboxField, false);
                                    if (!createResponse.Success)
                                        throw new Exception("System error 10060. Entity: area Field: folder" + " Message:" + response.Message);
                                }
                            }
                            #endregion

                        }
                        #endregion
                    }

                    if (currentVersion < 20160430)
                    {
                        systemSettings.Version = 20160430;

                        #region << plugin_data >>
                        var PLUGIN_DATA_ID = new Guid("d928d031-c8b1-4359-be3e-39bceb58f268");
                        var PLUGIN_DATA_NAME = "plugin_data";
                        {
                            #region << entity >>
                            {
                                InputEntity entity = new InputEntity();
                                entity.Id = PLUGIN_DATA_ID;
                                entity.Name = PLUGIN_DATA_NAME;
                                entity.Label = "Plugin Data";
                                entity.LabelPlural = "Plugin Data";
                                entity.System = true;
                                entity.IconName = "database";
                                entity.Weight = 99;
                                entity.RecordPermissions = new RecordPermissions();
                                entity.RecordPermissions.CanCreate = new List<Guid>();
                                entity.RecordPermissions.CanRead = new List<Guid>();
                                entity.RecordPermissions.CanUpdate = new List<Guid>();
                                entity.RecordPermissions.CanDelete = new List<Guid>();
                                //Create
                                entity.RecordPermissions.CanCreate.Add(SystemIds.AdministratorRoleId);
                                //READ
                                entity.RecordPermissions.CanRead.Add(SystemIds.AdministratorRoleId);
                                //UPDATE
                                entity.RecordPermissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                                //DELETE
                                entity.RecordPermissions.CanDelete.Add(SystemIds.AdministratorRoleId);

                                var systemItemIdDictionary = new Dictionary<string, Guid>();
                                systemItemIdDictionary["id"] = new Guid("bdb47d11-b8ee-42e9-8cd1-56e43246656b");
                                systemItemIdDictionary["created_on"] = new Guid("00f172b1-393b-4674-b6cd-32669dfb0924");
                                systemItemIdDictionary["created_by"] = new Guid("89379dbe-98ea-40b0-a794-a7cbf36201af");
                                systemItemIdDictionary["last_modified_on"] = new Guid("aaee0db8-d131-4273-b06a-a788757e24c3");
                                systemItemIdDictionary["last_modified_by"] = new Guid("eb0d2a71-4172-4293-87d7-d238a2153abf");
                                systemItemIdDictionary["user_plugin_data_created_by"] = new Guid("00e3f673-9dbc-4b57-b6d8-38d75e7d165a");
                                systemItemIdDictionary["user_plugin_data_modified_by"] = new Guid("c228125d-066c-415b-8c2a-a43ba2774411");
                                {
                                    var createResponse = entMan.CreateEntity(entity, false, false, systemItemIdDictionary);
                                    if (!createResponse.Success)
                                        throw new Exception("System error 10050. Entity: " + PLUGIN_DATA_NAME + " Field: entity creation" + " Message:" + response.Message);
                                }
                            }
                            #endregion

                            #region << name >>
                            {
                                InputTextField textboxField = new InputTextField();
                                textboxField.Id = new Guid("ab81aec7-da90-4ba8-8ac7-378faa01763f");
                                textboxField.Name = "name";
                                textboxField.Label = "Name";
                                textboxField.PlaceholderText = "";
                                textboxField.Description = "";
                                textboxField.HelpText = "";
                                textboxField.Required = true;
                                textboxField.Unique = true;
                                textboxField.Searchable = false;
                                textboxField.Auditable = false;
                                textboxField.System = true;
                                textboxField.DefaultValue = string.Empty;
                                textboxField.MaxLength = null;
                                textboxField.EnableSecurity = true;
                                textboxField.Permissions = new FieldPermissions();
                                textboxField.Permissions.CanRead = new List<Guid>();
                                textboxField.Permissions.CanUpdate = new List<Guid>();
                                //READ
                                textboxField.Permissions.CanRead.Add(SystemIds.AdministratorRoleId);
                                //UPDATE
                                textboxField.Permissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                                {
                                    var createResponse = entMan.CreateField(PLUGIN_DATA_ID, textboxField, false);
                                    if (!createResponse.Success)
                                        throw new Exception("System error 10060. Entity: " + PLUGIN_DATA_NAME + " Field: field_name" + " Message:" + response.Message);
                                }
                            }
                            #endregion

                            #region << data >>
                            {
                                InputTextField textboxField = new InputTextField();
                                textboxField.Id = new Guid("52a799ad-80a3-404b-99b5-1f58ce437982");
                                textboxField.Name = "data";
                                textboxField.Label = "Data";
                                textboxField.PlaceholderText = "";
                                textboxField.Description = "";
                                textboxField.HelpText = "";
                                textboxField.Required = false;
                                textboxField.Unique = false;
                                textboxField.Searchable = false;
                                textboxField.Auditable = false;
                                textboxField.System = true;
                                textboxField.DefaultValue = string.Empty;
                                textboxField.MaxLength = null;
                                textboxField.EnableSecurity = true;
                                textboxField.Permissions = new FieldPermissions();
                                textboxField.Permissions.CanRead = new List<Guid>();
                                textboxField.Permissions.CanUpdate = new List<Guid>();
                                //READ
                                textboxField.Permissions.CanRead.Add(SystemIds.AdministratorRoleId);
                                //UPDATE
                                textboxField.Permissions.CanUpdate.Add(SystemIds.AdministratorRoleId);
                                {
                                    var createResponse = entMan.CreateField(PLUGIN_DATA_ID, textboxField, false);
                                    if (!createResponse.Success)
                                        throw new Exception("System error 10060. Entity: " + PLUGIN_DATA_NAME + " Field: field_name" + " Message:" + response.Message);
                                }
                            }
                            #endregion

                        }
                        #endregion

                    }

                    new DbSystemSettingsRepository().Save(new DbSystemSettings { Id = systemSettings.Id, Version = systemSettings.Version });

                    connection.CommitTransaction();
                }
                catch (Exception ex)
                {
                    var exception = ex;
                    connection.RollbackTransaction();
                    throw;
                }

            }

            //recMan.ConvertNtoNRelations();
        }
Пример #2
0
        public void InitializeSystemEntities()
        {
            EntityResponse response = null;
            FieldResponse fieldResponse = null;
            EntityManager em = new EntityManager(StorageService);
            EntityRelationManager rm = new EntityRelationManager(StorageService);
            RecordManager recMan = new RecordManager(this);

            var transaction = recMan.CreateTransaction();

            try
            {

                transaction.Begin();

                IStorageSystemSettingsRepository systemSettingsRepository = StorageService.GetSystemSettingsRepository();
                IStorageSystemSettings storeSystemSettings = systemSettingsRepository.Read();

                Guid systemSettingsId = new Guid("F3223177-B2FF-43F5-9A4B-FF16FC67D186");
                SystemSettings systemSettings = new SystemSettings();
                systemSettings.Id = systemSettingsId;

                int currentVersion = 0;
                if (storeSystemSettings != null)
                {
                    systemSettings = new SystemSettings(storeSystemSettings);
                    currentVersion = systemSettings.Version;
                }

                EntityManager entityManager = new EntityManager(StorageService);

                //tmp code - during debug only
                //em.DeleteEntity(SystemIds.UserEntityId);
                //em.DeleteEntity(SystemIds.RoleEntityId);
                //rm.Delete(SystemIds.UserRoleRelationId);
                //currentVersion = 0;

                if (currentVersion < 150508)
                {
                    systemSettings.Version = 150508;

                    List<Guid> allowedRoles = new List<Guid>();
                    allowedRoles.Add(SystemIds.AdministratorRoleId);

                    #region << create role entity >>

                    {
                        InputEntity roleEntity = new InputEntity();
                        roleEntity.Id = SystemIds.RoleEntityId;
                        roleEntity.Name = "role";
                        roleEntity.Label = "Role";
                        roleEntity.LabelPlural = "Roles";
                        roleEntity.System = true;
                        roleEntity.RecordPermissions = new RecordPermissions();
                        roleEntity.RecordPermissions.CanRead = allowedRoles;
                        roleEntity.RecordPermissions.CanCreate = allowedRoles;
                        roleEntity.RecordPermissions.CanUpdate = allowedRoles;
                        roleEntity.RecordPermissions.CanDelete = allowedRoles;

                        response = entityManager.CreateEntity(roleEntity);

                        InputTextField nameRoleField = new InputTextField();

                        nameRoleField.Id = new Guid("36F91EBD-5A02-4032-8498-B7F716F6A349");
                        nameRoleField.Name = "name";
                        nameRoleField.Label = "Name";
                        nameRoleField.PlaceholderText = "";
                        nameRoleField.Description = "The name of the role";
                        nameRoleField.HelpText = "";
                        nameRoleField.Required = true;
                        nameRoleField.Unique = false;
                        nameRoleField.Searchable = false;
                        nameRoleField.Auditable = false;
                        nameRoleField.System = true;
                        nameRoleField.DefaultValue = "";

                        nameRoleField.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(roleEntity.Id.Value, nameRoleField, false);

                        InputTextField descriptionRoleField = new InputTextField();

                        descriptionRoleField.Id = new Guid("4A8B9E0A-1C36-40C6-972B-B19E2B5D265B");
                        descriptionRoleField.Name = "description";
                        descriptionRoleField.Label = "Description";
                        descriptionRoleField.PlaceholderText = "";
                        descriptionRoleField.Description = "";
                        descriptionRoleField.HelpText = "";
                        descriptionRoleField.Required = true;
                        descriptionRoleField.Unique = false;
                        descriptionRoleField.Searchable = false;
                        descriptionRoleField.Auditable = false;
                        descriptionRoleField.System = true;
                        descriptionRoleField.DefaultValue = "";

                        descriptionRoleField.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(roleEntity.Id.Value, descriptionRoleField, false);
                    }

                    #endregion

                    #region << create user entity >>
                    {

                        InputEntity userEntity = new InputEntity();
                        userEntity.Id = SystemIds.UserEntityId;
                        userEntity.Name = "user";
                        userEntity.Label = "User";
                        userEntity.LabelPlural = "Users";
                        userEntity.System = true;
                        userEntity.RecordPermissions = new RecordPermissions();
                        userEntity.RecordPermissions.CanRead = allowedRoles;
                        userEntity.RecordPermissions.CanCreate = allowedRoles;
                        userEntity.RecordPermissions.CanUpdate = allowedRoles;
                        userEntity.RecordPermissions.CanDelete = allowedRoles;

                        response = entityManager.CreateEntity(userEntity);

                        InputTextField firstName = new InputTextField();

                        firstName.Id = new Guid("DF211549-41CC-4D11-BB43-DACA4C164411");
                        firstName.Name = "first_name";
                        firstName.Label = "First Name";
                        firstName.PlaceholderText = "";
                        firstName.Description = "First name of the user";
                        firstName.HelpText = "";
                        firstName.Required = true;
                        firstName.Unique = false;
                        firstName.Searchable = false;
                        firstName.Auditable = false;
                        firstName.System = true;
                        firstName.DefaultValue = "";

                        firstName.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, firstName, false);

                        InputTextField lastName = new InputTextField();

                        lastName.Id = new Guid("63E685B1-B2C6-4961-B393-2B6723EBD1BF");
                        lastName.Name = "last_name";
                        lastName.Label = "Last Name";
                        lastName.PlaceholderText = "";
                        lastName.Description = "Last name of the user";
                        lastName.HelpText = "";
                        lastName.Required = true;
                        lastName.Unique = false;
                        lastName.Searchable = false;
                        lastName.Auditable = false;
                        lastName.System = true;
                        lastName.DefaultValue = "";

                        lastName.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, lastName, false);

                        InputEmailField email = new InputEmailField();

                        email.Id = new Guid("9FC75C8F-CE80-4A64-81D7-E2BEFA5E4815");
                        email.Name = "email";
                        email.Label = "Email";
                        email.PlaceholderText = "";
                        email.Description = "Email address of the user";
                        email.HelpText = "";
                        email.Required = true;
                        email.Unique = true;
                        email.Searchable = false;
                        email.Auditable = false;
                        email.System = true;
                        email.DefaultValue = "";

                        email.MaxLength = 255;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, email, false);

                        InputPasswordField password = new InputPasswordField();

                        password.Id = new Guid("4EDE88D9-217A-4462-9300-EA0D6AFCDCEA");
                        password.Name = "password";
                        password.Label = "Password";
                        password.PlaceholderText = "";
                        password.Description = "Password for the user account";
                        password.HelpText = "";
                        password.Required = true;
                        password.Unique = true;
                        password.Searchable = false;
                        password.Auditable = false;
                        password.System = true;
                        password.MinLength = 6;
                        password.MaxLength = 24;
                        password.Encrypted = true;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, password, false);

                        InputDateTimeField lastLoggedIn = new InputDateTimeField();

                        lastLoggedIn.Id = new Guid("3C85CCEC-D526-4E47-887F-EE169D1F508D");
                        lastLoggedIn.Name = "last_logged_in";
                        lastLoggedIn.Label = "Last Logged In";
                        lastLoggedIn.PlaceholderText = "";
                        lastLoggedIn.Description = "";
                        lastLoggedIn.HelpText = "";
                        lastLoggedIn.Required = false;
                        lastLoggedIn.Unique = true;
                        lastLoggedIn.Searchable = false;
                        lastLoggedIn.Auditable = true;
                        lastLoggedIn.System = true;
                        lastLoggedIn.DefaultValue = null;

                        lastLoggedIn.Format = "dd MMM yyyy HH:mm:ss";
                        lastLoggedIn.UseCurrentTimeAsDefaultValue = true;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, lastLoggedIn, false);

                        InputCheckboxField enabledField = new InputCheckboxField();

                        enabledField.Id = new Guid("C0C63650-7572-4252-8E4B-4E25C94897A6");
                        enabledField.Name = "enabled";
                        enabledField.Label = "Enabled";
                        enabledField.PlaceholderText = "";
                        enabledField.Description = "Shows if the user account is enabled";
                        enabledField.HelpText = "";
                        enabledField.Required = true;
                        enabledField.Unique = false;
                        enabledField.Searchable = false;
                        enabledField.Auditable = false;
                        enabledField.System = true;
                        enabledField.DefaultValue = false;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, enabledField, false);

                        InputCheckboxField verifiedUserField = new InputCheckboxField();

                        verifiedUserField.Id = new Guid("F1BA5069-8CC9-4E66-BCC3-60E33C79C265");
                        verifiedUserField.Name = "verified";
                        verifiedUserField.Label = "Verified";
                        verifiedUserField.PlaceholderText = "";
                        verifiedUserField.Description = "Shows if the user email is verified";
                        verifiedUserField.HelpText = "";
                        verifiedUserField.Required = true;
                        verifiedUserField.Unique = false;
                        verifiedUserField.Searchable = false;
                        verifiedUserField.Auditable = false;
                        verifiedUserField.System = true;
                        verifiedUserField.DefaultValue = false;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, verifiedUserField, false);

                    }

                    #endregion

                    #region << create user - role relation >>
                    {
                        var userEntity = em.ReadEntity(SystemIds.UserEntityId).Object;
                        var roleEntity = em.ReadEntity(SystemIds.RoleEntityId).Object;

                        EntityRelation userRoleRelation = new EntityRelation();
                        userRoleRelation.Id = SystemIds.UserRoleRelationId;
                        userRoleRelation.Name = "user_role";
                        userRoleRelation.Label = "User-Role";
                        userRoleRelation.System = true;
                        userRoleRelation.RelationType = EntityRelationType.ManyToMany;
                        userRoleRelation.TargetEntityId = userEntity.Id;
                        userRoleRelation.TargetFieldId = userEntity.Fields.Single(x => x.Name == "id").Id;
                        userRoleRelation.OriginEntityId = roleEntity.Id;
                        userRoleRelation.OriginFieldId = roleEntity.Fields.Single(x => x.Name == "id").Id;
                        {
                            var result = rm.Create(userRoleRelation);
                            if (!result.Success)
                                throw new Exception("CREATE USER-ROLE RELATION:" + result.Message);
                        }
                    }
                    #endregion

                    #region << create system records >>

                    {
                        EntityRecord user = new EntityRecord();
                        user["id"] = SystemIds.FirstUserId;
                        user["first_name"] = "WebVella";
                        user["last_name"] = "Erp";
                        user["password"] = "******";
                        user["email"] = "*****@*****.**";
                        user["created_by"] = SystemIds.FirstUserId;
                        user["last_modified_by"] = SystemIds.FirstUserId;
                        user["created_on"] = DateTime.UtcNow;
                        user["enabled"] = true;

                        QueryResponse result = recMan.CreateRecord("user", user);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST USER RECORD:" + result.Message);
                    }

                    {
                        EntityRecord adminRole = new EntityRecord();
                        adminRole["id"] = SystemIds.AdministratorRoleId;
                        adminRole["name"] = "Administrator";
                        adminRole["description"] = "";
                        adminRole["created_by"] = SystemIds.FirstUserId;
                        adminRole["last_modified_by"] = SystemIds.FirstUserId;
                        adminRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", adminRole);
                        if (!result.Success)
                            throw new Exception("CREATE ADMINITRATOR ROLE RECORD:" + result.Message);
                    }

                    {
                        EntityRecord regularRole = new EntityRecord();
                        regularRole["id"] = SystemIds.RegularRoleId;
                        regularRole["name"] = "Regular";
                        regularRole["description"] = "";
                        regularRole["created_by"] = SystemIds.FirstUserId;
                        regularRole["last_modified_by"] = SystemIds.FirstUserId;
                        regularRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", regularRole);
                        if (!result.Success)
                            throw new Exception("CREATE REGULAR ROLE RECORD:" + result.Message);
                    }

                    {
                        EntityRecord guestRole = new EntityRecord();
                        guestRole["id"] = SystemIds.GuestRoleId;
                        guestRole["name"] = "Guest";
                        guestRole["description"] = "";
                        guestRole["created_by"] = SystemIds.FirstUserId;
                        guestRole["last_modified_by"] = SystemIds.FirstUserId;
                        guestRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", guestRole);
                        if (!result.Success)
                            throw new Exception("CREATE GUEST ROLE RECORD:" + result.Message);
                    }

                    {
                        QueryResponse result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.AdministratorRoleId, SystemIds.FirstUserId);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST-USER <-> ADMINISTRATOR ROLE RELATION RECORD:" + result.Message);

                        result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.RegularRoleId, SystemIds.FirstUserId);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST-USER <-> REGULAR ROLE RELATION RECORD:" + result.Message);

                    }

                    #endregion

                    #region << create Area entity >>
                    {
                        InputEntity areaEntity = new InputEntity();
                        areaEntity.Id = SystemIds.AreaEntityId;
                        areaEntity.Name = "area";
                        areaEntity.Label = "Area";
                        areaEntity.LabelPlural = "areas";
                        areaEntity.System = true;
                        areaEntity.IconName = "folder";
                        areaEntity.Weight = 10;
                        areaEntity.RecordPermissions = new RecordPermissions();
                        areaEntity.RecordPermissions.CanRead = allowedRoles;
                        areaEntity.RecordPermissions.CanCreate = allowedRoles;
                        areaEntity.RecordPermissions.CanUpdate = allowedRoles;
                        areaEntity.RecordPermissions.CanDelete = allowedRoles;
                        {
                            var createResponse = entityManager.CreateEntity(areaEntity);
                            if (!createResponse.Success)
                                throw new Exception("System error 10330. Message:" + createResponse.Message);
                        }

                        InputTextField color = new InputTextField();
                        color.Id = new Guid("2B4AACD9-3C34-4C44-B3A3-8AFF1520CFF6");
                        color.Name = "color";
                        color.Label = "Color";
                        color.PlaceholderText = "";
                        color.Description = "";
                        color.HelpText = "";
                        color.Required = true;
                        color.Unique = false;
                        color.Searchable = false;
                        color.Auditable = false;
                        color.System = true;
                        color.DefaultValue = "teal";
                        color.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, color, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField label = new InputTextField();
                        label.Id = new Guid("F050E7A1-AFB7-4346-B57B-1F12B2BD5AE5");
                        label.Name = "label";
                        label.Label = "Label";
                        label.PlaceholderText = "";
                        label.Description = "";
                        label.HelpText = "";
                        label.Required = true;
                        label.Unique = false;
                        label.Searchable = false;
                        label.Auditable = false;
                        label.System = true;
                        label.DefaultValue = "Default";
                        label.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, label, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField iconName = new InputTextField();
                        iconName.Id = new Guid("5EA0C872-D219-4D94-9EFA-C5DA978D316B");
                        iconName.Name = "icon_name";
                        iconName.Label = "Icon Name";
                        iconName.PlaceholderText = "";
                        iconName.Description = "";
                        iconName.HelpText = "";
                        iconName.Required = true;
                        iconName.Unique = false;
                        iconName.Searchable = false;
                        iconName.Auditable = false;
                        iconName.System = true;
                        iconName.DefaultValue = "database";
                        iconName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, iconName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputNumberField weight = new InputNumberField();
                        weight.Id = new Guid("9B169431-6C31-4141-80EB-5844B8333E63");
                        weight.Name = "weight";
                        weight.Label = "Weight";
                        weight.PlaceholderText = "";
                        weight.Description = "";
                        weight.HelpText = "";
                        weight.Required = true;
                        weight.Unique = false;
                        weight.Searchable = false;
                        weight.Auditable = false;
                        weight.System = true;
                        weight.DefaultValue = 10;
                        weight.MinValue = 0;
                        weight.DecimalPlaces = 2;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, weight, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField subscriptions = new InputTextField();
                        subscriptions.Id = new Guid("288EA657-C12C-4AC1-B701-81D6F9F39363");
                        subscriptions.Name = "subscriptions";
                        subscriptions.Label = "Subscriptions JSON String";
                        subscriptions.PlaceholderText = "";
                        subscriptions.Description = "Stringified Array of subscription objects";
                        subscriptions.HelpText = "";
                        subscriptions.Required = false;
                        subscriptions.Unique = false;
                        subscriptions.Searchable = false;
                        subscriptions.Auditable = false;
                        subscriptions.System = true;
                        subscriptions.DefaultValue = null;
                        subscriptions.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, subscriptions, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField name = new InputTextField();
                        name.Id = new Guid("F297577B-073E-4D18-81F3-675C1AFB466D");
                        name.Name = "name";
                        name.Label = "Name";
                        name.PlaceholderText = "";
                        name.Description = "";
                        name.HelpText = "";
                        name.Required = true;
                        name.Unique = false;
                        name.Searchable = false;
                        name.Auditable = false;
                        name.System = true;
                        name.DefaultValue = "default";
                        name.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, name, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField roles = new InputTextField();
                        roles.Id = new Guid("8E486F76-D0C1-4D0E-8617-9EF868BF1C55");
                        roles.Name = "roles";
                        roles.Label = "Subscriptions JSON String";
                        roles.PlaceholderText = "";
                        roles.Description = "Stringified Array of roles that have access to this area";
                        roles.HelpText = "";
                        roles.Required = false;
                        roles.Unique = false;
                        roles.Searchable = false;
                        roles.Auditable = false;
                        roles.System = true;
                        roles.DefaultValue = null;
                        roles.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, roles, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                    }
                    #endregion
                }

                if (currentVersion < 150919)
                {
                    systemSettings.Version = 150919;
                    List<Guid> allowedRoles = new List<Guid>();
                    allowedRoles.Add(SystemIds.AdministratorRoleId);
                    Guid filterEntityId = new Guid("2a20e8b1-5713-4257-a860-b964a5cfb317");

                    #region << create filter >>
                    {
                        InputEntity filterEntity = new InputEntity();
                        filterEntity.Id = filterEntityId;
                        filterEntity.Name = "filter";
                        filterEntity.Label = "Filter";
                        filterEntity.LabelPlural = "Filters";
                        filterEntity.System = true;
                        filterEntity.IconName = "filter";
                        filterEntity.Weight = 100;
                        filterEntity.RecordPermissions = new RecordPermissions();
                        filterEntity.RecordPermissions.CanRead = allowedRoles;
                        filterEntity.RecordPermissions.CanCreate = allowedRoles;
                        filterEntity.RecordPermissions.CanUpdate = allowedRoles;
                        filterEntity.RecordPermissions.CanDelete = allowedRoles;
                        {
                            var createResponse = entityManager.CreateEntity(filterEntity);
                            if (!createResponse.Success)
                                throw new Exception("System error 10330. Message:" + createResponse.Message);
                        }

                        InputTextField filterId = new InputTextField();
                        filterId.Id = new Guid("597bd9f4-c534-4244-af88-b6970c6abb21");
                        filterId.Name = "filter_id";
                        filterId.Label = "Filter id";
                        filterId.PlaceholderText = "";
                        filterId.Description = "";
                        filterId.HelpText = "";
                        filterId.Required = true;
                        filterId.Unique = false;
                        filterId.Searchable = false;
                        filterId.Auditable = false;
                        filterId.System = true;
                        filterId.DefaultValue = "";
                        filterId.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, filterId, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField fieldName = new InputTextField();
                        fieldName.Id = new Guid("e4094c4d-0fd3-44ef-9cc0-190ea48f7bca");
                        fieldName.Name = "field_name";
                        fieldName.Label = "Field name";
                        fieldName.PlaceholderText = "";
                        fieldName.Description = "";
                        fieldName.HelpText = "";
                        fieldName.Required = true;
                        fieldName.Unique = false;
                        fieldName.Searchable = false;
                        fieldName.Auditable = false;
                        fieldName.System = true;
                        fieldName.DefaultValue = "";
                        fieldName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, fieldName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField relationName = new InputTextField();
                        relationName.Id = new Guid("2859082c-5356-4d13-8b7b-e8fe65417279");
                        relationName.Name = "relation_name";
                        relationName.Label = "Relation name";
                        relationName.PlaceholderText = "";
                        relationName.Description = "";
                        relationName.HelpText = "";
                        relationName.Required = true;
                        relationName.Unique = false;
                        relationName.Searchable = false;
                        relationName.Auditable = false;
                        relationName.System = true;
                        relationName.DefaultValue = "";
                        relationName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, relationName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField values = new InputTextField();
                        values.Id = new Guid("ff7511ae-0117-41c6-9a03-08e3c6568c39");
                        values.Name = "values";
                        values.Label = "Values";
                        values.PlaceholderText = "";
                        values.Description = "array of encoded strings";
                        values.HelpText = "";
                        values.Required = true;
                        values.Unique = false;
                        values.Searchable = false;
                        values.Auditable = false;
                        values.System = true;
                        values.DefaultValue = "";
                        values.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, values, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField helper = new InputTextField();
                        helper.Id = new Guid("9056b9fb-4a4a-456f-9c64-539eaf70b6b2");
                        helper.Name = "helper";
                        helper.Label = "Helper";
                        helper.PlaceholderText = "";
                        helper.Description = "stringified object that helps constructing the filter on the interface";
                        helper.HelpText = "";
                        helper.Required = true;
                        helper.Unique = false;
                        helper.Searchable = false;
                        helper.Auditable = false;
                        helper.System = true;
                        helper.DefaultValue = "";
                        helper.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, helper, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField entityName = new InputTextField();
                        entityName.Id = new Guid("22f58779-4c91-4278-8412-88e1a55784e1");
                        entityName.Name = "entity_name";
                        entityName.Label = "Entity Name";
                        entityName.PlaceholderText = "";
                        entityName.Description = "";
                        entityName.HelpText = "";
                        entityName.Required = true;
                        entityName.Unique = false;
                        entityName.Searchable = false;
                        entityName.Auditable = false;
                        entityName.System = true;
                        entityName.DefaultValue = "";
                        entityName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, entityName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField listName = new InputTextField();
                        listName.Id = new Guid("a2cb0965-fe51-42b0-a07d-765507da8865");
                        listName.Name = "list_name";
                        listName.Label = "List Name";
                        listName.PlaceholderText = "";
                        listName.Description = "";
                        listName.HelpText = "";
                        listName.Required = true;
                        listName.Unique = false;
                        listName.Searchable = false;
                        listName.Auditable = false;
                        listName.System = true;
                        listName.DefaultValue = "";
                        listName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(filterEntityId, listName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputDateTimeField lastUsedOn = new InputDateTimeField();

                        lastUsedOn.Id = new Guid("207cf27b-3595-41fd-b028-bcd47845ad25");
                        lastUsedOn.Name = "last_used_on";
                        lastUsedOn.Label = "Last used on";
                        lastUsedOn.PlaceholderText = "";
                        lastUsedOn.Description = "";
                        lastUsedOn.HelpText = "";
                        lastUsedOn.Required = true;
                        lastUsedOn.Unique = false;
                        lastUsedOn.Searchable = false;
                        lastUsedOn.Auditable = false;
                        lastUsedOn.System = true;
                        lastUsedOn.DefaultValue = null;
                        lastUsedOn.Format = "dd  MMM yyyy HH:mm:ss";
                        lastUsedOn.UseCurrentTimeAsDefaultValue = true;

                        {
                            var createResponse = entityManager.CreateField(filterEntityId, lastUsedOn, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        #region << match_type >>
                        InputSelectField matchType = new InputSelectField();
                        matchType.Id = new Guid("15416751-e66d-4b85-ae2f-974255f9c987");
                        matchType.Name = "match_type";
                        matchType.Label = "Match type";
                        matchType.PlaceholderText = "";
                        matchType.Description = "";
                        matchType.HelpText = "";
                        matchType.Required = true;
                        matchType.Unique = false;
                        matchType.Searchable = false;
                        matchType.Auditable = false;
                        matchType.System = true;
                        matchType.DefaultValue = "exact";
                        matchType.Options = null;
                        matchType.Options = new List<SelectFieldOption>
                            {
                                new SelectFieldOption(){ Key = "exact", Value = "Exact match" },
                                new SelectFieldOption(){ Key = "range", Value = "Range" },
                                new SelectFieldOption(){ Key = "period", Value = "Period" },
                                new SelectFieldOption(){ Key = "regex", Value = "Regex" }
                            };

                        {
                            var createResponse = entityManager.CreateField(filterEntityId, matchType, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10060. Entity: filter. Field: match_type" + " Message:" + createResponse.Message);
                        }
                        #endregion

                    }
                    #endregion

                }

                if (currentVersion < 150924)
                {
                    systemSettings.Version = 150924;
                    //User
                    #region << image >>
                    {
                        InputImageField imageField = new InputImageField();
                        imageField.Id = new Guid("bf199b74-4448-4f58-93f5-6b86d888843b");
                        imageField.Name = "image";
                        imageField.Label = "Image";
                        imageField.PlaceholderText = "";
                        imageField.Description = "";
                        imageField.HelpText = "";
                        imageField.Required = false;
                        imageField.Unique = false;
                        imageField.Searchable = false;
                        imageField.Auditable = false;
                        imageField.System = true;
                        imageField.DefaultValue = string.Empty;
                        imageField.EnableSecurity = false;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.UserEntityId, imageField, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10060. Entity: user. Field: image" + " Message:" + createResponse.Message);
                        }
                    }
                    #endregion
                }

                storeSystemSettings = systemSettingsRepository.Convert(systemSettings);
                systemSettingsRepository.Save(storeSystemSettings);

                //if (currentVersion == 150508) //update to 150510
                //{
                //    systemSettings.Version = 150510;

                //    storeSystemSettings = systemSettingsRepository.Convert(systemSettings);
                //    systemSettingsRepository.Save(storeSystemSettings);
                //}

                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
        }
Пример #3
0
        public IActionResult PatchField(string Id, string FieldId, [FromBody]JObject submitObj)
        {
            FieldResponse response = new FieldResponse();
            Entity entity = new Entity();
            InputField field = new InputGuidField();

            try
            {
                Guid entityId;
                if (!Guid.TryParse(Id, out entityId))
                {
                    response.Errors.Add(new ErrorModel("Id", Id, "id parameter is not valid Guid value"));
                    return DoBadRequestResponse(response, "Field was not updated!");
                }

                Guid fieldId;
                if (!Guid.TryParse(FieldId, out fieldId))
                {
                    response.Errors.Add(new ErrorModel("FieldId", FieldId, "FieldId parameter is not valid Guid value"));
                    return DoBadRequestResponse(response, "Field was not updated!");
                }

                DbEntity storageEntity = DbContext.Current.EntityRepository.Read(entityId);
                if (storageEntity == null)
                {
                    response.Errors.Add(new ErrorModel("Id", Id, "Entity with such Id does not exist!"));
                    return DoBadRequestResponse(response, "Field was not updated!");
                }
                entity = storageEntity.MapTo<Entity>();

                Field updatedField = entity.Fields.FirstOrDefault(f => f.Id == fieldId);
                if (updatedField == null)
                {
                    response.Errors.Add(new ErrorModel("FieldId", FieldId, "Field with such Id does not exist!"));
                    return DoBadRequestResponse(response, "Field was not updated!");
                }

                FieldType fieldType = FieldType.GuidField;

                var fieldTypeProp = submitObj.Properties().SingleOrDefault(k => k.Name.ToLower() == "fieldtype");
                if (fieldTypeProp != null)
                {
                    fieldType = (FieldType)Enum.ToObject(typeof(FieldType), fieldTypeProp.Value.ToObject<int>());
                }
                else
                {
                    response.Errors.Add(new ErrorModel("fieldType", null, "fieldType is required!"));
                    return DoBadRequestResponse(response, "Field was not updated!");
                }

                Type inputFieldType = InputField.GetFieldType(fieldType);
                foreach (var prop in submitObj.Properties())
                {
                    int count = inputFieldType.GetProperties().Where(n => n.Name.ToLower() == prop.Name.ToLower()).Count();
                    if (count < 1)
                        response.Errors.Add(new ErrorModel(prop.Name, prop.Value.ToString(), "Input object contains property that is not part of the object model."));
                }

                if (response.Errors.Count > 0)
                    return DoBadRequestResponse(response);

                InputField inputField = InputField.ConvertField(submitObj);

                foreach (var prop in submitObj.Properties())
                {
                    switch (fieldType)
                    {
                        case FieldType.AutoNumberField:
                            {
                                field = new InputAutoNumberField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputAutoNumberField)field).DefaultValue = ((InputAutoNumberField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "U")
                                    ((InputAutoNumberField)field).DisplayFormat = ((InputAutoNumberField)inputField).DisplayFormat;
                                if (prop.Name.ToLower() == "startingnumber")
                                    ((InputAutoNumberField)field).StartingNumber = ((InputAutoNumberField)inputField).StartingNumber;
                            }
                            break;
                        case FieldType.CheckboxField:
                            {
                                field = new InputCheckboxField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputCheckboxField)field).DefaultValue = ((InputCheckboxField)inputField).DefaultValue;
                            }
                            break;
                        case FieldType.CurrencyField:
                            {
                                field = new InputCurrencyField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputCurrencyField)field).DefaultValue = ((InputCurrencyField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "minvalue")
                                    ((InputCurrencyField)field).MinValue = ((InputCurrencyField)inputField).MinValue;
                                if (prop.Name.ToLower() == "maxvalue")
                                    ((InputCurrencyField)field).MaxValue = ((InputCurrencyField)inputField).MaxValue;
                                if (prop.Name.ToLower() == "currency")
                                    ((InputCurrencyField)field).Currency = ((InputCurrencyField)inputField).Currency;
                            }
                            break;
                        case FieldType.DateField:
                            {
                                field = new InputDateField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputDateField)field).DefaultValue = ((InputDateField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "format")
                                    ((InputDateField)field).Format = ((InputDateField)inputField).Format;
                                if (prop.Name.ToLower() == "usecurrenttimeasdefaultvalue")
                                    ((InputDateField)field).UseCurrentTimeAsDefaultValue = ((InputDateField)inputField).UseCurrentTimeAsDefaultValue;
                            }
                            break;
                        case FieldType.DateTimeField:
                            {
                                field = new InputDateTimeField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputDateTimeField)field).DefaultValue = ((InputDateTimeField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "format")
                                    ((InputDateTimeField)field).Format = ((InputDateTimeField)inputField).Format;
                                if (prop.Name.ToLower() == "usecurrenttimeasdefaultvalue")
                                    ((InputDateTimeField)field).UseCurrentTimeAsDefaultValue = ((InputDateTimeField)inputField).UseCurrentTimeAsDefaultValue;
                            }
                            break;
                        case FieldType.EmailField:
                            {
                                field = new InputEmailField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputEmailField)field).DefaultValue = ((InputEmailField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputEmailField)field).MaxLength = ((InputEmailField)inputField).MaxLength;
                            }
                            break;
                        case FieldType.FileField:
                            {
                                field = new InputFileField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputFileField)field).DefaultValue = ((InputFileField)inputField).DefaultValue;
                            }
                            break;
                        case FieldType.HtmlField:
                            {
                                field = new InputHtmlField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputHtmlField)field).DefaultValue = ((InputHtmlField)inputField).DefaultValue;
                            }
                            break;
                        case FieldType.ImageField:
                            {
                                field = new InputImageField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputImageField)field).DefaultValue = ((InputImageField)inputField).DefaultValue;
                            }
                            break;
                        case FieldType.MultiLineTextField:
                            {
                                field = new InputMultiLineTextField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputMultiLineTextField)field).DefaultValue = ((InputMultiLineTextField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputMultiLineTextField)field).MaxLength = ((InputMultiLineTextField)inputField).MaxLength;
                                if (prop.Name.ToLower() == "visiblelinenumber")
                                    ((InputMultiLineTextField)field).VisibleLineNumber = ((InputMultiLineTextField)inputField).VisibleLineNumber;
                            }
                            break;
                        case FieldType.MultiSelectField:
                            {
                                field = new InputMultiSelectField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputMultiSelectField)field).DefaultValue = ((InputMultiSelectField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "options")
                                    ((InputMultiSelectField)field).Options = ((InputMultiSelectField)inputField).Options;
                            }
                            break;
                        case FieldType.NumberField:
                            {
                                field = new InputNumberField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputNumberField)field).DefaultValue = ((InputNumberField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "minvalue")
                                    ((InputNumberField)field).MinValue = ((InputNumberField)inputField).MinValue;
                                if (prop.Name.ToLower() == "maxvalue")
                                    ((InputNumberField)field).MaxValue = ((InputNumberField)inputField).MaxValue;
                                if (prop.Name.ToLower() == "decimalplaces")
                                    ((InputNumberField)field).DecimalPlaces = ((InputNumberField)inputField).DecimalPlaces;
                            }
                            break;
                        case FieldType.PasswordField:
                            {
                                field = new InputPasswordField();
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputPasswordField)field).MaxLength = ((InputPasswordField)inputField).MaxLength;
                                if (prop.Name.ToLower() == "minlength")
                                    ((InputPasswordField)field).MinLength = ((InputPasswordField)inputField).MinLength;
                                if (prop.Name.ToLower() == "encrypted")
                                    ((InputPasswordField)field).Encrypted = ((InputPasswordField)inputField).Encrypted;
                            }
                            break;
                        case FieldType.PercentField:
                            {
                                field = new InputPercentField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputPercentField)field).DefaultValue = ((InputPercentField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "minvalue")
                                    ((InputPercentField)field).MinValue = ((InputPercentField)inputField).MinValue;
                                if (prop.Name.ToLower() == "maxvalue")
                                    ((InputPercentField)field).MaxValue = ((InputPercentField)inputField).MaxValue;
                                if (prop.Name.ToLower() == "decimalplaces")
                                    ((InputPercentField)field).DecimalPlaces = ((InputPercentField)inputField).DecimalPlaces;
                            }
                            break;
                        case FieldType.PhoneField:
                            {
                                field = new InputPhoneField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputPhoneField)field).DefaultValue = ((InputPhoneField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "format")
                                    ((InputPhoneField)field).Format = ((InputPhoneField)inputField).Format;
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputPhoneField)field).MaxLength = ((InputPhoneField)inputField).MaxLength;
                            }
                            break;
                        case FieldType.GuidField:
                            {
                                field = new InputGuidField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputGuidField)field).DefaultValue = ((InputGuidField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "generatenewid")
                                    ((InputGuidField)field).GenerateNewId = ((InputGuidField)inputField).GenerateNewId;
                            }
                            break;
                        case FieldType.SelectField:
                            {
                                field = new InputSelectField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputSelectField)field).DefaultValue = ((InputSelectField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "options")
                                    ((InputSelectField)field).Options = ((InputSelectField)inputField).Options;
                            }
                            break;
                        case FieldType.TextField:
                            {
                                field = new InputTextField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputTextField)field).DefaultValue = ((InputTextField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputTextField)field).MaxLength = ((InputTextField)inputField).MaxLength;
                            }
                            break;
                        case FieldType.UrlField:
                            {
                                field = new InputUrlField();
                                if (prop.Name.ToLower() == "defaultvalue")
                                    ((InputUrlField)field).DefaultValue = ((InputUrlField)inputField).DefaultValue;
                                if (prop.Name.ToLower() == "maxlength")
                                    ((InputUrlField)field).MaxLength = ((InputUrlField)inputField).MaxLength;
                                if (prop.Name.ToLower() == "opentargetinnewwindow")
                                    ((InputUrlField)field).OpenTargetInNewWindow = ((InputUrlField)inputField).OpenTargetInNewWindow;
                            }
                            break;
                    }

                    if (prop.Name.ToLower() == "label")
                        field.Label = inputField.Label;
                    else if (prop.Name.ToLower() == "placeholdertext")
                        field.PlaceholderText = inputField.PlaceholderText;
                    else if (prop.Name.ToLower() == "description")
                        field.Description = inputField.Description;
                    else if (prop.Name.ToLower() == "helptext")
                        field.HelpText = inputField.HelpText;
                    else if (prop.Name.ToLower() == "required")
                        field.Required = inputField.Required;
                    else if (prop.Name.ToLower() == "unique")
                        field.Unique = inputField.Unique;
                    else if (prop.Name.ToLower() == "searchable")
                        field.Searchable = inputField.Searchable;
                    else if (prop.Name.ToLower() == "auditable")
                        field.Auditable = inputField.Auditable;
                    else if (prop.Name.ToLower() == "system")
                        field.System = inputField.System;
                }
            }
            catch (Exception e)
            {
                return DoBadRequestResponse(response, "Input object is not in valid format! It cannot be converted.", e);
            }

            return DoResponse(entMan.UpdateField(entity, field));
        }
Пример #4
0
        public void InitializeSystemEntities()
        {
            EntityResponse response = null;
            FieldResponse fieldResponse = null;
            EntityManager em = new EntityManager(StorageService);
            EntityRelationManager rm = new EntityRelationManager(StorageService);
            RecordManager recMan = new RecordManager(this);

            var transaction = recMan.CreateTransaction();

            try {

                transaction.Begin();

                IStorageSystemSettingsRepository systemSettingsRepository = StorageService.GetSystemSettingsRepository();
                IStorageSystemSettings storeSystemSettings = systemSettingsRepository.Read();

                Guid systemSettingsId = new Guid("F3223177-B2FF-43F5-9A4B-FF16FC67D186");
                SystemSettings systemSettings = new SystemSettings();
                systemSettings.Id = systemSettingsId;

                int currentVersion = 0;
                if (storeSystemSettings != null)
                {
                    systemSettings = new SystemSettings(storeSystemSettings);
                    currentVersion = systemSettings.Version;
                }

                EntityManager entityManager = new EntityManager(StorageService);

                //tmp code - during debug only
                //em.DeleteEntity(SystemIds.UserEntityId);
                //em.DeleteEntity(SystemIds.RoleEntityId);
                //rm.Delete(SystemIds.UserRoleRelationId);
                //currentVersion = 0;

                if (currentVersion < 150508)
                {
                    systemSettings.Version = 150508;

                    List<Guid> allowedRoles = new List<Guid>();
                    allowedRoles.Add(new Guid("F42EBA3B-6433-752B-6C34-B322A7B4CE7D"));

                    #region << create role entity >>

                    {
                        InputEntity roleEntity = new InputEntity();
                        roleEntity.Id = SystemIds.RoleEntityId;
                        roleEntity.Name = "role";
                        roleEntity.Label = "Role";
                        roleEntity.LabelPlural = "Roles";
                        roleEntity.System = true;
                        roleEntity.RecordPermissions = new RecordPermissions();
                        roleEntity.RecordPermissions.CanRead = allowedRoles;
                        roleEntity.RecordPermissions.CanCreate = allowedRoles;
                        roleEntity.RecordPermissions.CanUpdate = allowedRoles;
                        roleEntity.RecordPermissions.CanDelete = allowedRoles;

                        response = entityManager.CreateEntity(roleEntity);

                        InputTextField nameRoleField = new InputTextField();

                        nameRoleField.Id = new Guid("36F91EBD-5A02-4032-8498-B7F716F6A349");
                        nameRoleField.Name = "name";
                        nameRoleField.Label = "Name";
                        nameRoleField.PlaceholderText = "";
                        nameRoleField.Description = "The name of the role";
                        nameRoleField.HelpText = "";
                        nameRoleField.Required = true;
                        nameRoleField.Unique = false;
                        nameRoleField.Searchable = false;
                        nameRoleField.Auditable = false;
                        nameRoleField.System = true;
                        nameRoleField.DefaultValue = "";

                        nameRoleField.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(roleEntity.Id.Value, nameRoleField,false);

                        InputTextField descriptionRoleField = new InputTextField();

                        descriptionRoleField.Id = new Guid("4A8B9E0A-1C36-40C6-972B-B19E2B5D265B");
                        descriptionRoleField.Name = "description";
                        descriptionRoleField.Label = "Description";
                        descriptionRoleField.PlaceholderText = "";
                        descriptionRoleField.Description = "";
                        descriptionRoleField.HelpText = "";
                        descriptionRoleField.Required = true;
                        descriptionRoleField.Unique = false;
                        descriptionRoleField.Searchable = false;
                        descriptionRoleField.Auditable = false;
                        descriptionRoleField.System = true;
                        descriptionRoleField.DefaultValue = "";

                        descriptionRoleField.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(roleEntity.Id.Value, descriptionRoleField,false);
                    }

                    #endregion

                    #region << create user entity >>
                    {

                        InputEntity userEntity = new InputEntity();
                        userEntity.Id = SystemIds.UserEntityId;
                        userEntity.Name = "user";
                        userEntity.Label = "User";
                        userEntity.LabelPlural = "Users";
                        userEntity.System = true;
                        userEntity.RecordPermissions = new RecordPermissions();
                        userEntity.RecordPermissions.CanRead = allowedRoles;
                        userEntity.RecordPermissions.CanCreate = allowedRoles;
                        userEntity.RecordPermissions.CanUpdate = allowedRoles;
                        userEntity.RecordPermissions.CanDelete = allowedRoles;

                        response = entityManager.CreateEntity(userEntity);

                        InputTextField firstName = new InputTextField();

                        firstName.Id = new Guid("DF211549-41CC-4D11-BB43-DACA4C164411");
                        firstName.Name = "first_name";
                        firstName.Label = "First Name";
                        firstName.PlaceholderText = "";
                        firstName.Description = "First name of the user";
                        firstName.HelpText = "";
                        firstName.Required = true;
                        firstName.Unique = false;
                        firstName.Searchable = false;
                        firstName.Auditable = false;
                        firstName.System = true;
                        firstName.DefaultValue = "";

                        firstName.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, firstName,false);

                        InputTextField lastName = new InputTextField();

                        lastName.Id = new Guid("63E685B1-B2C6-4961-B393-2B6723EBD1BF");
                        lastName.Name = "last_name";
                        lastName.Label = "Last Name";
                        lastName.PlaceholderText = "";
                        lastName.Description = "Last name of the user";
                        lastName.HelpText = "";
                        lastName.Required = true;
                        lastName.Unique = false;
                        lastName.Searchable = false;
                        lastName.Auditable = false;
                        lastName.System = true;
                        lastName.DefaultValue = "";

                        lastName.MaxLength = 200;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, lastName,false);

                        InputEmailField email = new InputEmailField();

                        email.Id = new Guid("9FC75C8F-CE80-4A64-81D7-E2BEFA5E4815");
                        email.Name = "email";
                        email.Label = "Email";
                        email.PlaceholderText = "";
                        email.Description = "Email address of the user";
                        email.HelpText = "";
                        email.Required = true;
                        email.Unique = true;
                        email.Searchable = false;
                        email.Auditable = false;
                        email.System = true;
                        email.DefaultValue = "";

                        email.MaxLength = 255;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, email,false);

                        InputPasswordField password = new InputPasswordField();

                        password.Id = new Guid("4EDE88D9-217A-4462-9300-EA0D6AFCDCEA");
                        password.Name = "password";
                        password.Label = "Password";
                        password.PlaceholderText = "";
                        password.Description = "Password for the user account";
                        password.HelpText = "";
                        password.Required = true;
                        password.Unique = true;
                        password.Searchable = false;
                        password.Auditable = false;
                        password.System = true;
                        password.MinLength = 6;
                        password.MaxLength = 24;
                        password.Encrypted = true;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, password, false);

                        InputDateTimeField lastLoggedIn = new InputDateTimeField();

                        lastLoggedIn.Id = new Guid("3C85CCEC-D526-4E47-887F-EE169D1F508D");
                        lastLoggedIn.Name = "last_logged_in";
                        lastLoggedIn.Label = "Last Logged In";
                        lastLoggedIn.PlaceholderText = "";
                        lastLoggedIn.Description = "";
                        lastLoggedIn.HelpText = "";
                        lastLoggedIn.Required = false;
                        lastLoggedIn.Unique = true;
                        lastLoggedIn.Searchable = false;
                        lastLoggedIn.Auditable = true;
                        lastLoggedIn.System = true;
                        lastLoggedIn.DefaultValue = null;

                        lastLoggedIn.Format = "MM/dd/YYYY";
                        lastLoggedIn.UseCurrentTimeAsDefaultValue = true;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, lastLoggedIn, false);

                        InputCheckboxField enabledField = new InputCheckboxField();

                        enabledField.Id = new Guid("C0C63650-7572-4252-8E4B-4E25C94897A6");
                        enabledField.Name = "enabled";
                        enabledField.Label = "Enabled";
                        enabledField.PlaceholderText = "";
                        enabledField.Description = "Shows if the user account is enabled";
                        enabledField.HelpText = "";
                        enabledField.Required = true;
                        enabledField.Unique = false;
                        enabledField.Searchable = false;
                        enabledField.Auditable = false;
                        enabledField.System = true;
                        enabledField.DefaultValue = false;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, enabledField,false);

                        InputCheckboxField verifiedUserField = new InputCheckboxField();

                        verifiedUserField.Id = new Guid("F1BA5069-8CC9-4E66-BCC3-60E33C79C265");
                        verifiedUserField.Name = "verified";
                        verifiedUserField.Label = "Verified";
                        verifiedUserField.PlaceholderText = "";
                        verifiedUserField.Description = "Shows if the user email is verified";
                        verifiedUserField.HelpText = "";
                        verifiedUserField.Required = true;
                        verifiedUserField.Unique = false;
                        verifiedUserField.Searchable = false;
                        verifiedUserField.Auditable = false;
                        verifiedUserField.System = true;
                        verifiedUserField.DefaultValue = false;

                        fieldResponse = entityManager.CreateField(userEntity.Id.Value, verifiedUserField, false);
                    }

                    #endregion

                    #region << create user - role relation >>
                    {
                        var userEntity = em.ReadEntity(SystemIds.UserEntityId).Object;
                        var roleEntity = em.ReadEntity(SystemIds.RoleEntityId).Object;

                        EntityRelation userRoleRelation = new EntityRelation();
                        userRoleRelation.Id = SystemIds.UserRoleRelationId; ;
                        userRoleRelation.Name = "user_role";
                        userRoleRelation.Label = "User-Role";
                        userRoleRelation.System = true;
                        userRoleRelation.RelationType = EntityRelationType.ManyToMany;
                        userRoleRelation.TargetEntityId = userEntity.Id;
                        userRoleRelation.TargetFieldId = userEntity.Fields.Single(x => x.Name == "id").Id;
                        userRoleRelation.OriginEntityId = roleEntity.Id;
                        userRoleRelation.OriginFieldId = roleEntity.Fields.Single(x => x.Name == "id").Id;
                        {
                            var result = rm.Create(userRoleRelation);
                            if (!result.Success)
                                throw new Exception("CREATE USER-ROLE RELATION:" + result.Message);
                        }
                    }
                    #endregion

                    #region << create system records >>

                    {
                        EntityRecord user = new EntityRecord();
                        user["id"] = SystemIds.FirstUserId;
                        user["first_name"] = "WebVella";
                        user["last_name"] = "Erp";
                        user["password"] = "******";
                        user["email"] = "*****@*****.**";
                        user["created_by"] = SystemIds.FirstUserId;
                        user["last_modified_by"] = SystemIds.FirstUserId;
                        user["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("user", user);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST USER RECORD:" + result.Message);
                    }

                    {
                        EntityRecord adminRole = new EntityRecord();
                        adminRole["id"] = SystemIds.AdministratorRoleId;
                        adminRole["name"] = "Administrator";
                        adminRole["description"] = "";
                        adminRole["created_by"] = SystemIds.FirstUserId;
                        adminRole["last_modified_by"] = SystemIds.FirstUserId;
                        adminRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", adminRole);
                        if (!result.Success)
                            throw new Exception("CREATE ADMINITRATOR ROLE RECORD:" + result.Message);
                    }

                    {
                        EntityRecord regularRole = new EntityRecord();
                        regularRole["id"] = SystemIds.RegularRoleId;
                        regularRole["name"] = "Regular";
                        regularRole["description"] = "";
                        regularRole["created_by"] = SystemIds.FirstUserId;
                        regularRole["last_modified_by"] = SystemIds.FirstUserId;
                        regularRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", regularRole);
                        if (!result.Success)
                            throw new Exception("CREATE REGULAR ROLE RECORD:" + result.Message);
                    }

                    {
                        EntityRecord guestRole = new EntityRecord();
                        guestRole["id"] = SystemIds.GuestRoleId;
                        guestRole["name"] = "Guest";
                        guestRole["description"] = "";
                        guestRole["created_by"] = SystemIds.FirstUserId;
                        guestRole["last_modified_by"] = SystemIds.FirstUserId;
                        guestRole["created_on"] = DateTime.UtcNow;

                        QueryResponse result = recMan.CreateRecord("role", guestRole);
                        if (!result.Success)
                            throw new Exception("CREATE GUEST ROLE RECORD:" + result.Message);
                    }

                    {
                        QueryResponse result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.FirstUserId, SystemIds.AdministratorRoleId);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST-USER <-> ADMINISTRATOR ROLE RELATION RECORD:" + result.Message);

                        result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.FirstUserId, SystemIds.RegularRoleId);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST-USER <-> REGULAR ROLE RELATION RECORD:" + result.Message);

                        result = recMan.CreateRelationManyToManyRecord(SystemIds.UserRoleRelationId, SystemIds.FirstUserId, SystemIds.GuestRoleId);
                        if (!result.Success)
                            throw new Exception("CREATE FIRST-USER <-> GUEST ROLE RELATION RECORD:" + result.Message);
                    }

                    #endregion

                    #region << create Area entity >>
                    {
                        InputEntity areaEntity = new InputEntity();
                        areaEntity.Id = SystemIds.AreaEntityId;
                        areaEntity.Name = "area";
                        areaEntity.Label = "Area";
                        areaEntity.LabelPlural = "areas";
                        areaEntity.System = true;
                        areaEntity.IconName = "folder";
                        areaEntity.Weight = 10;
                        areaEntity.RecordPermissions = new RecordPermissions();
                        areaEntity.RecordPermissions.CanRead = allowedRoles;
                        areaEntity.RecordPermissions.CanCreate = allowedRoles;
                        areaEntity.RecordPermissions.CanUpdate = allowedRoles;
                        areaEntity.RecordPermissions.CanDelete = allowedRoles;
                        {
                            var createResponse = entityManager.CreateEntity(areaEntity);
                            if (!createResponse.Success)
                                throw new Exception("System error 10330. Message:" + createResponse.Message);
                        }

                        InputTextField color = new InputTextField();
                        color.Id = new Guid("2B4AACD9-3C34-4C44-B3A3-8AFF1520CFF6");
                        color.Name = "color";
                        color.Label = "Color";
                        color.PlaceholderText = "";
                        color.Description = "";
                        color.HelpText = "";
                        color.Required = true;
                        color.Unique = false;
                        color.Searchable = false;
                        color.Auditable = false;
                        color.System = true;
                        color.DefaultValue = "teal";
                        color.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, color, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField label = new InputTextField();
                        label.Id = new Guid("F050E7A1-AFB7-4346-B57B-1F12B2BD5AE5");
                        label.Name = "label";
                        label.Label = "Label";
                        label.PlaceholderText = "";
                        label.Description = "";
                        label.HelpText = "";
                        label.Required = true;
                        label.Unique = false;
                        label.Searchable = false;
                        label.Auditable = false;
                        label.System = true;
                        label.DefaultValue = "Default";
                        label.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, label, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField iconName = new InputTextField();
                        iconName.Id = new Guid("5EA0C872-D219-4D94-9EFA-C5DA978D316B");
                        iconName.Name = "icon_name";
                        iconName.Label = "Icon Name";
                        iconName.PlaceholderText = "";
                        iconName.Description = "";
                        iconName.HelpText = "";
                        iconName.Required = true;
                        iconName.Unique = false;
                        iconName.Searchable = false;
                        iconName.Auditable = false;
                        iconName.System = true;
                        iconName.DefaultValue = "database";
                        iconName.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, iconName, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputNumberField weight = new InputNumberField();
                        weight.Id = new Guid("9B169431-6C31-4141-80EB-5844B8333E63");
                        weight.Name = "weight";
                        weight.Label = "Weight";
                        weight.PlaceholderText = "";
                        weight.Description = "";
                        weight.HelpText = "";
                        weight.Required = true;
                        weight.Unique = false;
                        weight.Searchable = false;
                        weight.Auditable = false;
                        weight.System = true;
                        weight.DefaultValue = 10;
                        weight.MinValue = 0;
                        weight.DecimalPlaces = 2;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, weight, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField subscriptions = new InputTextField();
                        subscriptions.Id = new Guid("288EA657-C12C-4AC1-B701-81D6F9F39363");
                        subscriptions.Name = "subscriptions";
                        subscriptions.Label = "Subscriptions JSON String";
                        subscriptions.PlaceholderText = "";
                        subscriptions.Description = "Stringified Array of subscription objects";
                        subscriptions.HelpText = "";
                        subscriptions.Required = false;
                        subscriptions.Unique = false;
                        subscriptions.Searchable = false;
                        subscriptions.Auditable = false;
                        subscriptions.System = true;
                        subscriptions.DefaultValue = null;
                        subscriptions.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, subscriptions, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField name = new InputTextField();
                        name.Id = new Guid("F297577B-073E-4D18-81F3-675C1AFB466D");
                        name.Name = "name";
                        name.Label = "Name";
                        name.PlaceholderText = "";
                        name.Description = "";
                        name.HelpText = "";
                        name.Required = true;
                        name.Unique = false;
                        name.Searchable = false;
                        name.Auditable = false;
                        name.System = true;
                        name.DefaultValue = "default";
                        name.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, name, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                        InputTextField roles = new InputTextField();
                        roles.Id = new Guid("8E486F76-D0C1-4D0E-8617-9EF868BF1C55");
                        roles.Name = "roles";
                        roles.Label = "Subscriptions JSON String";
                        roles.PlaceholderText = "";
                        roles.Description = "Stringified Array of roles that have access to this area";
                        roles.HelpText = "";
                        roles.Required = false;
                        roles.Unique = false;
                        roles.Searchable = false;
                        roles.Auditable = false;
                        roles.System = true;
                        roles.DefaultValue = null;
                        roles.MaxLength = null;
                        {
                            var createResponse = entityManager.CreateField(SystemIds.AreaEntityId, roles, false);
                            if (!createResponse.Success)
                                throw new Exception("System error 10340. Message:" + createResponse.Message);
                        }

                    }
                    #endregion
                }

                storeSystemSettings = systemSettingsRepository.Convert(systemSettings);
                systemSettingsRepository.Save(storeSystemSettings);

                //if (currentVersion == 150508) //update to 150510
                //{
                //    systemSettings.Version = 150510;

                //    storeSystemSettings = systemSettingsRepository.Convert(systemSettings);
                //    systemSettingsRepository.Save(storeSystemSettings);
                //}

                transaction.Commit();
            }
            catch( Exception )
            {
                transaction.Rollback();
                throw;
            }
        }