Exemplo n.º 1
0
        public async Task <Project> AddProject(string projectName, User creator)
        {
            var project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = false,
                CreatedDate       = DateTime.UtcNow,
                ProjectName       = Required(projectName),
                CharacterGroups   = new List <CharacterGroup>()
                {
                    new CharacterGroup()
                    {
                        IsPublic                = true,
                        IsRoot                  = true,
                        CharacterGroupName      = "Все роли",
                        IsActive                = true,
                        ResponsibleMasterUserId = creator.UserId,
                        HaveDirectSlots         = true,
                        AvaiableDirectSlots     = -1
                    }
                },
                ProjectAcls = new List <ProjectAcl>()
                {
                    ProjectAcl.CreateRootAcl(creator.UserId)
                }
            };

            project.MarkTreeModified();
            UnitOfWork.GetDbSet <Project>().Add(project);
            await UnitOfWork.SaveChangesAsync();

            return(project);
        }
Exemplo n.º 2
0
        public async Task <Project> AddProject(CreateProjectRequest request)
        {
            var rootGroup = new CharacterGroup()
            {
                IsPublic = true,
                IsRoot   = true,
                //TODO[Localize]
                CharacterGroupName      = "Все роли",
                IsActive                = true,
                ResponsibleMasterUserId = CurrentUserId,
                HaveDirectSlots         = true,
                AvaiableDirectSlots     = -1,
            };

            MarkCreatedNow(rootGroup);
            var project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = false,
                CreatedDate       = Now,
                ProjectName       = Required(request.ProjectName),
                CharacterGroups   = new List <CharacterGroup>()
                {
                    rootGroup,
                },
                ProjectAcls = new List <ProjectAcl>()
                {
                    ProjectAcl.CreateRootAcl(CurrentUserId, isOwner: true),
                },
                Details = new ProjectDetails(),
            };

            MarkTreeModified(project);
            switch (request.ProjectType)
            {
            case ProjectTypeDto.Larp:
                break;

            case ProjectTypeDto.Convention:
                project.Details.AutoAcceptClaims    = true;
                project.Details.EnableAccommodation = true;
                project.Details.GenerateCharacterNamesFromPlayer = true;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            UnitOfWork.GetDbSet <Project>().Add(project);
            await UnitOfWork.SaveChangesAsync();

            return(project);
        }
Exemplo n.º 3
0
        public async Task GrantAccessAsAdmin(int projectId)
        {
            var project = await ProjectRepository.GetProjectAsync(projectId);

            var acl = project.ProjectAcls.SingleOrDefault(a => a.UserId == CurrentUserId);

            if (acl == null)
            {
                project.ProjectAcls.Add(ProjectAcl.CreateRootAcl(CurrentUserId));
            }

            await UnitOfWork.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <Project> AddProject(CreateProjectRequest request)
        {
            var rootGroup = new CharacterGroup()
            {
                IsPublic = true,
                IsRoot   = true,
                //TODO[Localize]
                CharacterGroupName      = "Все роли",
                IsActive                = true,
                ResponsibleMasterUserId = CurrentUserId,
                HaveDirectSlots         = true,
                AvaiableDirectSlots     = -1,
            };

            MarkCreatedNow(rootGroup);
            var project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = false,
                CreatedDate       = Now,
                ProjectName       = Required(request.ProjectName),
                CharacterGroups   = new List <CharacterGroup>()
                {
                    rootGroup,
                },
                ProjectAcls = new List <ProjectAcl>()
                {
                    ProjectAcl.CreateRootAcl(CurrentUserId, isOwner: true),
                },
                Details = new ProjectDetails()
                {
                    CharacterNameLegacyMode = false,
                },
                ProjectFields = new List <ProjectField>(),
            };

            MarkTreeModified(project);
            ConfigureProjectDefaults(project, request.ProjectType);

            UnitOfWork.GetDbSet <Project>().Add(project);
            await UnitOfWork.SaveChangesAsync();

            return(project);
        }
