private CommerceResponse ExtractCommerceResponse(HttpWebResponse response) { CommerceResponse result = null; try { Stream responseStream = response.GetResponseStream(); if (responseStream != null) { string responseText; using (var streamReader = new StreamReader(responseStream)) { responseText = streamReader.ReadToEnd(); } if (!string.IsNullOrWhiteSpace(responseText)) { result = JsonConvert.DeserializeObject <V3RegisterDealResponse>(responseText); } } } catch (Exception e) { Log.Error(e.ToString()); } return(result); }
/// <summary> /// retrieve the user's profile from commerce server /// </summary> /// <param name="emailAddress">the user's email address</param> /// <returns>a commerce server user profile object</returns> /// <remarks> /// jwames - 10/14/14 - original code /// </remarks> public Core.Models.Generated.UserProfile GetCSProfile(Guid userId) { CommerceQuery <CommerceEntity> profileQuery = new CommerceQuery <CommerceEntity>("UserProfile"); profileQuery.SearchCriteria.Model.Properties["Id"] = userId.ToCommerceServerFormat(); profileQuery.Model.Properties.Add("Id"); profileQuery.Model.Properties.Add("Email"); profileQuery.Model.Properties.Add("LastLoginDate"); profileQuery.Model.Properties.Add("LastActivityDate"); profileQuery.Model.Properties.Add("FirstName"); profileQuery.Model.Properties.Add("LastName"); profileQuery.Model.Properties.Add("DefaultBranch"); profileQuery.Model.Properties.Add("DefaultCustomer"); profileQuery.Model.Properties.Add("Telephone"); // Execute the operation and get the results back CommerceResponse response = Helpers.FoundationService.ExecuteRequest(profileQuery.ToRequest()); CommerceQueryOperationResponse profileResponse = response.OperationResponses[0] as CommerceQueryOperationResponse; if (profileResponse.Count == 0) { return(null); } return((Core.Models.Generated.UserProfile)profileResponse.CommerceEntities[0]); }
public List <UserProfile> GetUsersForCustomerOrAccount(Guid orgId) { CommerceQuery <CommerceEntity> profileQuery = new CommerceQuery <CommerceEntity>("UserOrganizations"); profileQuery.SearchCriteria.Model.Properties["OrganizationId"] = orgId.ToCommerceServerFormat(); CommerceResponse res = Helpers.FoundationService.ExecuteRequest(profileQuery.ToRequest()); List <UserProfile> customerUsers = new List <UserProfile>(); Dictionary <Guid, bool> existingUsers = new Dictionary <Guid, bool>(); foreach (CommerceEntity ent in (res.OperationResponses[0] as CommerceQueryOperationResponse).CommerceEntities) { Guid userid = Guid.Parse(ent.Id); if (!existingUsers.ContainsKey(userid)) { existingUsers.Add(userid, true); customerUsers.Add(new UserProfile { UserId = userid, FirstName = (string)ent.Properties["FirstName"], LastName = (string)ent.Properties["LastName"], EmailAddress = (string)ent.Properties["Email"] }); } } return(customerUsers); }
/// <summary> /// retrieve the user's profile from commerce server /// </summary> /// <param name="emailAddress">the user's email address</param> /// <returns>a commerce server user profile object</returns> /// <remarks> /// jwames - 10/3/2014 - documented /// </remarks> public Core.Models.Generated.UserProfile GetCSProfile(string emailAddress) { CommerceQuery <CommerceEntity> profileQuery = new CommerceQuery <CommerceEntity>("UserProfile"); profileQuery.SearchCriteria.Model.Properties["Email"] = emailAddress; profileQuery.SearchCriteria.Model.DateModified = DateTime.Now; profileQuery.Model.Properties.Add("Id"); profileQuery.Model.Properties.Add("Email"); profileQuery.Model.Properties.Add("LastLoginDate"); profileQuery.Model.Properties.Add("LastActivityDate"); profileQuery.Model.Properties.Add("FirstName"); profileQuery.Model.Properties.Add("LastName"); profileQuery.Model.Properties.Add("DefaultBranch"); profileQuery.Model.Properties.Add("DefaultCustomer"); profileQuery.Model.Properties.Add("Telephone"); CommerceResponse response = Helpers.FoundationService.ExecuteRequest(profileQuery.ToRequest()); CommerceQueryOperationResponse profileResponse = response.OperationResponses[0] as CommerceQueryOperationResponse; if (profileResponse.Count == 0) { return(null); } return((Core.Models.Generated.UserProfile)profileResponse.CommerceEntities[0]); }
public void UpdateUserProfileLastAccess(Guid id) { CommerceUpdate <Core.Models.Generated.UserProfile> updateQuery = new CommerceUpdate <Core.Models.Generated.UserProfile>("UserProfile"); updateQuery.SearchCriteria.Model.Properties["Id"] = id.ToCommerceServerFormat(); updateQuery.Model.LastActivityDate = DateTime.Now; CommerceResponse response = Helpers.FoundationService.ExecuteRequest(updateQuery.ToRequest()); //_auditLog.WriteToAuditLog(Common.Core.Enumerations.AuditType.UserUpdate, null, Newtonsoft.Json.JsonConvert.SerializeObject(updateQuery.Model)); }
public void RemoveUserFromOrg(Guid orgId, Guid userId) { var deleteUser = new CommerceDelete <Svc.Core.Models.Generated.UserOrganizations>(); deleteUser.SearchCriteria.Model.UserOrganizationKey = GetUserOrgKey(orgId, userId); deleteUser.DeleteOptions.ReturnDeletedCount = true; CommerceResponse response = Svc.Impl.Helpers.FoundationService.ExecuteRequest(deleteUser.ToRequest()); CommerceDeleteOperationResponse deleteResponse = response.OperationResponses[0] as CommerceDeleteOperationResponse; }
public void AddUserToOrg(Guid orgId, Guid userId) { CommerceCreate <UserOrganizations> createOrg = new CommerceCreate <UserOrganizations>("UserOrganizations"); createOrg.Model.Id = Guid.NewGuid().ToCommerceServerFormat(); createOrg.Model.OrganizationId = orgId.ToCommerceServerFormat(); createOrg.Model.UserId = userId.ToCommerceServerFormat(); createOrg.CreateOptions.ReturnModel = new UserOrganizations(); createOrg.Model.UserOrganizationKey = GetUserOrgKey(orgId, userId); CommerceResponse res = Svc.Impl.Helpers.FoundationService.ExecuteRequest(createOrg.ToRequest()); }
/// <summary> /// Initializes the specified Response object. /// </summary> /// <param name="response"> /// The Response object to initialize. /// </param> /// <exception cref="ArgumentNullException"> /// Parameter response cannot be null. /// </exception> public static void Initialize(this CommerceResponse response, Guid requestId) { if (response == null) { throw new ArgumentNullException("response", "Parameter response cannot be null."); } response.RequestInformation = new RequestInformation(); response.RequestInformation.Initialize(requestId); response.ResultSummary = new ResultSummary(); response.ResultSummary.Initialize(); }
///// <summary> ///// update the user profile in Commerce Server (not implemented) ///// </summary> ///// <remarks> ///// jwames - 8/18/2014 - documented ///// </remarks> public void UpdateUserProfile(string updatedBy, Guid id, string emailAddress, string firstName, string lastName, string phoneNumber, string branchId) { CommerceUpdate <Core.Models.Generated.UserProfile> updateQuery = new CommerceUpdate <Core.Models.Generated.UserProfile>("UserProfile"); updateQuery.SearchCriteria.Model.Properties["Id"] = id.ToCommerceServerFormat(); updateQuery.Model.Email = emailAddress; updateQuery.Model.FirstName = firstName; updateQuery.Model.LastName = lastName; updateQuery.Model.Telephone = phoneNumber; updateQuery.Model.DefaultBranch = branchId; // TODO: add DefaultCustomer CommerceResponse response = Helpers.FoundationService.ExecuteRequest(updateQuery.ToRequest()); _auditLog.WriteToAuditLog(AuditType.UserUpdate, updatedBy, JsonConvert.SerializeObject(updateQuery.Model)); }
private async Task <bool> RegisterOfferWithCommerceAsync(V3DealDataContract dealDataContract) { bool bSuccess = false; string offerId = dealDataContract.Id.ToString(); Log.Info($"Calling commerce to register offer {offerId}"); string commercePayload = JsonConvert.SerializeObject(dealDataContract); int retryCount = 0; bool retry = true; while (retry) { try { var commerceResponse = await Task.Run(() => this.commerceService.RegisterOffer(commercePayload)).ConfigureAwait(false); if (commerceResponse != null) { retry = false; if (commerceResponse.ResultSummary != null && (commerceResponse.ResultSummary.ResultCode == "Created" || commerceResponse.ResultSummary.ResultCode == "Success")) { bSuccess = true; Log.Info( $"Successfully registered offer {dealDataContract.Id.ToString()} for provider {dealDataContract.ProviderId}, {dealDataContract.ProviderName} with commerce"); } } } catch (CryptographicException) { Log.Error($"Error in registering offer with commerce.Unable to find commerce certificate."); retry = false; } catch (WebException ex) { Log.Error($"Unable to register the offer with commerce"); var response = (HttpWebResponse)ex.Response; if (response != null) { CommerceResponse commerceResponse = ExtractCommerceResponse(response); if (commerceResponse != null) { Log.Error($"Error is {commerceResponse.ResultSummary.ResultCode} ; {commerceResponse.ResultSummary.Explanation}"); retry = false; } } } catch (Exception ex) { Log.Error($"Unable to register the offer with commerce; {ex.Message}"); } if (retry) { retryCount++; if (retryCount < 3) { int delayInterval = retryCount * 50; Log.Info($"Register offer with commerce failed...Call will be retried after a delay of {delayInterval} ms"); await Task.Delay(delayInterval); } else { retry = false; } } } return(bSuccess); }