private async Task <ImpersonationConfig> SaveImpersonationConfig(ImpersonationConfig impersonation, string buyerID, string accessToken, IOrderCloudClient oc = null) { // if we're seeding then use the passed in oc client // to support multiple environments and ease of setup for new orgs // else used the configured client var token = oc == null ? null : accessToken; var ocClient = oc ?? _oc; var currentConfig = await GetImpersonationByBuyerID(buyerID); if (currentConfig != null && impersonation == null) { await ocClient.ImpersonationConfigs.DeleteAsync(currentConfig.ID); return(null); } else if (currentConfig != null) { return(await ocClient.ImpersonationConfigs.SaveAsync(currentConfig.ID, impersonation, token)); } else { impersonation.BuyerID = buyerID; impersonation.SecurityProfileID = Enum.GetName(typeof(CustomRole), CustomRole.HSBaseBuyer); impersonation.ID = $"hs_admin_{buyerID}"; return(await ocClient.ImpersonationConfigs.CreateAsync(impersonation)); } }
public async Task <SuperHSBuyer> Create(SuperHSBuyer superBuyer, string accessToken, bool isSeedingEnvironment = false) { var createdImpersonationConfig = new ImpersonationConfig(); var createdBuyer = await CreateBuyerAndRelatedFunctionalResources(superBuyer.Buyer, accessToken, isSeedingEnvironment); var createdMarkup = await CreateMarkup(superBuyer.Markup, createdBuyer.ID, accessToken); if (superBuyer?.ImpersonationConfig != null) { createdImpersonationConfig = await SaveImpersonationConfig(superBuyer.ImpersonationConfig, createdBuyer.ID, accessToken); } return(new SuperHSBuyer() { Buyer = createdBuyer, Markup = createdMarkup, ImpersonationConfig = createdImpersonationConfig }); }
public async Task <SuperHSBuyer> Create(SuperHSBuyer superBuyer, string accessToken, IOrderCloudClient oc) { var createdImpersonationConfig = new ImpersonationConfig(); var createdBuyer = await CreateBuyerAndRelatedFunctionalResources(superBuyer.Buyer, accessToken, oc); var createdMarkup = await CreateMarkup(superBuyer.Markup, createdBuyer.ID, accessToken, oc); if (superBuyer?.ImpersonationConfig != null) { createdImpersonationConfig = await SaveImpersonationConfig(superBuyer.ImpersonationConfig, createdBuyer.ID, accessToken, oc); } return(new SuperHSBuyer() { Buyer = createdBuyer, Markup = createdMarkup, ImpersonationConfig = createdImpersonationConfig }); }
public async Task <SuperHSBuyer> Update(string buyerID, SuperHSBuyer superBuyer, string token) { // to prevent changing buyerIDs superBuyer.Buyer.ID = buyerID; var updatedImpersonationConfig = new ImpersonationConfig(); var updatedBuyer = await _oc.Buyers.SaveAsync <HSBuyer>(buyerID, superBuyer.Buyer, token); var updatedMarkup = await UpdateMarkup(superBuyer.Markup, superBuyer.Buyer.ID, token); if (superBuyer.ImpersonationConfig != null) { updatedImpersonationConfig = await SaveImpersonationConfig(superBuyer.ImpersonationConfig, buyerID, token); } return(new SuperHSBuyer() { Buyer = updatedBuyer, Markup = updatedMarkup, ImpersonationConfig = updatedImpersonationConfig }); }
private async Task <ImpersonationConfig> SaveImpersonationConfig(ImpersonationConfig impersonation, string buyerID, string token) { var currentConfig = await GetImpersonationByBuyerID(buyerID); if (currentConfig != null && impersonation == null) { await _oc.ImpersonationConfigs.DeleteAsync(currentConfig.ID); return(null); } else if (currentConfig != null) { return(await _oc.ImpersonationConfigs.SaveAsync(currentConfig.ID, impersonation, token)); } else { impersonation.BuyerID = buyerID; impersonation.SecurityProfileID = Enum.GetName(typeof(CustomRole), CustomRole.HSBaseBuyer); impersonation.ID = $"hs_admin_{buyerID}"; return(await _oc.ImpersonationConfigs.CreateAsync(impersonation)); } }
private async Task <ImpersonationConfig> SaveImpersonationConfig(ImpersonationConfig impersonation, string buyerID) { return(await SaveImpersonationConfig(impersonation, buyerID, null, _oc)); }