Exemplo n.º 5
0
        public async Task <Project> AddProject(string projectName, User creator)
        {
            var rootGroup = new CharacterGroup()
            {
                IsPublic = true,
                IsRoot   = true,
                //TODO[Localize]
                CharacterGroupName      = "Все роли",
                IsActive                = true,
                ResponsibleMasterUserId = creator.UserId,
                HaveDirectSlots         = true,
                AvaiableDirectSlots     = -1,
            };

            MarkCreatedNow(rootGroup);
            var project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = false,
                CreatedDate       = Now,
                ProjectName       = Required(projectName),
                CharacterGroups   = new List <CharacterGroup>()
                {
                    rootGroup
                },
                ProjectAcls = new List <ProjectAcl>()
                {
                    ProjectAcl.CreateRootAcl(creator.UserId)
                },
                Details = new ProjectDetails()
            };

            MarkTreeModified(project);
            UnitOfWork.GetDbSet <Project>().Add(project);
            await UnitOfWork.SaveChangesAsync();

            return(project);
        }
Exemplo n.º 6
0
        public MockedProject()
        {
            MasterOnlyField = new ProjectField()
            {
                CanPlayerEdit          = false,
                CanPlayerView          = false,
                IsActive               = true,
                ShowOnUnApprovedClaims = true
            };
            CharacterField = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                ShowOnUnApprovedClaims        = true,
                AvailableForCharacterGroupIds = new int[0]
            };
            ConditionalField = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                ShowOnUnApprovedClaims        = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                AvailableForCharacterGroupIds = new int[0]
            };

            HideForUnApprovedClaim = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                ShowOnUnApprovedClaims        = false,
                AvailableForCharacterGroupIds = new int[0]
            };

            PublicField = new ProjectField()
            {
                CanPlayerEdit = false,
                CanPlayerView = true,
                IsPublic      = true,
                IsActive      = true,
                FieldBoundTo  = FieldBoundTo.Character,
                AvailableForCharacterGroupIds = new int[0],
                ShowOnUnApprovedClaims        = true,
            };

            ConditionalHeader = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                ShowOnUnApprovedClaims        = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                AvailableForCharacterGroupIds = new int[0],
                FieldType                     = ProjectFieldType.Header
            };

            var characterFieldValue = new FieldWithValue(CharacterField, "Value");
            var publicFieldValue    = new FieldWithValue(PublicField, "Public");

            Character = new Character
            {
                IsActive                = true,
                IsAcceptingClaims       = true,
                ParentCharacterGroupIds = new int[0]
            };

            CharacterWithoutGroup = new Character
            {
                IsActive                = true,
                IsAcceptingClaims       = true,
                ParentCharacterGroupIds = new int[0]
            };


            Group = new CharacterGroup()
            {
                AvaiableDirectSlots = 0,
                HaveDirectSlots     = true
            };

            Project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = true,
                ProjectAcls       = new List <ProjectAcl>
                {
                    ProjectAcl.CreateRootAcl(Master.UserId)
                },
                ProjectFields = new List <ProjectField>()
                {
                    MasterOnlyField, CharacterField, ConditionalField, HideForUnApprovedClaim, PublicField, ConditionalHeader
                },
                Characters = new List <Character>()
                {
                    Character, CharacterWithoutGroup
                },
                CharacterGroups = new List <CharacterGroup> {
                    Group
                },
                Claims = new List <Claim>()
            };

            FixProjectSubEntities(Project);
            //That needs to happen after FixProjectSubEntities(..)
            Character.JsonData = new[] { characterFieldValue, publicFieldValue }.SerializeFields();

            Character.ParentCharacterGroupIds = new[] { Group.CharacterGroupId };

            ConditionalField.AvailableForCharacterGroupIds  = new[] { Group.CharacterGroupId };
            ConditionalHeader.AvailableForCharacterGroupIds = new[] { Group.CharacterGroupId };
        }
