예제 #1
0
        /// <summary>
        /// Puts a ReturnModel to the Basket Update Query that returns the updated Basket (full model with all properties and default relationships (Addresses, LineItems, Shipments, Discounts and Payments)) as part of the response.
        /// </summary>
        /// <param name="updateQuery">The Basket Update Query that gets the ReturnModel query added.</param>
        /// <param name="customRelationships">Any custom relationships that should be returned with the updated basket.</param>
        public static CommerceRequest ToRequestWithBasketReturnModel(this CommerceUpdate <CommerceEntity, CommerceModelSearch <CommerceEntity>, CommerceBasketUpdateOptionsBuilder> updateQuery, params Relationship[] customRelationships)
        {
            if (updateQuery == null)
            {
                throw new ArgumentNullException("updateQuery");
            }

            var updateOperation = updateQuery.ToOperation() as CommerceUpdateOperation;

            if (updateOperation == null)
            {
                throw new InvalidOperationException();
            }

            updateOperation.Options.ReturnModel = new CommerceEntity(MetadataDefinitions.Basket.EntityName);

            var relationships = new List <Relationship>
            {
                new Relationship(MetadataDefinitions.Basket.Relationships.Addresses, MetadataDefinitions.Address.EntityName),
                new Relationship(MetadataDefinitions.Basket.Relationships.LineItems, MetadataDefinitions.LineItem.EntityName),
                new Relationship(MetadataDefinitions.Basket.Relationships.Shipments, MetadataDefinitions.Shipment.EntityName),
                new Relationship(MetadataDefinitions.Basket.Relationships.Discounts, MetadataDefinitions.Discount.EntityName)
            };

            if (customRelationships != null)
            {
                relationships.AddRange(customRelationships);
            }

            foreach (var relationship in relationships)
            {
                updateOperation.Options.ReturnModelQueries.Add(new CommerceQueryRelatedItem
                {
                    RelationshipName = relationship.Name,
                    Model            = new CommerceEntity(relationship.Model)
                });
            }

            updateOperation.Options.ReturnModelQueries.Add(new CommerceQueryRelatedItem
            {
                RelationshipName  = MetadataDefinitions.Basket.Relationships.Payments,
                Model             = new CommerceEntity(MetadataDefinitions.Payment.EntityName),
                RelatedOperations = new List <CommerceRelatedOperation>
                {
                    new CommerceQueryRelatedItem
                    {
                        RelationshipName = "PaymentAccount",
                        Model            = new CommerceEntity()
                    }
                }
            });

            return(new CommerceRequest
            {
                Operations = new List <CommerceOperation> {
                    updateOperation
                }
            });
        }
예제 #2
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));
        }
예제 #3
0
        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));
        }
예제 #4
0
        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());
        }
예제 #5
0
        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
        }
예제 #6
0
        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)));
        }
예제 #7
0
        ///// <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));
        }
예제 #8
0
        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());
        }
예제 #9
0
        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);
        }