コード例 #1
0
        public async Task <Guid> CreateAsync(Partner partner)
        {
            partner.Id = Guid.NewGuid();

            partner.Locations = await _locationService.CreateLocationsContactPersonForPartnerAsync(partner);

            if (partner.UseGlobalCurrencyRate)
            {
                partner.AmountInTokens   = null;
                partner.AmountInCurrency = null;
            }

            CredentialsCreateResponse credential;

            try
            {
                credential = await _credentialsClient.Partners.CreateAsync(new PartnerCredentialsCreateRequest
                {
                    PartnerId    = partner.Id.ToString(),
                    ClientId     = partner.ClientId,
                    ClientSecret = partner.ClientSecret
                });
            }
            catch (ClientApiException e)
            {
                if (e.HttpStatusCode == HttpStatusCode.BadRequest)
                {
                    throw new PartnerRegistrationFailedException(e.ErrorResponse.ErrorMessage);
                }

                throw;
            }

            if (credential.Error == CredentialsError.LoginAlreadyExists)
            {
                var exception = new ClientAlreadyExistException($"Client with id '{partner.ClientId}' already exist.");
                _log.Warning(exception.Message, context: partner);
                throw exception;
            }

            if (credential.Error != CredentialsError.None)
            {
                var exception = new PartnerRegistrationFailedException("Register user failed.");
                _log.Warning(exception.Message, context: partner);
                throw exception;
            }

            var createdPartner = await _partnerRepository.CreateAsync(partner);

            await _partnerCreatedPublisher.PublishAsync(new PartnerCreatedEvent
            {
                CreatedBy = createdPartner.CreatedBy, PartnerId = createdPartner.Id, Timestamp = DateTime.UtcNow
            });

            return(createdPartner.Id);
        }
コード例 #2
0
        public async Task <IActionResult> Create(CreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Defines the Photo as the default
                var path = $"~/images/Partners/no-logo.png";

                if (model.ImageFile != null && model.ImageFile.Length > 0)
                {
                    path = await _imageHelper.UploadImageAsync(model.ImageFile, "Partners");
                }


                var entity = _converterHelper.ToPartnerEntity(model, path);
                await _partnerRepository.CreateAsync(entity);

                ViewBag.Message = "Partner successfuly created and awaiting aproval";
            }
            return(View(model));
        }