public async Task <int> CreateFolderAsync(FolderDto folder)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@Name", folder.Name);
            parameters.Add("@ParentFolderId", folder.ParentFolderId);
            parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var folderId = await _connectionWrapper.ExecuteScalarAsync <int>("CreateFolder", parameters, commandType : CommandType.StoredProcedure);

            var errorCode = parameters.Get <int?>("ErrorCode");

            if (errorCode.HasValue)
            {
                switch (errorCode.Value)
                {
                case (int)SqlErrorCodes.GeneralSqlError:
                    throw new Exception(ErrorMessages.GeneralErrorOfCreatingFolder);

                case (int)SqlErrorCodes.FolderWithSuchNameExistsInParentFolder:
                    throw new ConflictException(ErrorMessages.FolderWithSuchNameExistsInParentFolder, ErrorCodes.Conflict);

                case (int)SqlErrorCodes.ParentFolderNotExists:
                    throw new ResourceNotFoundException(ErrorMessages.ParentFolderNotExists, ErrorCodes.ResourceNotFound);

                default:
                    return(folderId);
                }
            }
            return(folderId);
        }
Exemple #2
0
        public async Task <InstanceAdminPrivileges> GetInstanceAdminPrivilegesAsync(int userId)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@UserId", userId);

            return(await _connectionWrapper.ExecuteScalarAsync <InstanceAdminPrivileges>("GetInstancePermissionsForUser", parameters, commandType : CommandType.StoredProcedure));
        }
Exemple #3
0
        public async Task <Guid?> DeleteFile(Guid guid, DateTime?expired)
        {
            var prm = new DynamicParameters();

            prm.Add("@FileId", guid);
            prm.Add("@ExpiredTime", GetDeleteFileExpirationTime(expired));
            return((await _connectionWrapper.ExecuteScalarAsync <int>("[FileStore].DeleteFile", prm, commandTimeout: _commandTimeout, commandType: CommandType.StoredProcedure)) > 0 ? guid : (Guid?)null);
        }
        public async Task <XmlProfileSettings> GetSettingsAsync(int itemId, int userId)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@userId", userId);
            parameters.Add("@itemId", itemId);

            var settingsXml = await _connectionWrapper.ExecuteScalarAsync <string>(
                "GetArtifactListSettings", parameters, commandType : CommandType.StoredProcedure);

            return(SerializationHelper.FromXml <XmlProfileSettings>(settingsXml));
        }
        public Task <ProjectPermissions> GetProjectPermissions(int projectId)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@ProjectId", projectId);

            return(_connectionWrapper.ExecuteScalarAsync <ProjectPermissions>("GetProjectPermissions", parameters, commandType: CommandType.StoredProcedure));
        }
Exemple #6
0
        public Task <bool> IsDiscussionDeleted(int discussionId)
        {
            var discussionsPrm = new DynamicParameters();

            discussionsPrm.Add("@DiscussionId", discussionId);

            return(_connectionWrapper.ExecuteScalarAsync <bool>("IsDiscussionDeleted", discussionsPrm, commandType: CommandType.StoredProcedure));
        }
        public async Task <int> AddGroupAsync(GroupDto group, IDbTransaction transaction)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@Name", group.Name);
            parameters.Add("@Email", group.Email);
            parameters.Add("@Source", group.Source);
            parameters.Add("@LicenseId", (int)group.LicenseType);
            parameters.Add("@ProjectId", group.ProjectId);
            parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output);

            int groupId;

            if (transaction == null)
            {
                groupId = await _connectionWrapper.ExecuteScalarAsync <int>("AddGroup", parameters, commandType : CommandType.StoredProcedure);
            }
            else
            {
                groupId = await transaction.Connection.ExecuteScalarAsync <int>("AddGroup", parameters, transaction, commandType : CommandType.StoredProcedure);
            }

            var errorCode = parameters.Get <int?>("ErrorCode");

            if (errorCode.HasValue)
            {
                switch (errorCode.Value)
                {
                case (int)SqlErrorCodes.GeneralSqlError:
                    throw new Exception(ErrorMessages.GeneralErrorOfCreatingGroup);

                case (int)SqlErrorCodes.GroupWithNameAndScopeExist:
                    throw new BadRequestException(ErrorMessages.GroupAlreadyExist);

                case (int)SqlErrorCodes.CurrentProjectIsNotExist:
                    throw new ResourceNotFoundException(ErrorMessages.TheProjectDoesNotExist, ErrorCodes.ResourceNotFound);

                default:
                    return(groupId);
                }
            }

            return(groupId);
        }
