예제 #1
0
        protected async Task <TModel> GetProjectAsync(string projectId)
        {
            Attempt <TModel> projectAttempt = await RealtimeService.TryGetSnapshotAsync <TModel>(projectId);

            if (!projectAttempt.TryResult(out TModel project))
            {
                throw new DataNotFoundException("The project does not exist.");
            }
            return(project);
        }
예제 #2
0
        public async Task SyncAsync(string curUserId, string projectId)
        {
            Attempt <SFProject> attempt = await RealtimeService.TryGetSnapshotAsync <SFProject>(projectId);

            if (!attempt.TryResult(out SFProject project))
            {
                throw new DataNotFoundException("The project does not exist.");
            }

            if (!IsProjectAdmin(project, curUserId))
            {
                throw new ForbiddenException();
            }

            await _syncService.SyncAsync(curUserId, projectId, false);
        }
예제 #3
0
        public async Task AddTranslateMetricsAsync(string curUserId, string projectId, TranslateMetrics metrics)
        {
            Attempt <SFProject> attempt = await RealtimeService.TryGetSnapshotAsync <SFProject>(projectId);

            if (!attempt.TryResult(out SFProject project))
            {
                throw new DataNotFoundException("The project does not exist.");
            }

            if (!project.UserRoles.ContainsKey(curUserId))
            {
                throw new ForbiddenException();
            }

            metrics.UserRef    = curUserId;
            metrics.ProjectRef = projectId;
            metrics.Timestamp  = DateTime.UtcNow;
            await _translateMetrics.ReplaceAsync(metrics, true);
        }