public IHttpActionResult GetNewShipment(string id) { var order = _customerOrderService.GetByIds(new[] { id }, CustomerOrderResponseGroup.Full.ToString()).FirstOrDefault(); if (order != null) { var retVal = AbstractTypeFactory <Shipment> .TryCreateInstance(); retVal.Id = Guid.NewGuid().ToString(); retVal.Currency = order.Currency; var numberTemplate = _settingManager.GetValue("Order.ShipmentNewNumberTemplate", "SH{0:yyMMdd}-{1:D5}"); retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); return(Ok(retVal)); ////Detect not whole shipped items ////TODO: LineItem partial shipping //var shippedLineItemIds = order.Shipments.SelectMany(x => x.Items).Select(x => x.LineItemId); ////TODO Add check for digital products (don't add to shipment) //retVal.Items = order.Items.Where(x => !shippedLineItemIds.Contains(x.Id)) // .Select(x => new coreModel.ShipmentItem(x)).ToList(); //return Ok(retVal.ToWebModel()); } return(NotFound()); }
public IHttpActionResult GetNewShipment(string id) { coreModel.Shipment retVal = null; var order = _customerOrderService.GetById(id, coreModel.CustomerOrderResponseGroup.Full); if (order != null) { retVal = new coreModel.Shipment { Currency = order.Currency }; retVal.Number = _uniqueNumberGenerator.GenerateNumber("SH{0:yyMMdd}-{1:D5}"); //Detect not whole shipped items //TODO: LineItem partial shipping var shippedLineItemIds = order.Shipments.SelectMany(x => x.Items).Select(x => x.LineItemId); //TODO Add check for digital products (don't add to shipment) retVal.Items = order.Items.Where(x => !shippedLineItemIds.Contains(x.Id)) .Select(x => new coreModel.ShipmentItem(x)).ToList(); return(Ok(retVal.ToWebModel())); } return(NotFound()); }
public async Task <ActionResult <Shipment> > GetNewShipment(string id) { var order = await _customerOrderService.GetByIdAsync(id, CustomerOrderResponseGroup.Full.ToString()); if (order != null) { var retVal = AbstractTypeFactory <Shipment> .TryCreateInstance(); retVal.Id = Guid.NewGuid().ToString(); retVal.Currency = order.Currency; retVal.Status = "New"; var store = await _storeService.GetByIdAsync(order.StoreId); var numberTemplate = store.Settings.GetSettingValue( ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate.Name, ModuleConstants.Settings.General.OrderShipmentNewNumberTemplate.DefaultValue); retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate.ToString()); return(Ok(retVal)); ////Detect not whole shipped items ////TODO: LineItem partial shipping //var shippedLineItemIds = order.Shipments.SelectMany(x => x.Items).Select(x => x.LineItemId); ////TODO Add check for digital products (don't add to shipment) //retVal.Items = order.Items.Where(x => !shippedLineItemIds.Contains(x.Id)) // .Select(x => new coreModel.ShipmentItem(x)).ToList(); //return Ok(retVal.ToWebModel()); } return(NotFound()); }
protected virtual async Task EnsureThatAllOperationsHaveNumber(CustomerOrder order) { var store = await _storeService.GetByIdAsync(order.StoreId, StoreResponseGroup.StoreInfo.ToString()); foreach (var operation in order.GetFlatObjectsListWithInterface <IOperation>()) { if (operation.Number == null) { var objectTypeName = operation.OperationType; // take uppercase chars to form operation type, or just take 2 first chars. (CustomerOrder => CO, PaymentIn => PI, Shipment => SH) var opType = string.Concat(objectTypeName.Select(c => char.IsUpper(c) ? c.ToString() : "")); if (opType.Length < 2) { opType = objectTypeName.Substring(0, 2).ToUpper(); } var numberTemplate = opType + "{0:yyMMdd}-{1:D5}"; if (store != null) { numberTemplate = store.Settings.GetSettingValue("Order." + objectTypeName + "NewNumberTemplate", numberTemplate); } operation.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); } } }
public virtual async Task <Subscription> TryCreateSubscriptionFromOrderAsync(CustomerOrder order) { Subscription retVal = null; PaymentPlan paymentPlan = null; if (!string.IsNullOrEmpty(order.ShoppingCartId)) { //Retrieve payment plan with id as the same order original shopping cart id paymentPlan = (await _paymentPlanService.GetByIdsAsync(new[] { order.ShoppingCartId })).FirstOrDefault(); } if (paymentPlan == null) { //Try to create subscription if order line item with have defined PaymentPlan //TODO: On the right must also be taken into account when the situation in the order contains items with several different plans paymentPlan = (await _paymentPlanService.GetByIdsAsync(order.Items.Select(x => x.ProductId).ToArray())).FirstOrDefault(); } //Generate numbers for new subscriptions var store = await _storeService.GetByIdAsync(order.StoreId); var numberTemplate = store.Settings.GetSettingValue("Subscription.SubscriptionNewNumberTemplate", "SU{0:yyMMdd}-{1:D5}"); if (paymentPlan != null) { var now = DateTime.UtcNow; //There need to make "prototype" for future orders which will be created by subscription schedule information retVal = AbstractTypeFactory <Subscription> .TryCreateInstance <Subscription>(); retVal.StoreId = order.StoreId; retVal.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); retVal.CustomerOrderPrototype = CloneCustomerOrder(order); //Need to prevent subscription creation for prototype order in CreateSubscriptionHandler retVal.CustomerOrderPrototype.Number = retVal.Number; retVal.CustomerOrderPrototype.IsPrototype = true; retVal.CustomerId = order.CustomerId; retVal.CustomerName = order.CustomerName; retVal.Interval = paymentPlan.Interval; retVal.IntervalCount = paymentPlan.IntervalCount; retVal.StartDate = now; retVal.CurrentPeriodStart = now; retVal.TrialPeriodDays = paymentPlan.TrialPeriodDays; retVal.SubscriptionStatus = SubscriptionStatus.Active; retVal.CurrentPeriodEnd = GetPeriodEnd(now, paymentPlan.Interval, paymentPlan.IntervalCount); if (retVal.TrialPeriodDays > 0) { retVal.TrialSart = now; retVal.TrialEnd = GetPeriodEnd(now, PaymentInterval.Days, retVal.TrialPeriodDays); //For trial need to shift start and end period retVal.CurrentPeriodStart = retVal.TrialEnd; retVal.CurrentPeriodEnd = GetPeriodEnd(retVal.TrialEnd.Value, paymentPlan.Interval, paymentPlan.IntervalCount); } retVal.CustomerOrders = new List <CustomerOrder> { order }; } return(retVal); }
public virtual async Task SaveSubscriptionsAsync(Subscription[] subscriptions) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Subscription> >(); using (var repository = _subscriptionRepositoryFactory()) { var existEntities = await repository.GetSubscriptionsByIdsAsync(subscriptions.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { //Generate numbers for new subscriptions if (string.IsNullOrEmpty(subscription.Number)) { var store = await _storeService.GetByIdAsync(subscription.StoreId, StoreResponseGroup.StoreInfo.ToString()); var numberTemplate = store.Settings.GetSettingValue(ModuleConstants.Settings.General.NewNumberTemplate.Name, ModuleConstants.Settings.General.NewNumberTemplate.DefaultValue.ToString()); subscription.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); } //Save subscription order prototype with same as subscription Number if (subscription.CustomerOrderPrototype != null) { subscription.CustomerOrderPrototype.Number = subscription.Number; subscription.CustomerOrderPrototype.IsPrototype = true; await _customerOrderService.SaveChangesAsync(new[] { subscription.CustomerOrderPrototype }); } var originalEntity = existEntities.FirstOrDefault(x => x.Id == subscription.Id); var modifiedEntity = AbstractTypeFactory <SubscriptionEntity> .TryCreateInstance().FromModel(subscription, pkMap); if (originalEntity != null) { changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()), EntryState.Modified)); modifiedEntity.Patch(originalEntity); //force the subscription.ModifiedDate update, because the subscription object may not have any changes in its properties originalEntity.ModifiedDate = DateTime.UtcNow; } else { repository.Add(modifiedEntity); changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, EntryState.Added)); } } //Raise domain events await _eventPublisher.Publish(new SubscriptionChangingEvent(changedEntries)); await repository.UnitOfWork.CommitAsync(); pkMap.ResolvePrimaryKeys(); ClearCacheFor(subscriptions); await _eventPublisher.Publish(new SubscriptionChangedEvent(changedEntries)); } }
private void EnsureThatQuoteHasNumber(QuoteRequest[] quoteRequests) { foreach (var quoteRequest in quoteRequests) { if (String.IsNullOrEmpty(quoteRequest.Number)) { quoteRequest.Number = _uniqueNumberGenerator.GenerateNumber("RFQ{0:yyMMdd}-{1:D5}"); } } }
private void EnsureThatQuoteHasNumber(QuoteRequest[] quoteRequests) { foreach (var quoteRequest in quoteRequests) { if (string.IsNullOrEmpty(quoteRequest.Number)) { var numberTemplate = _settingManager.GetValue("Quotes.QuoteRequestNewNumberTemplate", "RFQ{0:yyMMdd}-{1:D5}"); quoteRequest.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); } } }
public void SaveSubscriptions(Subscription[] subscriptions) { var pkMap = new PrimaryKeyResolvingMap(); var changedEntries = new List <GenericChangedEntry <Subscription> >(); using (var repository = _subscriptionRepositoryFactory()) using (var changeTracker = GetChangeTracker(repository)) { var existEntities = repository.GetSubscriptionsByIds(subscriptions.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var subscription in subscriptions) { //Generate numbers for new subscriptions if (string.IsNullOrEmpty(subscription.Number)) { var store = _storeService.GetById(subscription.StoreId); var numberTemplate = store.Settings.GetSettingValue("Subscription.SubscriptionNewNumberTemplate", "SU{0:yyMMdd}-{1:D5}"); subscription.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); } //Save subscription order prototype with same as subscription Number if (subscription.CustomerOrderPrototype != null) { subscription.CustomerOrderPrototype.Number = subscription.Number; subscription.CustomerOrderPrototype.IsPrototype = true; _customerOrderService.SaveChanges(new[] { subscription.CustomerOrderPrototype }); } var originalEntity = existEntities.FirstOrDefault(x => x.Id == subscription.Id); var originalSubscription = originalEntity != null?originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()) : subscription; var modifiedEntity = AbstractTypeFactory <SubscriptionEntity> .TryCreateInstance() .FromModel(subscription, pkMap) as SubscriptionEntity; if (originalEntity != null) { changeTracker.Attach(originalEntity); changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, originalEntity.ToModel(AbstractTypeFactory <Subscription> .TryCreateInstance()), EntryState.Modified)); modifiedEntity.Patch(originalEntity); //force the subscription.ModifiedDate update, because the subscription object may not have any changes in its properties originalEntity.ModifiedDate = DateTime.UtcNow; } else { repository.Add(modifiedEntity); changedEntries.Add(new GenericChangedEntry <Subscription>(subscription, EntryState.Added)); } } //Raise domain events _eventPublisher.Publish(new SubscriptionChangingEvent(changedEntries)); CommitChanges(repository); pkMap.ResolvePrimaryKeys(); _eventPublisher.Publish(new SubscriptionChangedEvent(changedEntries)); } }
private async Task EnsureThatQuoteHasNumber(QuoteRequest[] quoteRequests) { var stores = await _storeService.GetByIdsAsync(quoteRequests.Select(x => x.StoreId).Distinct().ToArray()); foreach (var quoteRequest in quoteRequests) { if (string.IsNullOrEmpty(quoteRequest.Number)) { var store = stores.FirstOrDefault(x => x.Id == quoteRequest.StoreId); var numberTemplate = "RFQ{0:yyMMdd}-{1:D5}"; if (store != null) { numberTemplate = store.Settings.GetSettingValue("Quotes.QuoteRequestNewNumberTemplate", numberTemplate); } quoteRequest.Number = _uniqueNumberGenerator.GenerateNumber(numberTemplate); } } }
private void EnsureThatAllOperationsHaveNumber(CustomerOrder order) { foreach (var operation in order.GetFlatObjectsListWithInterface <IOperation>()) { if (operation.Number == null) { var objectTypeName = operation.GetType().Name; // take upercase chars to form operation type, or just take 2 first chars. (CustomerOrder => CO, PaymentIn => PI, Shipment => SH) var objectType = string.Concat(objectTypeName.Select(c => char.IsUpper(c) ? c.ToString() : "")); if (objectType.Length < 2) { objectType = objectTypeName.Substring(0, 2).ToUpper(); } operation.Number = _uniqueNumberGenerator.GenerateNumber(objectType + "{0:yyMMdd}-{1:D5}"); } } }