Exemplo n.º 1
0
        private SystemOperationResult SaveOrder()
        {
            SystemOperationResult result = new SystemOperationResult(false, "");

            Order o = MTApp.OrderServices.Orders.FindForCurrentStore(this.BvinField.Value);
            if (o == null)
            {
                result.Success = false;
                result.Message = "Unable to reload order.";
                return result;
            }

            o.UserID = this.UserIdField.Value;
            o.UserEmail = this.UserPicker1.UserName;
            o.Instructions = this.InstructionsField.Text.Trim();

            o.BillingAddress = this.BillingAddressEditor.GetAsAddress();
            o.ShippingAddress = this.ShippingAddressEditor.GetAsAddress();

            SystemOperationResult modifyResult = ModifyQuantities(o);
            if (!modifyResult.Success)
            {
                result.Message = modifyResult.Message;
            }

            // Save Shipping Selection
            string shippingRateKey = Request.Form["shippingrate"];
            MTApp.OrderServices.OrdersRequestShippingMethodByUniqueKey(shippingRateKey, o, MTApp.CurrentStore);

            // Shipping Override
            if (this.ShippingOverride.Text.Trim().Length < 1)
            {
                o.TotalShippingBeforeDiscountsOverride = -1m;
            }
            else
            {
                decimal shipOverride = o.TotalShippingBeforeDiscountsOverride;
                decimal.TryParse(this.ShippingOverride.Text, System.Globalization.NumberStyles.Currency, System.Threading.Thread.CurrentThread.CurrentUICulture, out shipOverride);
                o.TotalShippingBeforeDiscountsOverride = shipOverride;
            }

            result.Success = MTApp.CalculateOrderAndSave(o);

            return result;
        }
Exemplo n.º 2
0
        private SystemOperationResult ModifyQuantities(Order o)
        {
            SystemOperationResult result = new SystemOperationResult(true, "");

            for (int i = 0; i < this.ItemsGridView.Rows.Count - 1; i++)
            {
                GridViewRow currentRow = ItemsGridView.Rows[i];

                if (currentRow.RowType == DataControlRowType.DataRow)
                {
                    long lineitemId = (long)ItemsGridView.DataKeys[currentRow.RowIndex].Value;
                    var li = o.Items.Where(y => y.Id == lineitemId).FirstOrDefault();
                    if (li != null)
                    {
                        TextBox qty = (TextBox)currentRow.FindControl("QtyField");
                        if (qty != null)
                        {
                            string tempQty = qty.Text.Trim();
                            int actualQty = li.Quantity;
                            int.TryParse(tempQty, out actualQty);
                            li.Quantity = actualQty;
                        }
                    }
                }
            }
            return result;
        }
Exemplo n.º 3
0
        private void RunOrderEditedWorkflow(SystemOperationResult saveResult)
        {
            MerchantTribe.Commerce.BusinessRules.OrderTaskContext c = new MerchantTribe.Commerce.BusinessRules.OrderTaskContext(MTApp);
            c.Order = MTApp.OrderServices.Orders.FindForCurrentStore(this.BvinField.Value);
            c.UserId = c.Order.UserID;

            if (!MerchantTribe.Commerce.BusinessRules.Workflow.RunByName(c, MerchantTribe.Commerce.BusinessRules.WorkflowNames.OrderEdited))
            {
                foreach (MerchantTribe.Commerce.BusinessRules.WorkflowMessage msg in c.Errors)
                {
                    EventLog.LogEvent("Order Edited Workflow", msg.Description, EventLogSeverity.Warning);
                }
                if (!String.IsNullOrEmpty(saveResult.Message))
                {
                    this.MessageBox1.ShowError(saveResult.Message + " Error Occurred. Please see event log.");
                }
                else
                {
                    this.MessageBox1.ShowError("Error Occurred. Please see event log.");
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(saveResult.Message))
                {
                    this.MessageBox1.ShowError(saveResult.Message);
                }
                else
                {
                    this.MessageBox1.ShowOk("Changes Saved");
                }
            }
        }