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 AddCustomerToAccount(string addedBy, Guid accountId, Guid customerId) { var updateQuery = new CommerceUpdate <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); updateQuery.SearchCriteria.Model.Properties["Id"] = customerId.ToCommerceServerFormat(); updateQuery.Model.ParentOrganizationId = accountId.ToCommerceServerFormat(); var response = FoundationService.ExecuteRequest(updateQuery.ToRequest()); _auditLog.WriteToAuditLog(Common.Core.Enumerations.AuditType.CustomerAddedToCustomerGroup, addedBy, string.Format("Customer: {0}, Account: {1}", customerId, accountId)); }
public Guid CreateOrUpdateBasket(Guid userId, string branchId, Basket basket, List <LineItem> items, bool runPipelines = false) { var updateOrder = new CommerceUpdate <Basket, CommerceModelSearch <Basket>, CommerceBasketUpdateOptionsBuilder>(); updateOrder.SearchCriteria.Model.UserId = userId.ToString(); updateOrder.SearchCriteria.Model.BasketType = 0; if (!string.IsNullOrEmpty(basket.Id)) { updateOrder.SearchCriteria.Model.Id = basket.Id; } else { updateOrder.SearchCriteria.Model.Name = basket.Name; } updateOrder.Model = basket; updateOrder.UpdateOptions.ToOptions().ReturnModel = (new Basket()).ToCommerceEntity(); updateOrder.UpdateOptions.RefreshBasket = runPipelines; if (items != null) { foreach (var item in items) { if (string.IsNullOrEmpty(item.Id) || item.Id == Guid.Empty.ToCommerceServerFormat()) { var lineItemCreate = new CommerceCreateRelatedItem <LineItem>(Basket.RelationshipName.LineItems); lineItemCreate.Model = item; updateOrder.RelatedOperations.Add(lineItemCreate); } else { var lineItemUpdate = new CommerceUpdateRelatedItem <LineItem>(Basket.RelationshipName.LineItems); lineItemUpdate.SearchCriteria.Model.Id = item.Id; lineItemUpdate.Model = item; updateOrder.RelatedOperations.Add(lineItemUpdate); } } } // create the request var response = FoundationService.ExecuteRequest(updateOrder.ToRequest()); if (response.OperationResponses.Count != 1) { return(Guid.Empty); } return(((CommerceUpdateOperationResponse)response.OperationResponses[0]).CommerceEntities[0].Id.ToGuid()); }
public void RemoveCustomerFromAccount(string removedBy, Guid accountId, Guid customerId) { var updateQuery = new CommerceUpdate <KeithLink.Svc.Core.Models.Generated.Organization>("Organization"); updateQuery.SearchCriteria.Model.Properties["Id"] = customerId.ToCommerceServerFormat(); updateQuery.Model.ParentOrganizationId = string.Empty; var response = FoundationService.ExecuteRequest(updateQuery.ToRequest()); _auditLog.WriteToAuditLog(Common.Core.Enumerations.AuditType.CustomerRemovedFromCustomerGroup, removedBy, string.Format("Customer: {0}, Account: {1}", customerId, accountId)); // TODO: remove all users associated directly to the customer }
public void UpdateCustomerCanViewPricing(Guid customerId, bool canView) { CommerceUpdate <Organization> update = new CommerceUpdate <Organization>(); // have to use the Commerce Server ID to search for customers so we cannot use branch/customer number update.SearchCriteria.Model.Id = customerId.ToCommerceServerFormat(); update.Model.CanViewPricing = canView; CommerceUpdateOperationResponse res = FoundationService.ExecuteRequest(update.ToRequest()).OperationResponses[0] as CommerceUpdateOperationResponse; Customer cus = GetCustomerById(customerId); _customerCacheRepository.RemoveItem(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, GetCacheKey(string.Join("-", cus.CustomerNumber, cus.CustomerBranch))); }
///// <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)); }
public void DeleteItem(Guid userId, Guid cartId, Guid itemId, bool runPipelines = false) { var updateOrder = new CommerceUpdate <Basket, CommerceModelSearch <Basket>, CommerceBasketUpdateOptionsBuilder>(); updateOrder.SearchCriteria.Model.UserId = userId.ToString(); updateOrder.SearchCriteria.Model.BasketType = 0; updateOrder.SearchCriteria.Model.Id = cartId.ToCommerceServerFormat(); updateOrder.UpdateOptions.RefreshBasket = runPipelines; var lineItemUpdate = new CommerceDeleteRelatedItem <LineItem>(Basket.RelationshipName.LineItems); lineItemUpdate.SearchCriteria.Model.Id = itemId.ToCommerceServerFormat(); updateOrder.RelatedOperations.Add(lineItemUpdate); FoundationService.ExecuteRequest(updateOrder.ToRequest()); }
public Guid?AddItem(Guid cartId, LineItem newItem, Basket basket, bool runPipelines = false) { var updateOrder = new CommerceUpdate <Basket, CommerceModelSearch <Basket>, CommerceBasketUpdateOptionsBuilder>(); updateOrder.SearchCriteria.Model.UserId = basket.UserId; updateOrder.SearchCriteria.Model.BasketType = 0; updateOrder.SearchCriteria.Model.Id = cartId.ToCommerceServerFormat(); updateOrder.UpdateOptions.RefreshBasket = runPipelines; // disable running of pipelines to optimize save time updateOrder.UpdateOptions.ToOptions().ReturnModel = (new Basket()).ToCommerceEntity(); var lineItemUpdate = new CommerceCreateRelatedItem <LineItem>(Basket.RelationshipName.LineItems); lineItemUpdate.Model = newItem; updateOrder.RelatedOperations.Add(lineItemUpdate); updateOrder.UpdateOptions.ToOptions().ReturnModelQueries.Add( new CommerceQueryRelatedItem() { RelationshipName = Basket.RelationshipName.LineItems, Model = (new LineItem()).ToCommerceEntity() }); var response = FoundationService.ExecuteRequest(updateOrder.ToRequest()); CommerceServer.Foundation.CommerceRelationshipList lineItemsFromResponse = (response.OperationResponses[0] as CommerceUpdateOperationResponse) .CommerceEntities[0].Properties[Basket.RelationshipName.LineItems] as CommerceServer.Foundation.CommerceRelationshipList; var newId = lineItemsFromResponse.Where(b => !basket.LineItems.Any(i => i.Id.Equals(b.Target.Id))).FirstOrDefault(); if (newId != null) { return(newId.Target.Id.ToGuid()); } return(null); }