public async Task <IActionResult> AddVideoJobApplication(CreateVideoJobApplicationModel createVideoJobApplicationModel,
                                                                 CancellationToken cancellationToken)
        {
            await this.VideoJobApplicationService.AddVideoJobApplicationAsync(createVideoJobApplicationModel,
                                                                              cancellationToken);

            return(Ok());
        }
Example #2
0
        public async Task AddVideoJobApplicationAsync(CreateVideoJobApplicationModel createVideoJobApplicationModel, CancellationToken cancellationToken)
        {
            var loggedInUserAzureObjectId = CurrentUserProvider.GetObjectId();
            var userEntity = FairplaytubeDatabaseContext.ApplicationUser
                             .Single(p => p.AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId);
            var videoJobApplicationEntity = await FairplaytubeDatabaseContext.VideoJobApplication
                                            .Include(p => p.ApplicantApplicationUser)
                                            .Include(p => p.VideoJob)
                                            .ThenInclude(p => p.VideoInfo)
                                            .ThenInclude(p => p.ApplicationUser)
                                            .SingleOrDefaultAsync(p => p.VideoJobId == createVideoJobApplicationModel.VideoJobId &&
                                                                  p.ApplicantApplicationUser.AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId,
                                                                  cancellationToken: cancellationToken);

            if (videoJobApplicationEntity is not null)
            {
                throw new CustomValidationException(Localizer[UserApplicationAlreadyExistsTextKey]);
            }
            var videoJobEntity = await FairplaytubeDatabaseContext.VideoJob
                                 .Include(p => p.VideoInfo).ThenInclude(p => p.ApplicationUser)
                                 .SingleAsync(p => p.VideoJobId == createVideoJobApplicationModel.VideoJobId,
                                              cancellationToken: cancellationToken);

            if (videoJobEntity.VideoInfo.ApplicationUser
                .AzureAdB2cobjectId.ToString() == loggedInUserAzureObjectId)
            {
                throw new CustomValidationException(Localizer[CannotApplyToOwnedVideosJobsTextKey]);
            }
            videoJobApplicationEntity = new VideoJobApplication()
            {
                ApplicantApplicationUserId = userEntity.ApplicationUserId,
                ApplicantCoverLetter       = createVideoJobApplicationModel.ApplicantCoverLetter,
                VideoJobId = createVideoJobApplicationModel.VideoJobId.Value,
                VideoJobApplicationStatusId = (short)Common.Global.Enums.VideoJobApplicationStatus.New
            };
            await FairplaytubeDatabaseContext.VideoJobApplication.AddAsync(videoJobApplicationEntity, cancellationToken);

            await FairplaytubeDatabaseContext.SaveChangesAsync(cancellationToken);

            string message = String.Format(Localizer[UserHasAppliedToJobTextKey],
                                           videoJobEntity.VideoInfo.ApplicationUser.FullName, videoJobEntity.Title);
            await HubContext.Clients.User(videoJobEntity.VideoInfo
                                          .ApplicationUser.AzureAdB2cobjectId.ToString())
            .ReceiveMessage(new Models.Notifications.NotificationModel()
            {
                Message = message
            });
        }
        public async Task AddVideoJobApplicationAsync(CreateVideoJobApplicationModel createVideoJobApplicationModel)
        {
            var authorizedHttpClient = this.HttpClientService.CreateAuthorizedClient();
            var response             = await authorizedHttpClient
                                       .PostAsJsonAsync(ApiRoutes.VideoJobApplicationController.AddVideoJobApplication,
                                                        createVideoJobApplicationModel);

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

                if (problemHttpResponse != null)
                {
                    throw new CustomValidationException(problemHttpResponse.Detail);
                }
                else
                {
                    throw new CustomValidationException(response.ReasonPhrase);
                }
            }
        }