Beispiel #1
0
        public CreateCustomerResponse CreateCustomer(CreateCustomerParam param)
        {
            var request = new RestRequest(Url.CustomersUrl, Method.POST)
            {
                RequestFormat = DataFormat.Json
            };

            var data     = CreateNewCustomerParam(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 <CreateCustomerResult>(request);

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

            return(new CreateCustomerResponse
            {
                CustomerId = res.Data.customer_id,
                UserId = res.Data.user.id,
                LoginName = res.Data.user.login_name,
                Password = res.Data.user.password
            });
        }
Beispiel #2
0
 private object CreateNewCustomerParam(CreateCustomerParam param) => new
 {
     company = new
     {
         name        = param.Customer.Name,
         state       = param.Customer.State,
         country     = param.Customer.Country,
         city        = param.Customer.City,
         address     = param.Customer.Address,
         postal_code = param.Customer.PostalCode,
         note        = param.Customer.Note
     },
     user = new
     {
         login_name = param.User.LoginName,
         first_name = param.User.FirstName,
         last_name  = param.User.LastName,
         email      = param.User.Email,
         time_zone  = param.User.TimeZone,
         language   = param.User.Language,
         area_code  = param.User.PhoneAreaCode,
         number     = param.User.PhoneNumber,
         extension  = param.User.PhoneExtension
     }
 };
Beispiel #3
0
        public async Task <string> CreateCustomerAsync(string externalId)
        {
            var company = await _dataService.CompanyService.ExternalGetAsync(externalId);

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

            var param = new CreateCustomerParam
            {
                Customer = new I.Customer
                {
                    Name       = company.Name,
                    State      = "HR",
                    Country    = "HR",
                    City       = "Zagreb",
                    Address    = company.Address,
                    PostalCode = 10000.ToString(),
                    Note       = ""
                },
                User = new I.User
                {
                    LoginName = user.ApplicationLoginName,
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Email     = user.Email,
                    TimeZone  = "UTC",
                    Language  = "en-US"
                }
            };

            var res = _client.CreateCustomer(param);

            company.ApplicationCustomerID = res.CustomerId.ToString();
            company.IsDeleted             = false;

            user.ApplicationLoginName = res.LoginName;
            user.ApplicationPassword  = res.Password;
            user.ApplicationID        = res.UserId.ToString();

            _dataService.CompanyService.Update(company);
            _dataService.UserService.Update(user);

            await _dataService.SaveChangesAsync();

            return(res.CustomerId.ToString());
        }