예제 #1
0
        public async Task <Result> CreateSubscriptionAsync(string applicationcustomerID, int quantity, string externalId, string servicePlanId, string assetId)
        {
            var company = await _dataService.CompanyService.ExternalGetAsync(externalId);

            var user = await _dataService.UserService.ExternalGetAsync(externalId);

            var role = await _dataService.RolesService.GetAsync((int)Role.Admin);

            var param = new CreateSubscriptionParam
            {
                CustomerId       = new Guid(applicationcustomerID),
                ServicePlanId    = new Guid(servicePlanId),
                UnitsPerLicense  = quantity,
                LicenseStartDate = DateTime.Now
            };

            var res = _client.CreateSubscription(param);

            company.ApplicationSubscriptionId = res.SubscriptionId.ToString();

            _dataService.CompanyService.Update(company);

            var applicationLicences = res.Licenses.Select(x => new ApplicationLicences
            {
                LicenceKey            = x.AcCode,
                GracePeriod           = x.GracePeriod,
                LicenceExpirationDate = x.LicenseExpirationDate,
                LicenceStartDate      = x.LicenseStartDate,
                StartChargeDate       = x.StartChargeDate,
                Units      = x.Units,
                Version    = x.Version,
                ExternalId = assetId
            }).ToList();

            var subscription = new ApplicationSubscription
            {
                ServiceUrl          = res.ServiceUrl,
                SubscriptionId      = res.SubscriptionId.ToString(),
                ProductName         = res.ProductName,
                CompanyId           = company.Id,
                ApplicationLicences = applicationLicences,
                ExternalId          = assetId
            };

            _dataService.ApplicationSubscriptionService.Add(subscription);

            var userRole = new UserRole
            {
                Quantity = quantity,
                Role     = role,
                User     = user
            };

            _dataService.UserRoleService.Add(userRole);

            await _dataService.SaveChangesAsync();

            return(new Result(true, null));
        }
예제 #2
0
파일: Client.cs 프로젝트: Gajotres100/CSP
        public CreateSubscriptionResponse CreateSubscription(CreateSubscriptionParam param)
        {
            var request = new RestRequest(Url.SubscriptionUrl, Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            request.AddUrlSegment("customer_id", param.CustomerId.ToString());

            var data     = CreateNewSubscriptionParam(param);
            var jsonData = request.JsonSerializer.Serialize(data);

            request.AddBody(data);
            var url = _client.BuildUri(request);

            request = ConstructRequestHeader(request, url.PathAndQuery, jsonData);

            var res = _client.Execute <CreateSubscriptionResult>(request);

            if (res.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new TrendMicroApiException(res.StatusCode, res.StatusDescription, res.ErrorMessage, res.ErrorException);
            }

            return(new CreateSubscriptionResponse
            {
                SubscriptionId = res.Data.subscription_id,
                ProductName = res.Data.product_name,
                ServiceUrl = res.Data.service_url,
                Licenses = res.Data.licenses.Select(x => new License
                {
                    AcCode = x.ac_code,
                    ProductId = x.product_id,
                    Version = x.version,
                    LicenseStartDate = x.license_start_date,
                    LicenseExpirationDate = x.license_expiration_date,
                    StartChargeDate = x.start_charge_date,
                    Units = x.units
                }).ToList()
            });
        }
예제 #3
0
파일: Client.cs 프로젝트: Gajotres100/CSP
 private object CreateNewSubscriptionParam(CreateSubscriptionParam param) => new
 {
     service_plan_id    = param.ServicePlanId,
     units_per_license  = param.UnitsPerLicense,
     license_start_date = param.LicenseStartDate.HasValue ? param.LicenseStartDate.Value.ToString("yyyy-MM-ddTHH:mm:ssZ") : ""
 };