public AddItemsToSalesOrderCommand(string id, Sku sku, uint quantity, Money unitPrice) { Id = id; Sku = sku; Quantity = quantity; UnitPrice = unitPrice; }
public void AddItem(Sku sku, uint quantity, Money unitPrice) { /* 1. Guard clauses */ if (sku == null) throw new ArgumentNullException("sku"); if (unitPrice == null) throw new ArgumentNullException("unitPrice"); if (OrderValue != null && unitPrice.Currency != OrderValue.Currency) { throw new ArgumentException( string.Format( "Unable to mix currencies on an order (SalesOrder value: {0}, supplied unit price: {1}", OrderValue, unitPrice)); } /* 2. Invariants */ // Would these items take the order over it's max? Money itemsValue = quantity * unitPrice; if ((OrderValue + itemsValue) > MaxCustomerOrderValue) { throw new InvalidOperationException( string.Format( "Adding items with value of {0} would take the current order value of {1} over the customer allowed maximum of {2}", itemsValue, OrderValue, MaxCustomerOrderValue)); } /* 3. Update state */ OrderValue += quantity * unitPrice; Lines.Add(new SalesOrderLine(sku, quantity, unitPrice)); }
/// <summary> /// Handles the Click event of the btnSaveInventory control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnSaveInventory_Click(object sender, EventArgs e) { try { int inventory = 0; TextBox textBox; int skuId = 0; foreach (DataGridItem item in dgSkuInventory.Items) { textBox = item.FindControl("txtInventory") as TextBox; int.TryParse(textBox.Text, out inventory); int.TryParse(dgSkuInventory.DataKeys[item.ItemIndex].ToString(), out skuId); if (skuId > 0) { Sku sku = new Sku(skuId); sku.Inventory = inventory; sku.Save(WebUtility.GetUserName()); skuId = 0; } } product.AllowNegativeInventories = chkAllowNegativeInventories.Checked; product.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveProductFromCache(productId); base.MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblInventoriesSaved")); } catch(Exception ex) { Logger.Error(typeof(sku).Name + ".btnSaveInventory_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); Sku sku = null; if (!string.IsNullOrWhiteSpace(this.SkuName)) { sku = new Sku(ParseSkuName(this.SkuName)); } Dictionary<string, string> tags = null; if (this.Tag != null) { Dictionary<string, string> tagDictionary = TagsConversionHelper.CreateTagDictionary(Tag); tags = tagDictionary ?? new Dictionary<string, string>(); } string processMessage = string.Empty; if (sku != null && tags != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateSkuAndTags, this.Name, sku.Name); } else if (sku != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateSku, this.Name, sku.Name); } else if (tags != null) { processMessage = string.Format(CultureInfo.CurrentCulture, Resources.SetAccount_ProcessMessage_UpdateTags, this.Name); } else { // Not updating anything (this is allowed) - just return the account, no need for approval. var cognitiveServicesAccount = this.CognitiveServicesClient.CognitiveServicesAccounts.GetProperties(this.ResourceGroupName, this.Name); WriteCognitiveServicesAccount(cognitiveServicesAccount); return; } if (ShouldProcess( this.Name, processMessage) || Force.IsPresent) { RunCmdLet(() => { var updatedAccount = this.CognitiveServicesClient.CognitiveServicesAccounts.Update( this.ResourceGroupName, this.Name, sku, tags); WriteCognitiveServicesAccount(updatedAccount); }); } }
public ItemsAddedToSalesOrderEvent(string orderId, Sku sku, uint quantity, Money unitPrice, DateTimeOffset date) : base(orderId, date) { if (orderId == null) throw new ArgumentNullException("orderId"); if (sku == null) throw new ArgumentNullException("sku"); if (unitPrice == null) throw new ArgumentNullException("unitPrice"); OrderId = orderId; Sku = sku; Quantity = quantity; UnitPrice = unitPrice; }
public void AddItem(Sku sku, uint quantity, Money unitPrice) { if (sku == null) throw new ArgumentNullException("sku"); if (unitPrice == null) throw new ArgumentNullException("unitPrice"); if (_orderValue != null && unitPrice.Currency != _orderValue.Currency) { throw new ArgumentException(string.Format("Unable to mix currencies on an order (SalesOrder value: {0}, supplied unit price: {1}", _orderValue, unitPrice)); } Money itemsValue = (quantity * unitPrice); if ((_orderValue + itemsValue) > _maxCustomerOrderValue) { throw new InvalidOperationException(string.Format("Adding items with value of {0} would take the current order value of {1} over the customer allowed maximum of {2}", itemsValue, _orderValue, _maxCustomerOrderValue)); } Record(new ItemsAddedToSalesOrderEvent(Id, sku, quantity, unitPrice, DateTimeOffset.Now)); }
/// <summary> /// Long running put request with non resource. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sku'> /// Sku to put /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task<Sku> PutAsyncNonResourceAsync( this ILROsOperations operations, Sku sku = default(Sku), CancellationToken cancellationToken = default(CancellationToken)) { AzureOperationResponse<Sku> result = await operations.PutAsyncNonResourceWithHttpMessagesAsync(sku, null, cancellationToken).ConfigureAwait(false); return result.Body; }
/// <summary> /// Handles the ItemDataBound event of the rptrCart control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> void rptrCart_ItemDataBound(object sender, RepeaterItemEventArgs e) { OrderItem orderItem = e.Item.DataItem as OrderItem; Product product = new Product(orderItem.ProductId); TextBox quantityTextBox = e.Item.FindControl("txtQuantity") as TextBox; DropDownList quantityDropDownList = e.Item.FindControl("ddlQuantity") as DropDownList; FilteredTextBoxExtender filteredTextBoxExtender = e.Item.FindControl("ftbeQuantity") as FilteredTextBoxExtender; if (quantityTextBox != null) { if(this.IsEditable) { if(product.AllowNegativeInventories) { quantityDropDownList.Visible = false; quantityTextBox.Text = orderItem.Quantity.ToString(); } else { quantityTextBox.Visible = false; filteredTextBoxExtender.Enabled = false; Sku sku = new Sku("Sku", orderItem.Sku); for(int i = 1;i <= sku.Inventory;i++) { quantityDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString())); } //Inventory may have changed, so try to set it, but we may have to reset it if(quantityDropDownList.Items.FindByValue(orderItem.Quantity.ToString()) != null) { quantityDropDownList.SelectedValue = orderItem.Quantity.ToString(); } else { quantityDropDownList.SelectedIndex = 0; } } } else { quantityDropDownList.Visible = false; quantityTextBox.Text = orderItem.Quantity.ToString(); quantityTextBox.CssClass = "readOnly"; quantityTextBox.ReadOnly = true; } } }
public bool Equals(Sku other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.Value, Value); }
public PSNamespaceAttributes(EHNamespace evResource) { if (evResource != null) { Sku = new Sku { Capacity = evResource.Sku.Capacity, Name = evResource.Sku.Name, Tier = evResource.Sku.Tier }; if (evResource.ProvisioningState != null) { ProvisioningState = evResource.ProvisioningState; } if (evResource.CreatedAt.HasValue) { CreatedAt = evResource.CreatedAt; } if (evResource.UpdatedAt.HasValue) { UpdatedAt = evResource.UpdatedAt; } if (evResource.ServiceBusEndpoint != null) { ServiceBusEndpoint = evResource.ServiceBusEndpoint; } if (evResource.Location != null) { Location = evResource.Location; } if (evResource.Id != null) { Id = evResource.Id; } if (evResource.Name != null) { Name = evResource.Name; } if (evResource.IsAutoInflateEnabled.HasValue) { IsAutoInflateEnabled = evResource.IsAutoInflateEnabled; } if (evResource.MaximumThroughputUnits.HasValue) { MaximumThroughputUnits = evResource.MaximumThroughputUnits; } if (evResource.KafkaEnabled.HasValue) { KafkaEnabled = evResource.KafkaEnabled; } if (evResource.Tags.Count > 0) { Tags = new Dictionary <string, string>(evResource.Tags); } ResourceGroup = Regex.Split(evResource.Id, @"/")[4]; ResourceGroupName = Regex.Split(evResource.Id, @"/")[4]; } }
public OrderLine(Sku sku, int count, Amount itemPrice) { Sku = sku; ItemCount = count; ItemPrice = itemPrice; }
public SalesOrderLine(Sku sku, uint quantity, Money unitPrice) { Sku = sku; Quantity = quantity; UnitPrice = unitPrice; }
/// <summary> /// Long running put request with non resource. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sku'> /// sku to put /// </param> public static Sku PutNonResource(this ILROsOperations operations, Sku sku = default(Sku)) { return System.Threading.Tasks.Task.Factory.StartNew(s => ((ILROsOperations)s).PutNonResourceAsync(sku), operations, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
/// <summary> /// Refunds the specified transaction. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="refundedOrder">The refunded order.</param> /// <param name="userName">Name of the user.</param> public static void RefundStandard(Transaction transaction, Order refundedOrder, string userName) { Order order = new Order(transaction.OrderId); Transaction refundTransaction = new Transaction(); //refundTransaction.OrderId = transaction.OrderId; refundTransaction.TransactionTypeDescriptorId = (int)TransactionType.Refund; refundTransaction.PaymentMethod = PAYPAL; refundTransaction.GatewayName = PAYPAL_STANDARD; refundTransaction.GatewayResponse = SUCCESS; refundTransaction.GatewayTransactionId = CoreUtility.GenerateRandomString(16); refundTransaction.GrossAmount = refundedOrder.Total; refundTransaction.NetAmount = 0.00M; refundTransaction.FeeAmount = 0.00M; refundTransaction.TransactionDate = DateTime.Now; //refundTransaction.Save(userName); refundedOrder.Save(userName); //set the orderid for the refund foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) { orderItem.OrderId = refundedOrder.OrderId; } refundedOrder.OrderItemCollection.SaveAll(userName); //set the orderId to the refunded orderId refundTransaction.OrderId = refundedOrder.OrderId; refundTransaction.Save(userName); Guid userGuid = new Guid(Membership.GetUser(order.UserName).ProviderUserKey.ToString()); DownloadCollection downloadCollection; foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) { //put the stock back Sku sku = new Sku(Sku.Columns.SkuX, orderItem.Sku); sku.Inventory = sku.Inventory + orderItem.Quantity; sku.Save(userName); ProductCache.RemoveSKUFromCache(orderItem.Sku); //remove the access control downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId); if (downloadCollection.Count > 0) { foreach (Download download in downloadCollection) { new DownloadAccessControlController().Delete(userGuid, download.DownloadId); } } } if(refundedOrder.Total == order.Total) { order.OrderStatusDescriptorId = (int)OrderStatus.OrderFullyRefunded; } else { order.OrderStatusDescriptorId = (int)OrderStatus.OrderPartiallyRefunded; } order.Save(userName); //Add an OrderNote OrderNote orderNote = new OrderNote(); orderNote.OrderId = order.OrderId; orderNote.Note = Strings.ResourceManager.GetString(ORDER_REFUNDED); orderNote.Save(userName); //send off the notifications MessageService messageService = new MessageService(); messageService.SendOrderRefundToCustomer(refundedOrder); }
/// <summary> /// Charges the specified order. /// </summary> /// <param name="order">The order.</param> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static Transaction Charge(Order order, string userName) { //update the order with IP order.IPAddress = HttpContext.Current.Request.UserHostAddress; PaymentService paymentService = new PaymentService(); Transaction transaction = paymentService.Charge(order); order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder; order.OrderTypeId = (int)OrderType.Purchase; order.Save(userName); Guid userGuid = new Guid(Membership.GetUser(userName).ProviderUserKey.ToString()); try { //Add an OrderNote OrderNote orderNote = new OrderNote(); orderNote.OrderId = order.OrderId; orderNote.Note = Strings.ResourceManager.GetString(ORDER_CHARGED); orderNote.Save(userName); Sku sku; DownloadCollection downloadCollection; DownloadAccessControlCollection downloadAccessControlCollection; DownloadAccessControl downloadAccessControl; foreach (OrderItem orderItem in order.OrderItemCollection) { //Adjust the Inventory sku = new Sku(SKU, orderItem.Sku); sku.Inventory = sku.Inventory - orderItem.Quantity; sku.Save(SYSTEM); ProductCache.RemoveSKUFromCache(orderItem.Sku); //Add access control for orderitems downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId); if (downloadCollection.Count > 0) { foreach (Download download in downloadCollection) { Query query = new Query(DownloadAccessControl.Schema). AddWhere(DownloadAccessControl.Columns.UserId, Comparison.Equals, userGuid). AddWhere(DownloadAccessControl.Columns.DownloadId, Comparison.Equals, download.DownloadId); downloadAccessControlCollection = new DownloadAccessControlController().FetchByQuery(query); if (downloadAccessControlCollection.Count == 0) { downloadAccessControl = new DownloadAccessControl(); downloadAccessControl.DownloadId = download.DownloadId; downloadAccessControl.UserId = userGuid; downloadAccessControl.Save(SYSTEM); } } } } //Send out the messages //Send these last in case something happens with the email MessageService messageService = new MessageService(); messageService.SendOrderReceivedNotificationToCustomer(order); messageService.SendOrderReceivedNotificationToMerchant(order); } catch (Exception ex) { //swallow the exception here because the transaction is saved //and, while this is an inconvenience, it's not critical Logger.Error(typeof(OrderController).Name + ".Charge", ex); } return transaction; }
/// <summary> /// Refunds the specified transaction. /// </summary> /// <param name="transaction">The transaction.</param> /// <param name="refundedOrder">The order the refund should be applied to.</param> /// <param name="userName">Name of the user.</param> public static void Refund(Transaction transaction, Order refundedOrder, string userName) { Order order = new Order(transaction.OrderId); PaymentService paymentService = new PaymentService(); Transaction refundTransaction = paymentService.Refund(transaction, refundedOrder); refundedOrder.Save(userName); //set the orderid for the refund foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) { orderItem.OrderId = refundedOrder.OrderId; } refundedOrder.OrderItemCollection.SaveAll(userName); //set the orderId to the refunded orderId refundTransaction.OrderId = refundedOrder.OrderId; refundTransaction.Save(userName); Guid userGuid = new Guid(Membership.GetUser(order.UserName).ProviderUserKey.ToString()); foreach(OrderItem orderItem in refundedOrder.OrderItemCollection) { new Product(orderItem.ProductId); //put the stock back Sku sku = new Sku(Sku.Columns.SkuX, orderItem.Sku); sku.Inventory = sku.Inventory + orderItem.Quantity; sku.Save(userName); ProductCache.RemoveSKUFromCache(orderItem.Sku); //remove the access control DownloadCollection downloadCollection = new ProductController().FetchAssociatedDownloadsByProductIdAndForPurchase(orderItem.ProductId); if (downloadCollection.Count > 0) { foreach (Download download in downloadCollection) { new DownloadAccessControlController().Delete(userGuid, download.DownloadId); } } } if(refundedOrder.Total == order.Total) { order.OrderStatusDescriptorId = (int)OrderStatus.OrderFullyRefunded; } else { order.OrderStatusDescriptorId = (int)OrderStatus.OrderPartiallyRefunded; } order.Save(userName); //Add an OrderNote OrderNote orderNote = new OrderNote(); orderNote.OrderId = order.OrderId; orderNote.Note = Strings.ResourceManager.GetString(ORDER_REFUNDED); orderNote.Save(userName); //send off the notifications MessageService messageService = new MessageService(); messageService.SendOrderRefundToCustomer(refundedOrder); }
/// <summary> /// Does the express checkout. /// </summary> /// <param name="order">The order.</param> /// <param name="authorizeOnly">if set to <c>true</c> [authorize only].</param> /// <param name="userName">Name of the user.</param> /// <returns></returns> public static Transaction DoExpressCheckout(Order order, bool authorizeOnly, string userName) { PaymentService paymentService = new PaymentService(); Transaction transaction = paymentService.DoExpressCheckout(order, authorizeOnly); order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder; order.Save(userName); try { //Adjust the Inventory Sku sku; foreach (OrderItem orderItem in order.OrderItemCollection) { sku = new Sku(SKU, orderItem.Sku); sku.Inventory = sku.Inventory - orderItem.Quantity; sku.Save(SYSTEM); ProductCache.RemoveSKUFromCache(orderItem.Sku); } //Send out the messages MessageService messageService = new MessageService(); messageService.SendOrderReceivedNotificationToCustomer(order); messageService.SendOrderReceivedNotificationToMerchant(order); } catch (Exception ex) { //swallow the exception here because the transaction is saved //and, while this is an inconvenience, it's not critical Logger.Error(typeof(OrderController).Name + ".DoExpressCheckout", ex); } return transaction; }
/// <summary> /// Commits the standard transaction. /// </summary> /// <param name="order">The order.</param> /// <param name="transactionId">The transaction id.</param> /// <param name="grossAmount">The gross amount.</param> /// <returns></returns> public static Transaction CommitStandardTransaction(Order order, string transactionId, decimal grossAmount) { order.OrderStatusDescriptorId = (int)OrderStatus.ReceivedPaymentProcessingOrder; order.Save(SYSTEM); Transaction transaction = new Transaction(); transaction.OrderId = order.OrderId; transaction.TransactionTypeDescriptorId = (int)TransactionType.Charge; transaction.PaymentMethod = PAYPAL; transaction.GatewayName = PAYPAL_STANDARD; transaction.GatewayResponse = SUCCESS; transaction.GatewayTransactionId = transactionId; transaction.GrossAmount = grossAmount; transaction.TransactionDate = DateTime.UtcNow; transaction.Save(SYSTEM); try { //Adjust the Inventory Sku sku; foreach (OrderItem orderItem in order.OrderItemCollection) { sku = new Sku("Sku", orderItem.Sku); sku.Inventory = sku.Inventory - orderItem.Quantity; sku.Save("System"); ProductCache.RemoveSKUFromCache(orderItem.Sku); } //Send out the messages MessageService messageService = new MessageService(); messageService.SendOrderReceivedNotificationToCustomer(order); messageService.SendOrderReceivedNotificationToMerchant(order); } catch (Exception ex) { //swallow the exception here because the transaction is saved //and, while this is an inconvenience, it's not critical Logger.Error(typeof(OrderController).Name + ".CommitStandardTransaction", ex); } return transaction; }
protected void rptShoppingCart_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lblSkuCode = e.Item.FindControl("lblSkuCode") as Label; Label lblSkuDescription = e.Item.FindControl("lblSkuDescription") as Label; TextBox txtQuantity = e.Item.FindControl("txtQuantity") as TextBox; //Label lblQuantity = e.Item.FindControl("lblQuantity") as Label; Label lblSkuInitialPrice = e.Item.FindControl("lblSkuInitialPrice") as Label; ImageButton btnRemoveItem = e.Item.FindControl("btnRemoveItem") as ImageButton; HtmlContainerControl holderQuantity = e.Item.FindControl("holderQuantity") as HtmlContainerControl; HtmlContainerControl holderRemove = e.Item.FindControl("holderRemove") as HtmlContainerControl; Image imgProduct = e.Item.FindControl("imgProduct") as Image; Sku cartItem = e.Item.DataItem as Sku; lblSkuDescription.Text = cartItem.ShortDescription; //lblQuantity.Text = txtQuantity.Text = cartItem.Quantity.ToString(); lblSkuInitialPrice.Text = String.Format("${0:0.##}", cartItem.InitialPrice); if (cartItem.ImagePath != null && cartItem.ImagePath.Length > 0) { imgProduct.ImageUrl = cartItem.ImagePath; lblSkuCode.Visible = false; } else { imgProduct.Visible = false; lblSkuCode.Text = cartItem.SkuCode.ToString(); } btnRemoveItem.CommandArgument = cartItem.SkuId.ToString(); //txtQuantity.Attributes["onchange"] = Page.ClientScript.GetPostBackEventReference(refresh, ""); switch (QuantityMode) { case ShoppingCartQuanityMode.Hidden: holderQuantity.Visible = false; break; //case ShoppingCartQuanityMode.Editable: // lblQuantity.Visible = false; // break; //case ShoppingCartQuanityMode.Readonly: // txtQuantity.Visible = false; // break; default: break; } if (HideRemoveButton) { holderRemove.Visible = false; } } else if (e.Item.ItemType == ListItemType.Header) { HtmlContainerControl holderHeaderQuantity = e.Item.FindControl("holderHeaderQuantity") as HtmlContainerControl; HtmlContainerControl holderHeaderRemove = e.Item.FindControl("holderHeaderRemove") as HtmlContainerControl; if (QuantityMode == ShoppingCartQuanityMode.Hidden) { holderHeaderQuantity.Visible = false; } if (HideRemoveButton) { holderHeaderRemove.Visible = false; } } }
/// <summary> /// Long running put request with non resource. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sku'> /// Sku to put /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task<Sku> BeginPutAsyncNonResourceAsync(this ILROsOperations operations, Sku sku = default(Sku), CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginPutAsyncNonResourceWithHttpMessagesAsync(sku, null, cancellationToken).ConfigureAwait(false)) { return _result.Body; } }
public void Insert(int ProductId,string SkuX,int Inventory,string CreatedBy,string CreatedOn,string ModifiedBy,string ModifiedOn) { Sku item = new Sku(); item.ProductId = ProductId; item.SkuX = SkuX; item.Inventory = Inventory; item.CreatedBy = CreatedBy; item.CreatedOn = CreatedOn; item.ModifiedBy = ModifiedBy; item.ModifiedOn = ModifiedOn; item.Save(UserName); }
private void Run() { // Sku Sku vSku = null; // Plan Plan vPlan = null; // UpgradePolicy UpgradePolicy vUpgradePolicy = null; // AutomaticRepairsPolicy AutomaticRepairsPolicy vAutomaticRepairsPolicy = null; // VirtualMachineProfile PSVirtualMachineScaleSetVMProfile vVirtualMachineProfile = null; // ProximityPlacementGroup SubResource vProximityPlacementGroup = null; // AdditionalCapabilities AdditionalCapabilities vAdditionalCapabilities = null; // ScaleInPolicy ScaleInPolicy vScaleInPolicy = null; // Identity VirtualMachineScaleSetIdentity vIdentity = null; // ExtendedLocation CM.PSExtendedLocation vExtendedLocation = null; if (this.IsParameterBound(c => c.SkuName)) { if (vSku == null) { vSku = new Sku(); } vSku.Name = this.SkuName; } if (this.IsParameterBound(c => c.SkuTier)) { if (vSku == null) { vSku = new Sku(); } vSku.Tier = this.SkuTier; } if (this.IsParameterBound(c => c.SkuCapacity)) { if (vSku == null) { vSku = new Sku(); } vSku.Capacity = this.SkuCapacity; } if (this.IsParameterBound(c => c.PlanName)) { if (vPlan == null) { vPlan = new Plan(); } vPlan.Name = this.PlanName; } if (this.IsParameterBound(c => c.PlanPublisher)) { if (vPlan == null) { vPlan = new Plan(); } vPlan.Publisher = this.PlanPublisher; } if (this.IsParameterBound(c => c.PlanProduct)) { if (vPlan == null) { vPlan = new Plan(); } vPlan.Product = this.PlanProduct; } if (this.IsParameterBound(c => c.PlanPromotionCode)) { if (vPlan == null) { vPlan = new Plan(); } vPlan.PromotionCode = this.PlanPromotionCode; } if (this.IsParameterBound(c => c.UpgradePolicyMode)) { if (vUpgradePolicy == null) { vUpgradePolicy = new UpgradePolicy(); } vUpgradePolicy.Mode = this.UpgradePolicyMode; } if (this.IsParameterBound(c => c.RollingUpgradePolicy)) { if (vUpgradePolicy == null) { vUpgradePolicy = new UpgradePolicy(); } vUpgradePolicy.RollingUpgradePolicy = this.RollingUpgradePolicy; } if (this.AutoOSUpgrade.IsPresent) { if (vUpgradePolicy == null) { vUpgradePolicy = new UpgradePolicy(); } if (vUpgradePolicy.AutomaticOSUpgradePolicy == null) { vUpgradePolicy.AutomaticOSUpgradePolicy = new AutomaticOSUpgradePolicy(); } vUpgradePolicy.AutomaticOSUpgradePolicy.EnableAutomaticOSUpgrade = this.AutoOSUpgrade.IsPresent; } if (this.EnableAutomaticRepair.IsPresent) { if (vAutomaticRepairsPolicy == null) { vAutomaticRepairsPolicy = new AutomaticRepairsPolicy(); } vAutomaticRepairsPolicy.Enabled = this.EnableAutomaticRepair.IsPresent; } if (this.EncryptionAtHost.IsPresent) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.SecurityProfile == null) { vVirtualMachineProfile.SecurityProfile = new SecurityProfile(); } vVirtualMachineProfile.SecurityProfile.EncryptionAtHost = this.EncryptionAtHost; } if (this.IsParameterBound(c => c.CapacityReservationGroupId)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.CapacityReservation == null) { vVirtualMachineProfile.CapacityReservation = new CapacityReservationProfile(); } vVirtualMachineProfile.CapacityReservation.CapacityReservationGroup = new SubResource(this.CapacityReservationGroupId); } if (this.IsParameterBound(c => c.AutomaticRepairGracePeriod)) { if (vAutomaticRepairsPolicy == null) { vAutomaticRepairsPolicy = new AutomaticRepairsPolicy(); } vAutomaticRepairsPolicy.GracePeriod = this.AutomaticRepairGracePeriod; } if (this.IsParameterBound(c => c.DisableAutoRollback)) { if (vUpgradePolicy == null) { vUpgradePolicy = new UpgradePolicy(); } if (vUpgradePolicy.AutomaticOSUpgradePolicy == null) { vUpgradePolicy.AutomaticOSUpgradePolicy = new AutomaticOSUpgradePolicy(); } vUpgradePolicy.AutomaticOSUpgradePolicy.DisableAutomaticRollback = this.DisableAutoRollback; } if (this.IsParameterBound(c => c.OsProfile)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.OsProfile = this.OsProfile; } if (this.IsParameterBound(c => c.StorageProfile)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.StorageProfile = this.StorageProfile; } if (this.IsParameterBound(c => c.HealthProbeId)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.NetworkProfile == null) { vVirtualMachineProfile.NetworkProfile = new VirtualMachineScaleSetNetworkProfile(); } if (vVirtualMachineProfile.NetworkProfile.HealthProbe == null) { vVirtualMachineProfile.NetworkProfile.HealthProbe = new ApiEntityReference(); } vVirtualMachineProfile.NetworkProfile.HealthProbe.Id = this.HealthProbeId; } if (this.IsParameterBound(c => c.NetworkInterfaceConfiguration)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.NetworkProfile == null) { vVirtualMachineProfile.NetworkProfile = new VirtualMachineScaleSetNetworkProfile(); } vVirtualMachineProfile.NetworkProfile.NetworkInterfaceConfigurations = this.NetworkInterfaceConfiguration; } if (this.IsParameterBound(c => c.BootDiagnostic)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.DiagnosticsProfile == null) { vVirtualMachineProfile.DiagnosticsProfile = new DiagnosticsProfile(); } vVirtualMachineProfile.DiagnosticsProfile.BootDiagnostics = this.BootDiagnostic; } if (this.IsParameterBound(c => c.Extension)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.ExtensionProfile == null) { vVirtualMachineProfile.ExtensionProfile = new PSVirtualMachineScaleSetExtensionProfile(); } vVirtualMachineProfile.ExtensionProfile.Extensions = this.Extension; } if (this.IsParameterBound(c => c.LicenseType)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.LicenseType = this.LicenseType; } if (this.IsParameterBound(c => c.Priority)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.Priority = this.Priority; } if (this.IsParameterBound(c => c.EvictionPolicy)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.EvictionPolicy = this.EvictionPolicy; } if (this.IsParameterBound(c => c.MaxPrice)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.BillingProfile == null) { vVirtualMachineProfile.BillingProfile = new BillingProfile(); } vVirtualMachineProfile.BillingProfile.MaxPrice = this.MaxPrice; } if (this.TerminateScheduledEvents.IsPresent) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.ScheduledEventsProfile == null) { vVirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile(); } if (vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile == null) { vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile = new TerminateNotificationProfile(); } vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile.Enable = this.TerminateScheduledEvents.IsPresent; } if (this.IsParameterBound(c => c.TerminateScheduledEventNotBeforeTimeoutInMinutes)) { if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } if (vVirtualMachineProfile.ScheduledEventsProfile == null) { vVirtualMachineProfile.ScheduledEventsProfile = new ScheduledEventsProfile(); } if (vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile == null) { vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile = new TerminateNotificationProfile(); } vVirtualMachineProfile.ScheduledEventsProfile.TerminateNotificationProfile.NotBeforeTimeout = XmlConvert.ToString(new TimeSpan(0, this.TerminateScheduledEventNotBeforeTimeoutInMinutes, 0)); } if (this.IsParameterBound(c => c.ProximityPlacementGroupId)) { if (vProximityPlacementGroup == null) { vProximityPlacementGroup = new SubResource(); } vProximityPlacementGroup.Id = this.ProximityPlacementGroupId; } if (this.EnableUltraSSD.IsPresent) { if (vAdditionalCapabilities == null) { vAdditionalCapabilities = new AdditionalCapabilities(true); } } if (this.IsParameterBound(c => c.ScaleInPolicy)) { if (vScaleInPolicy == null) { vScaleInPolicy = new ScaleInPolicy(); } vScaleInPolicy.Rules = this.ScaleInPolicy; } if (this.IsParameterBound(c => c.IdentityType)) { if (vIdentity == null) { vIdentity = new VirtualMachineScaleSetIdentity(); } vIdentity.Type = this.IdentityType; } if (this.IsParameterBound(c => c.IdentityId)) { if (vIdentity == null) { vIdentity = new VirtualMachineScaleSetIdentity(); } vIdentity.UserAssignedIdentities = new Dictionary <string, VirtualMachineScaleSetIdentityUserAssignedIdentitiesValue>(); foreach (var id in this.IdentityId) { vIdentity.UserAssignedIdentities.Add(id, new VirtualMachineScaleSetIdentityUserAssignedIdentitiesValue()); } } if (this.IsParameterBound(c => c.EdgeZone)) { vExtendedLocation = new CM.PSExtendedLocation(this.EdgeZone); } if (this.IsParameterBound(c => c.UserData)) { if (!ValidateBase64EncodedString.ValidateStringIsBase64Encoded(this.UserData)) { this.UserData = ValidateBase64EncodedString.EncodeStringToBase64(this.UserData); this.WriteInformation(ValidateBase64EncodedString.UserDataEncodeNotification, new string[] { "PSHOST" }); } if (vVirtualMachineProfile == null) { vVirtualMachineProfile = new PSVirtualMachineScaleSetVMProfile(); } vVirtualMachineProfile.UserData = this.UserData; } if (this.IsParameterBound(c => c.AutomaticRepairAction)) { if (vAutomaticRepairsPolicy == null) { vAutomaticRepairsPolicy = new AutomaticRepairsPolicy(); } vAutomaticRepairsPolicy.RepairAction = this.AutomaticRepairAction; } var vVirtualMachineScaleSet = new PSVirtualMachineScaleSet { Overprovision = this.IsParameterBound(c => c.Overprovision) ? this.Overprovision : (bool?)null, DoNotRunExtensionsOnOverprovisionedVMs = this.SkipExtensionsOnOverprovisionedVMs.IsPresent ? true : (bool?)null, SinglePlacementGroup = this.IsParameterBound(c => c.SinglePlacementGroup) ? this.SinglePlacementGroup : (bool?)null, ZoneBalance = this.ZoneBalance.IsPresent ? true : (bool?)null, PlatformFaultDomainCount = this.IsParameterBound(c => c.PlatformFaultDomainCount) ? this.PlatformFaultDomainCount : (int?)null, Zones = this.IsParameterBound(c => c.Zone) ? this.Zone : null, Location = this.IsParameterBound(c => c.Location) ? this.Location : null, ExtendedLocation = vExtendedLocation, Tags = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null, Sku = vSku, Plan = vPlan, UpgradePolicy = vUpgradePolicy, AutomaticRepairsPolicy = vAutomaticRepairsPolicy, VirtualMachineProfile = vVirtualMachineProfile, ProximityPlacementGroup = vProximityPlacementGroup, AdditionalCapabilities = vAdditionalCapabilities, ScaleInPolicy = vScaleInPolicy, Identity = vIdentity, OrchestrationMode = this.IsParameterBound(c => c.OrchestrationMode) ? this.OrchestrationMode : null, SpotRestorePolicy = this.IsParameterBound(c => c.EnableSpotRestore) ? new SpotRestorePolicy(true, this.SpotRestoreTimeout) : null }; WriteObject(vVirtualMachineScaleSet); }
/// <summary> /// Long running put request with non resource. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sku'> /// sku to put /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async System.Threading.Tasks.Task<Sku> PutNonResourceAsync(this ILROsOperations operations, Sku sku = default(Sku), System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { using (var _result = await operations.PutNonResourceWithHttpMessagesAsync(sku, null, cancellationToken).ConfigureAwait(false)) { return _result.Body; } }
private void GetTemplateSelections(ref Dictionary <int, int> skusAndQuantities) { #region Sample XML /* * <TemplateDetails> * <SelectionParameters> * <FixedSkuEntryFields useCondition="cond1" type="onepay"> * <Sku Id="36"> * <Field what="quantity" name="SKU36QTY" /> * </Sku> * <Sku Id="39"> * <Field what="quantity" name="SKU39QTY" defaultValue /> * </Sku> * </FixedSkuEntryFields> * <FixedSkuEntryFields useCondition="cond2"> * <Sku Id="40"> * <Field what="quantity" name="SKU40QTY" /> * </Sku> * </FixedSkuEntryFields> * <Conditions> * <Condition key="cond1"> * <FieldMatch name="userSelection" isRegex="false">one</FieldMatch> * </Condition> * <Condition key="cond2"> * <FieldMatch name="userSelection" isRegex="false">two</FieldMatch> * </Condition> * </Conditions> * </SelectionParameters> * </TemplateDetails> * */ #endregion XElement templateTags = XElement.Parse(((Template)(new PathManager().GetTemplate(AllTemplates[CurrentTemplateIndex]))).Tag); // search "sku and select fields" information foreach (var r in templateTags.XPathSelectElements("//selectionparameters/fixedskuentryfields")) { if (r.Attribute("type") != null && r.Attribute("type").Value.Equals("onepay")) { Order orderItem = new OrderManager().GetBatchProcessOrders(CartContext.OrderId); foreach (Sku s in orderItem.SkuItems) { s.LoadAttributeValues(); try { if (s.AttributeValues["relatedonepaysku"] != null && !s.AttributeValues["relatedonepaysku"].Value.Equals("")) { int skuId = Convert.ToInt32(s.AttributeValues["relatedonepaysku"].Value); skusAndQuantities.Add(skuId, 1); } } catch { } } foreach (Sku s in CartContext.CartInfo.CartItems) { s.LoadAttributeValues(); try { if (s.AttributeValues["relatedonepaysku"] != null && !s.AttributeValues["relatedonepaysku"].Value.Equals("")) { int skuId = Convert.ToInt32(s.AttributeValues["relatedonepaysku"].Value); skusAndQuantities.Add(skuId, 1); } } catch { } } } else { if (r.Attribute("usecondition") == null || MatchesCondition(templateTags.XPathSelectElement("//selectionparameters/conditions"), r.Attribute("usecondition").Value)) { foreach (var s in r.XPathSelectElements("sku")) { int skuId = Convert.ToInt32(s.Attribute("id").Value); string fieldName = null; // read quantity int quantity = 0; XElement quantField = s.XPathSelectElement("field[@what = 'quantity']"); if (quantField != null) { if (quantField.Attribute("name") != null) { fieldName = quantField.Attribute("name").Value; if (int.TryParse(Request.Form[fieldName], out quantity)) { skusAndQuantities.Add(skuId, quantity); } } else if (quantField.Attribute("skuid") != null) { Sku matchSku = CartContext.CartInfo.CartItems.FirstOrDefault(x => { return(x.SkuId == int.Parse(quantField.Attribute("skuid").Value)); }); if (matchSku != null) { skusAndQuantities.Add(skuId, matchSku.Quantity); } else { skusAndQuantities.Add(skuId, Convert.ToInt32((quantField.Attribute("defaultvalue") ?? new XAttribute("0", "0")).Value)); } } else { skusAndQuantities.Add(skuId, Convert.ToInt32((quantField.Attribute("defaultvalue") ?? new XAttribute("0", "0")).Value)); } } } } } } }
/// <summary> /// Long running put request with non resource. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='sku'> /// Sku to put /// </param> public static Sku BeginPutAsyncNonResource(this ILROsOperations operations, Sku sku = default(Sku)) { return Task.Factory.StartNew(s => ((ILROsOperations)s).BeginPutAsyncNonResourceAsync(sku), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
protected void rptShoppingCart_OnItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lblSkuCode = e.Item.FindControl("lblSkuCode") as Label; Label lblSkuDescription = e.Item.FindControl("lblSkuDescription") as Label; TextBox txtQuantity = e.Item.FindControl("txtQuantity") as TextBox; Label lblQuantity = e.Item.FindControl("lblQuantity") as Label; Label lblSkuInitialPrice = e.Item.FindControl("lblSkuInitialPrice") as Label; ImageButton btnRemoveItem = e.Item.FindControl("btnRemoveItem") as ImageButton; HtmlContainerControl holderQuantity = e.Item.FindControl("holderQuantity") as HtmlContainerControl; HtmlContainerControl holderRemove = e.Item.FindControl("holderRemove") as HtmlContainerControl; Image imgProduct = e.Item.FindControl("imgProduct") as Image; Sku cartItem = e.Item.DataItem as Sku; lblSkuDescription.Text = cartItem.ShortDescription; lblQuantity.Text = txtQuantity.Text = cartItem.Quantity.ToString(); decimal initialPrice = cartItem.InitialPrice; if (CSWebBase.SiteBasePage.IsMainSku(cartItem.SkuId)) { // add up all initial prices of all kit bundle items foreach (Sku bundleSku in CartContext.CartInfo.CartItems.FindAll(x => x.Visible == true && CSWebBase.SiteBasePage.IsKitBundleItem(x.SkuId))) { initialPrice += bundleSku.InitialPrice; } } lblSkuInitialPrice.Text = String.Format("${0:0.##}", initialPrice); if (cartItem.ImagePath.Length > 0) { imgProduct.ImageUrl = cartItem.ImagePath; lblSkuCode.Visible = false; } else { imgProduct.Visible = false; lblSkuCode.Text = cartItem.SkuCode.ToString(); } btnRemoveItem.CommandArgument = cartItem.SkuId.ToString(); txtQuantity.Attributes["onchange"] = Page.ClientScript.GetPostBackEventReference(refresh, ""); switch (QuantityMode) { case ShoppingCartQuanityMode.Hidden: holderQuantity.Visible = false; break; case ShoppingCartQuanityMode.Editable: lblQuantity.Visible = false; break; case ShoppingCartQuanityMode.Readonly: txtQuantity.Visible = false; break; default: break; } if (HideRemoveButton) { holderRemove.Visible = false; } } else if (e.Item.ItemType == ListItemType.Header) { HtmlContainerControl holderHeaderQuantity = e.Item.FindControl("holderHeaderQuantity") as HtmlContainerControl; HtmlContainerControl holderHeaderRemove = e.Item.FindControl("holderHeaderRemove") as HtmlContainerControl; if (QuantityMode == ShoppingCartQuanityMode.Hidden) { holderHeaderQuantity.Visible = false; } if (HideRemoveButton) { holderHeaderRemove.Visible = false; } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { try { SkuCollection skuCollection = new SkuCollection(); Sku sku; if (associatedAttributeCollection != null && associatedAttributeCollection.Count > 0) CreateSkus(associatedAttributeCollection[0], 0, product.BaseSku); else skus.Add(product.BaseSku); for(int i = 0;i < skus.Count;i++) { sku = new Sku(); sku.ProductId = productId; sku.SkuX = skus[i]; skuCollection.Add(sku); } skuCollection.SaveAll(WebUtility.GetUserName()); product.IsEnabled = true; product.Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveProductFromCache(productId); SkuCollection savedSkuCollection = LoadSkuCollection(productId); if(savedSkuCollection.Count > 0) { pnlSkuList.Visible = false; pnlSkuInventory.Visible = true; } base.MasterPage.MessageCenter.DisplaySuccessMessage(LocalizationUtility.GetText("lblAttributesSaved")); } catch (Exception ex) { Logger.Error(typeof(sku).Name + ".btnSave_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Validate the object. /// </summary> /// <exception cref="ValidationException"> /// Thrown if validation fails /// </exception> public virtual void Validate() { if (NotificationSenderEmail != null) { if (NotificationSenderEmail.Length > 100) { throw new ValidationException(ValidationRules.MaxLength, "NotificationSenderEmail", 100); } } if (HostnameConfigurations != null) { foreach (var element in HostnameConfigurations) { if (element != null) { element.Validate(); } } } if (VirtualNetworkConfiguration != null) { VirtualNetworkConfiguration.Validate(); } if (AdditionalLocations != null) { foreach (var element1 in AdditionalLocations) { if (element1 != null) { element1.Validate(); } } } if (Certificates != null) { foreach (var element2 in Certificates) { if (element2 != null) { element2.Validate(); } } } if (PublisherEmail != null) { if (PublisherEmail.Length > 100) { throw new ValidationException(ValidationRules.MaxLength, "PublisherEmail", 100); } } if (PublisherName != null) { if (PublisherName.Length > 100) { throw new ValidationException(ValidationRules.MaxLength, "PublisherName", 100); } } if (Sku != null) { Sku.Validate(); } }