示例#1
0
        public async Task <IActionResult> NewWorker(string providerId, [FromBody] ProviderWorkerBindingModel bindingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrors()));
            }

            var(imageBucket, outcomeAction, error) =
                await _imageBucketRepository.NewImageBucket(
                    new ImageBucket
            {
                StoreBucket = new ImageBucketKey {
                    Store = Constants.WORKER_IMAGES_STORE
                },
                ImageList = new List <string>()
            });

            if (outcomeAction != RepositoryOutcomeAction.OkCreated)
            {
                return(this.StatusCode(500, error));
            }

            var providerWorker = new ProviderWorker
            {
                Name        = bindingModel.Name,
                LastName    = bindingModel.LastName,
                Email       = bindingModel.Email,
                PhoneNumber = bindingModel.PhoneNumber,
                ProviderWorkerImageBucketKey = imageBucket.StoreBucket
            };

            (providerWorker, outcomeAction, error) = await _providerWorkerRepository.NewAsync(providerId, providerWorker);

            try
            {
                var userRegistration = await _userService.RegisterUserAsync(
                    new UserRegistration
                {
                    ProviderId = providerId,
                    WorkerId   = providerWorker.Id,
                    FirstName  = bindingModel.Name,
                    LastName   = bindingModel.LastName,
                    Email      = bindingModel.Email,
                    Password   = bindingModel.Password,
                });
            }
            catch (ApiException ex)
            {
                return(BadRequest(ex.ApiError));
            }

            var location = this.Url.BuildGetProviderWorkerUrl(providerId, providerWorker?.Id);

            return(this.FromRepositoryOutcome(outcomeAction, error, MapToProviderWorkerViewModel(providerWorker), location));
        }
示例#2
0
        public async Task TesNewAsyncFailsToCreateProviderWorkerWhenProviderDoesNotExist()
        {
            // arrange
            var providerId = "0000ffff0000ffff0000ffff0000ffff";

            var providerWorker = new ProviderWorker
            {
                ProviderId = providerId,
                Name       = "Homer",
                LastName   = "Simpson"
            };

            _dataStore.EnsureProviderDoesNotExist(providerId);

            // act
            var(providerWorkerResult, outcomeAction, error) = await _providerWorkerRepository.NewAsync(providerId, providerWorker);

            // assert
            Assert.Null(providerWorkerResult);
            Assert.Equal(RepositoryOutcomeAction.ValidationErrorNone, outcomeAction);
            Assert.NotNull(error);
        }