Exemplo n.º 1
0
        public async Task <IActionResult> CreateAmazonAccount(int id)
        {
            var username     = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub");
            var service      = new InstituteRepositoryService(connString);
            var institute    = (await service.GetInstituteById(id)).Name;
            var bucketSevice = new AmazonS3Service();
            var bucketName   = GetName(institute);
            await bucketSevice.CreateBucketToS3(bucketName);

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

            var amazonAccountModel = new InstituteAmazonAccount()
            {
                AccessKey   = accesKeyInfo.AccessKey,
                Actor       = username,
                BucketName  = bucketName,
                IamUsername = iamUserName,
                InstituteId = id,
                SecretKey   = accesKeyInfo.SecurityKey
            };
            await service.CreateInstituteAmazonAccount(amazonAccountModel);

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "Cloud account created successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(int id)
        {
            var service = new InstituteRepositoryService(connString);
            var result  = await service.GetInstituteById(id);

            var response = new GenericResponse <InstituteDTO>()
            {
                IsSuccess    = true,
                Message      = "Data fetched successfully.",
                ResponseCode = 200,
                Result       = result
            };

            return(Ok(response));
        }