private async Task OnApplyToVideoJobClickedAsync(VideoJobModel videoJobModel)
        {
            var state = await AuthenticationStateTask;

            if (state != null && state.User.Identity.IsAuthenticated)
            {
                this.SelectdVideoJob = videoJobModel;
                this.CreateVideoJobApplicationModel.VideoJobId = videoJobModel.VideoJobId;
                this.ShowApplyToVideoJobModal = true;
            }
            else
            {
                ToastService.ShowError(Localizer[MustBeLoggedInTextKey],
                                       Localizer[AccessDeniedTextKey]);
            }
        }
        public async Task AddVideoJobAsync(VideoJobModel videoJobModel)
        {
            var authorizedHttpClient = this.HttpClientService.CreateAuthorizedClient();
            var response             = await authorizedHttpClient.PostAsJsonAsync(ApiRoutes.VideoJobController.AddVideoJob, videoJobModel);

            if (!response.IsSuccessStatusCode)
            {
                ProblemHttpResponse problemHttpResponse = await response.Content.ReadFromJsonAsync <ProblemHttpResponse>();

                if (problemHttpResponse != null)
                {
                    throw new CustomValidationException(problemHttpResponse.Detail);
                }
                else
                {
                    throw new CustomValidationException(response.ReasonPhrase);
                }
            }
        }
Example #3
0
        public async Task AddVideoJobAsync(VideoJobModel videoJobModel, CancellationToken cancellationToken)
        {
            if (videoJobModel.Budget <= 0)
            {
                throw new CustomValidationException(Localizer[BudgetMustbeGreaterThan0TextKey]);
            }
            var userObjectId = this.CurrentUserProvider.GetObjectId();
            var videoEntity  = await this.FairplaytubeDatabaseContext.VideoInfo
                               .Include(p => p.ApplicationUser)
                               .FirstOrDefaultAsync(p => p.VideoId == videoJobModel.VideoId, cancellationToken: cancellationToken);

            if (videoEntity == null)
            {
                throw new CustomValidationException($"{String.Format(Localizer[VideoWithIdDoesNotExistsTextKey], videoJobModel.VideoId)}");
            }
            var userEntity    = videoEntity.ApplicationUser;
            var fundsToDeduct = videoJobModel.Budget + (videoJobModel.Budget * Common.Global.Constants.Commissions.VideoJobComission);

            if (fundsToDeduct > userEntity.AvailableFunds)
            {
                throw new CustomValidationException(String.Format(Localizer[NotEnoughFundsTextKey], fundsToDeduct, userEntity.AvailableFunds));
            }
            VideoJob videoJobEntity = new()
            {
                Budget      = videoJobModel.Budget,
                Title       = videoJobModel.Title,
                Description = videoJobModel.Description,
                VideoInfoId = videoEntity.VideoInfoId
            };

            videoJobEntity.VideoJobEscrow = new VideoJobEscrow()
            {
                Amount = fundsToDeduct
            };
            userEntity.AvailableFunds -= fundsToDeduct;
            await this.FairplaytubeDatabaseContext.VideoJob.AddAsync(videoJobEntity, cancellationToken : cancellationToken);

            await this.FairplaytubeDatabaseContext.SaveChangesAsync(cancellationToken : cancellationToken);
        }