Exemple #8
0
        public Task <int> GetLockedLicenses(int excludeUserId, int licenseLevel, int licenseLockTimeMinutes)
        {
            var prm = new DynamicParameters();

            prm.Add("@TimeUtc", DateTime.UtcNow);
            prm.Add("@UserId", excludeUserId);
            prm.Add("@LicenseLevel", licenseLevel);
            prm.Add("@TimeDiff", -licenseLockTimeMinutes);

            return(_connectionWrapper.ExecuteScalarAsync <int>(
                       @"SELECT COUNT(*) FROM [AdminStore].[Sessions] 
                WHERE LicenseLevel = @LicenseLevel AND UserId <> @UserId AND 
                (EndTime IS NULL OR EndTime > DATEADD(MINUTE, @TimeDiff, @TimeUtc) )",
                       prm));
        }
        public async Task <int> AddArtifactsToCollectionAsync(
            int collectionId, IEnumerable <int> artifactIds, int userId, IDbTransaction transaction = null)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@UserId", userId);
            parameters.Add("@CollectionId", collectionId);
            parameters.Add("@ArtifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));

            int result;

            if (transaction == null)
            {
                result = await _connectionWrapper.ExecuteScalarAsync <int>(
                    "AddArtifactsToCollection", parameters, commandType : CommandType.StoredProcedure);
            }
            else
            {
                result = await transaction.Connection.ExecuteScalarAsync <int>(
                    "AddArtifactsToCollection", parameters, transaction, commandType : CommandType.StoredProcedure);
            }

            return(result);
        }
        public async Task <AssignProjectsResult> AssignProjectsAndArtifactTypesToWorkflow(int workflowId, WorkflowAssignScope scope)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@WorkflowId", workflowId);
            parameters.Add("@AllArtifactTypes", scope.AllArtifacts, dbType: DbType.Boolean);
            parameters.Add("@AllProjects", scope.AllProjects, dbType: DbType.Boolean);
            parameters.Add("@ArtifactTypesIds", SqlConnectionWrapper.ToDataTable(scope.ArtifactIds, "Int32Collection", "Int32Value"));
            parameters.Add("@ProjectIds", SqlConnectionWrapper.ToDataTable(scope.ProjectIds, "Int32Collection", "Int32Value"));
            parameters.Add("@AllProjectsAssignedToWorkflow", dbType: DbType.Boolean, direction: ParameterDirection.Output);
            parameters.Add("@ErrorCode", dbType: DbType.Int32, direction: ParameterDirection.Output);

            var result = await _connectionWrapper.ExecuteScalarAsync <int>("AssignProjectsAndArtifactTypesToWorkflow", parameters, commandType : CommandType.StoredProcedure);

            var errorCode = parameters.Get <int?>("ErrorCode");

            if (errorCode.HasValue)
            {
                switch (errorCode.Value)
                {
                case (int)SqlErrorCodes.GeneralSqlError:
                    throw new Exception(ErrorMessages.GeneralErrorOfAssignProjectsAndArtifactTypesToWorkflow);

                case (int)SqlErrorCodes.WorkflowWithCurrentIdNotExist:
                    throw new ResourceNotFoundException(ErrorMessages.WorkflowNotExist, ErrorCodes.ResourceNotFound);

                case (int)SqlErrorCodes.WorkflowWithCurrentIdIsActive:
                    throw new ConflictException(ErrorMessages.WorkflowIsActive, ErrorCodes.WorkflowIsActive);
                }
            }

            return(new AssignProjectsResult()
            {
                TotalAssigned = result, AllProjectsAssignedToWorkflow = parameters.Get <bool>("AllProjectsAssignedToWorkflow")
            });
        }