Exemplo n.º 7
0
        public async Task <Project> AddProject(CreateProjectRequest request)
        {
            var rootGroup = new CharacterGroup()
            {
                IsPublic = true,
                IsRoot   = true,
                //TODO[Localize]
                CharacterGroupName      = "Все роли",
                IsActive                = true,
                ResponsibleMasterUserId = CurrentUserId,
                HaveDirectSlots         = true,
                AvaiableDirectSlots     = -1,
            };

            MarkCreatedNow(rootGroup);
            var project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = false,
                CreatedDate       = Now,
                ProjectName       = Required(request.ProjectName),
                CharacterGroups   = new List <CharacterGroup>()
                {
                    rootGroup,
                },
                ProjectAcls = new List <ProjectAcl>()
                {
                    ProjectAcl.CreateRootAcl(CurrentUserId, isOwner: true),
                },
                Details       = new ProjectDetails(),
                ProjectFields = new List <ProjectField>(),
            };

            MarkTreeModified(project);
            switch (request.ProjectType)
            {
            case ProjectTypeDto.Larp:

                project.Details.CharacterNameLegacyMode = false;
                project.Details.CharacterNameField      = new ProjectField()
                {
                    CanPlayerEdit     = false,
                    CanPlayerView     = true,
                    FieldBoundTo      = FieldBoundTo.Character,
                    FieldName         = "Имя персонажа", //TODO[Localize]
                    FieldType         = ProjectFieldType.String,
                    IsActive          = true,
                    IsPublic          = true,
                    MandatoryStatus   = MandatoryStatus.Required,
                    IncludeInPrint    = false,
                    ValidForNpc       = true,
                    ProjectFieldId    = -2,
                    Description       = new MarkdownString(""),
                    MasterDescription = new MarkdownString(""),
                };
                project.Details.CharacterDescription = new ProjectField()
                {
                    CanPlayerEdit     = false,
                    CanPlayerView     = true,
                    FieldBoundTo      = FieldBoundTo.Character,
                    FieldName         = "Описание персонажа", //TODO[Localize]
                    FieldType         = ProjectFieldType.Text,
                    IsActive          = true,
                    IsPublic          = true,
                    MandatoryStatus   = MandatoryStatus.Optional,
                    IncludeInPrint    = false,
                    ValidForNpc       = true,
                    ProjectFieldId    = -1,
                    Description       = new MarkdownString(""),
                    MasterDescription = new MarkdownString(""),
                };

                project.ProjectFields.Add(project.Details.CharacterNameField);

                project.ProjectFields.Add(project.Details.CharacterDescription);
                break;

            case ProjectTypeDto.Convention:
                project.Details.AutoAcceptClaims        = true;
                project.Details.EnableAccommodation     = true;
                project.Details.CharacterNameLegacyMode = false;
                project.Details.CharacterNameField      = null;
                project.Details.CharacterDescription    = null;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            UnitOfWork.GetDbSet <Project>().Add(project);
            await UnitOfWork.SaveChangesAsync();

            return(project);
        }
Exemplo n.º 8
0
        public MockedProject()
        {
            MasterOnlyField = new ProjectField()
            {
                CanPlayerEdit          = false,
                CanPlayerView          = false,
                IsActive               = true,
                ShowOnUnApprovedClaims = true,
            };
            CharacterField = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                ShowOnUnApprovedClaims        = true,
                AvailableForCharacterGroupIds = Array.Empty <int>(),
            };

            HideForUnApprovedClaim = new ProjectField()
            {
                CanPlayerEdit                 = true,
                CanPlayerView                 = true,
                IsActive                      = true,
                FieldBoundTo                  = FieldBoundTo.Character,
                ShowOnUnApprovedClaims        = false,
                AvailableForCharacterGroupIds = Array.Empty <int>(),
            };

            PublicField = new ProjectField()
            {
                CanPlayerEdit = false,
                CanPlayerView = true,
                IsPublic      = true,
                IsActive      = true,
                FieldBoundTo  = FieldBoundTo.Character,
                AvailableForCharacterGroupIds = Array.Empty <int>(),
                ShowOnUnApprovedClaims        = true,
            };

            Character = new Character
            {
                IsActive                = true,
                IsAcceptingClaims       = true,
                ParentCharacterGroupIds = Array.Empty <int>(),
            };

            CharacterWithoutGroup = new Character
            {
                IsActive                = true,
                IsAcceptingClaims       = true,
                ParentCharacterGroupIds = Array.Empty <int>(),
            };


            Project = new Project()
            {
                Active            = true,
                IsAcceptingClaims = true,
                ProjectAcls       = new List <ProjectAcl>
                {
                    ProjectAcl.CreateRootAcl(Master.UserId, isOwner: true),
                },
                ProjectFields = new List <ProjectField>()
                {
                    MasterOnlyField,
                    CharacterField,
                    HideForUnApprovedClaim,
                    PublicField,
                },
                Characters = new List <Character>()
                {
                    Character, CharacterWithoutGroup
                },
                CharacterGroups = new List <CharacterGroup>(),
                Claims          = new List <Claim>(),
                Details         = new ProjectDetails(),
            };

            FixProjectSubEntities(Project);

            Group = CreateCharacterGroup(new CharacterGroup()
            {
                AvaiableDirectSlots = 1,
                HaveDirectSlots     = true,
            });

            Character.ParentCharacterGroupIds = new[] { Group.CharacterGroupId };
        }