protected virtual string GetKeyValue([NotNull] object context, [NotNull] string key) { Assert.ArgumentNotNull(context, "context"); Assert.ArgumentNotNull(key, "key"); ActionContext actionContext = context as ActionContext; Assert.IsNotNull(actionContext, "context should be of ActionContext type."); Assert.IsNotNull(actionContext.Owner, "context.Owner cannot be null."); Assert.IsNotNull(actionContext.Owner.Page, "context.Owner.Page cannot be null."); SmartPanel smartPanel = actionContext.Owner.Page as SmartPanel; Assert.IsNotNull(smartPanel, "SmartPanel cannot be null."); return(smartPanel.Parameters[key]); }
/// <summary> /// Called when the save has click. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <exception cref="NotImplementedException">Such action is not supported.</exception> /// <exception cref="NotSupportedException">Such action is not supported.</exception> protected override void OnSaveClick(object sender, EventArgs e) { Assert.IsNotNull(this.Page, "Page cannot be null."); SmartPanel smartPanel = this.Page as SmartPanel; Assert.IsNotNull(smartPanel, "SmartPanel cannot be null."); string orderLineAction = smartPanel.Parameters[ActionKey]; Assert.IsNotNullOrEmpty(orderLineAction, "Order line action is not provided."); OrderLineActions action = (OrderLineActions)Enum.Parse(typeof(OrderLineActions), orderLineAction); if (!this.ValidateControls()) { base.OnSaveClick(sender, e); return; } ActionContext context = new ActionContext { Owner = this.Page }; IDictionary <string, object> parameters = new Dictionary <string, object>(); string message; string result; switch (action) { case OrderLineActions.Add: { this.Strategy = Ecommerce.Context.Entity.Resolve <OrderProcessingStrategy>("AddOrderLine"); Assert.IsNotNull(this.Strategy, "Cannot resolve the strategy."); this.OrderProcessor.OrderProcessingStrategy = this.Strategy; this.UblEntityResolver = this.strategyForAdding; Order order = this.UblEntityResolver.GetEntity(context) as Order; Assert.IsNotNull(order, "Order should be provided."); if (!this.CheckPrice(order)) { return; } parameters.Add("productcode", this.ProductCode); parameters.Add("quantity", this.Quantity); message = Texts.TheOrderLineHasBeenAddedToTheOrder; result = this.OrderProcessor.ProcessOrder(order, parameters); break; } case OrderLineActions.Edit: { this.Strategy = Ecommerce.Context.Entity.Resolve <OrderProcessingStrategy>("EditOrderLine"); Assert.IsNotNull(this.Strategy, "Cannot resolve the strategy."); this.OrderProcessor.OrderProcessingStrategy = this.Strategy; OrderLine orderLine = this.UblEntityResolver.GetEntity(context) as OrderLine; Assert.IsNotNull(orderLine, "OrderLine should be provided."); if (!this.CheckPrice(orderLine.Order)) { return; } parameters.Add("orderlineid", orderLine.Alias); parameters.Add("productcode", this.ProductCode); parameters.Add("quantity", this.Quantity); message = Texts.TheOrderLineHasBeenChanged; result = this.OrderProcessor.ProcessOrder(orderLine.Order, parameters); break; } default: { throw new NotSupportedException("Such action is not supported."); } } base.OnSaveClick(sender, e); if (result == OrderProcessingStrategy.SuccessfulResult) { ScriptManager.GetCurrent(this.Page).Message(new Message(message) { Sticky = false, Type = MessageType.Info }); } else if (result == OrderProcessingStrategy.CustomResults.OutOfStock.ToString()) { ScriptManager.GetCurrent(this.Page).Message(new Message(Texts.TheProductIsOutOfStock) { Sticky = false, Type = MessageType.Error }); } }