Пример #1
0
        public async Task <IActionResult> Create(PublisherModel model)
        {
            var username = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub");
            var service  = new PublisherRepositoryService(connString);
            var pubId    = await service.CreatePublisher(model, username);

            PublisherAmazonAccount amazonAccountModel;

            if (model.CloudAccountRequired)
            {
                var bucketSevice = new AmazonS3Service();
                var bucketName   = GetName(model.PublisherName);
                await bucketSevice.CreateBucketToS3(bucketName);

                var iamService   = new AmazonIAMService();
                var iamUserName  = GetName(model.PublisherName);
                var accesKeyInfo = await iamService.CreateIAMUser("/", iamUserName);

                amazonAccountModel = new PublisherAmazonAccount()
                {
                    AccessKey   = accesKeyInfo.AccessKey,
                    Actor       = username,
                    BucketName  = bucketName,
                    IamUsername = iamUserName,
                    PublisherId = pubId,
                    SecretKey   = accesKeyInfo.SecurityKey
                };
                await service.CreatePublisherAmazonAccount(amazonAccountModel);
            }
            var response = new GenericResponse <int>()
            {
                IsSuccess    = true,
                Message      = "Publisher created successfully.",
                ResponseCode = 200,
                Result       = pubId
            };

            return(Ok(response));
        }