Ejemplo n.º 1
0
        public async Task<ActionResult> Recalculate(QuoteRequest model)
        {
            Context.QuoteRequest = await QuoteService.GetByNumberAsync(Context.StoreId, Context.CustomerId, model.Number);

            foreach (var modelQuoteItem in model.Items)
            {
                var quoteItem = Context.QuoteRequest.Items.FirstOrDefault(i => i.Id == modelQuoteItem.Id);
                quoteItem.SelectedTierPrice = modelQuoteItem.SelectedTierPrice;
            }

            Context.QuoteRequest = await QuoteService.RecalculateAsync(Context.QuoteRequest);

            return Json(Context.QuoteRequest);
        }
        public static QuoteRequest ToViewModel(this DataContracts.Quotes.QuoteRequest quoteRequest)
        {
            var quoteRequestModel = new QuoteRequest(quoteRequest.StoreId, quoteRequest.CustomerId);

            if (quoteRequest.Addresses != null)
            {
                var billingAddress = quoteRequest.Addresses.FirstOrDefault(a => a.AddressType == DataContracts.AddressType.Billing);
                if (billingAddress != null)
                {
                    quoteRequestModel.BillingAddress = billingAddress.ToViewModel();
                }

                var shippingAddress = quoteRequest.Addresses.FirstOrDefault(a => a.AddressType == DataContracts.AddressType.Shipping);
                if (shippingAddress != null)
                {
                    quoteRequestModel.ShippingAddress = shippingAddress.ToViewModel();
                }

                var firstAddressWithEmail = quoteRequest.Addresses.FirstOrDefault(a => !string.IsNullOrEmpty(a.Email));
                if (firstAddressWithEmail != null)
                {
                    quoteRequestModel.Email = firstAddressWithEmail.Email;
                }
            }

            if (quoteRequest.Attachments != null)
            {
                foreach (var attachment in quoteRequest.Attachments)
                {
                    quoteRequestModel.Attachments.Add(attachment.ToViewModel());
                }
            }

            quoteRequestModel.CancelledAt = quoteRequest.CancelledDate;
            quoteRequestModel.CancelReason = quoteRequest.CancelReason;
            quoteRequestModel.Comment = quoteRequest.Comment;
            quoteRequestModel.Coupon = quoteRequest.Coupon;
            quoteRequestModel.CreatedAt = quoteRequest.CreatedDate;
            quoteRequestModel.Currency = quoteRequest.Currency;
            quoteRequestModel.CustomerName = quoteRequest.CustomerName;
            quoteRequestModel.ExpirationDate = quoteRequest.ExpirationDate;
            quoteRequestModel.Id = quoteRequest.Id;
            quoteRequestModel.IsCancelled = quoteRequest.IsCancelled;
            quoteRequestModel.IsLocked = quoteRequest.IsLocked;

            if (quoteRequest.Items != null)
            {
                foreach (var quoteItem in quoteRequest.Items)
                {
                    var quoteItemModel = quoteItem.ToViewModel();
                    quoteRequestModel.Items.Add(quoteItemModel);
                }
            }

            quoteRequestModel.Language = quoteRequest.LanguageCode;
            quoteRequestModel.Number = quoteRequest.Number;
            quoteRequestModel.Status = quoteRequest.Status;
            quoteRequestModel.Tag = quoteRequest.Tag;

            if (quoteRequest.TaxDetails != null)
            {
                foreach (var taxDetail in quoteRequest.TaxDetails)
                {
                    quoteRequestModel.TaxLines.Add(taxDetail.ToViewModel());
                }
            }

            if (quoteRequest.Totals != null)
            {
                quoteRequestModel.Totals.AdjustmentQuoteExlTax = quoteRequest.Totals.AdjustmentQuoteExlTax;
                quoteRequestModel.Totals.DiscountTotal = quoteRequest.Totals.DiscountTotal;
                quoteRequestModel.Totals.GrandTotalExlTax = quoteRequest.Totals.GrandTotalExlTax;
                quoteRequestModel.Totals.GrandTotalInclTax = quoteRequest.Totals.GrandTotalInclTax;
                quoteRequestModel.Totals.OriginalSubTotalExlTax = quoteRequest.Totals.OriginalSubTotalExlTax;
                quoteRequestModel.Totals.ShippingTotal = quoteRequest.Totals.ShippingTotal;
                quoteRequestModel.Totals.SubTotalExlTax = quoteRequest.Totals.SubTotalExlTax;
                quoteRequestModel.Totals.TaxTotal = quoteRequest.Totals.TaxTotal;
            }

            return quoteRequestModel;
        }
Ejemplo n.º 3
0
        public async Task<ActionResult> ConfirmQuote(QuoteRequest model)
        {
            Context.QuoteRequest = await QuoteService.GetByNumberAsync(Context.StoreId, Context.CustomerId, model.Number);

            foreach (var modelQuoteItem in model.Items)
            {
                var quoteItem = Context.QuoteRequest.Items.FirstOrDefault(i => i.Id == modelQuoteItem.Id);
                quoteItem.SelectedTierPrice = modelQuoteItem.SelectedTierPrice;
            }

            var newQuoteRequest = await QuoteService.RecalculateAsync(Context.QuoteRequest);
            Context.QuoteRequest = newQuoteRequest;

            Context.Cart.Items.Clear();

            foreach (var quoteItem in Context.QuoteRequest.Items)
            {
                var lineItemModel = quoteItem.AsLineItemModel();
                Context.Cart.Items.Add(lineItemModel);
            }

            Context.QuoteRequest.Status = "Accepted";
            await QuoteService.UpdateQuoteRequestAsync(Context.QuoteRequest);

            if (Context.Cart.IsTransient)
            {
                await Service.CreateCartAsync(Context.Cart);
            }
            else
            {
                await Service.SaveChangesAsync(Context.Cart);
            }

            var checkout = await Service.GetCheckoutAsync();
            checkout.BillingAddress = newQuoteRequest.BillingAddress;
            checkout.ShippingAddress = newQuoteRequest.ShippingAddress;

            await Service.UpdateCheckoutAsync(checkout);

            return Json(new { redirectUrl = VirtualPathUtility.ToAbsolute("~/checkout") });
        }
Ejemplo n.º 4
0
        public async Task<ActionResult> Submit(QuoteRequest model)
        {
            if (User.Identity.IsAuthenticated && string.IsNullOrEmpty(model.Email))
            {
                return Json(new { errorMessage = "Field \"Email\" is required" });
            }
            if (model.BillingAddress != null)
            {
                if (model.BillingAddressErrors.Count > 0)
                {
                    var firstError = model.BillingAddressErrors.First();
                    return Json(new { errorMessage = firstError });
                }
            }
            if (model.ShippingAddress != null)
            {
                if (model.ShippingAddressErrors.Count > 0)
                {
                    var firstError = model.ShippingAddressErrors.First();
                    return Json(new { errorMessage = firstError });
                }
            }
            Context.ActualQuoteRequest.CustomerId = Context.CustomerId;
            Context.ActualQuoteRequest.CustomerName = Context.Customer.Name;
            Context.ActualQuoteRequest.Comment = model.Comment;
            Context.ActualQuoteRequest.Email = model.Email;
            Context.ActualQuoteRequest.BillingAddress = model.BillingAddress;
            Context.ActualQuoteRequest.ShippingAddress = model.ShippingAddress;

            foreach (var quoteItem in model.Items)
            {
                var existingQuoteItem = Context.ActualQuoteRequest.Items.FirstOrDefault(i => i.Id == quoteItem.Id);

                existingQuoteItem.Comment = quoteItem.Comment;

                existingQuoteItem.ProposalPrices = new List<TierPrice>();
                foreach (var tearPrice in quoteItem.ProposalPrices)
                {
                    existingQuoteItem.ProposalPrices.Add(new TierPrice
                    {
                        Quantity = tearPrice.Quantity,
                        Price = existingQuoteItem.SalePrice == 0 ? existingQuoteItem.ListPrice : existingQuoteItem.SalePrice
                    });
                }
            }

            if (!Context.ActualQuoteRequest.ProposalPricesUnique)
            {
                return Json(new { errorMessage = "Proposal prices quantities must be unique." });
            }

            if (User.Identity.IsAuthenticated)
            {
                Context.ActualQuoteRequest.Tag = null;
            }

            Context.ActualQuoteRequest.Status = "Processing";

            await QuoteService.UpdateQuoteRequestAsync(Context.ActualQuoteRequest);

            if (!User.Identity.IsAuthenticated)
            {
                string returnUrl = VirtualPathUtility.ToAbsolute("~/quote");
                return Json(new { redirectUrl = VirtualPathUtility.ToAbsolute("~/account/login?returnUrl=" + returnUrl) });
            }

            return Json(new { redirectUrl = VirtualPathUtility.ToAbsolute("~/account/quote/" + Context.ActualQuoteRequest.Number) });
        }
Ejemplo n.º 5
0
        public QuoteRequest MergeQuoteWith(QuoteRequest anotherQuote)
        {
            foreach (var anotherQuoteItem in anotherQuote.Items)
            {
                AddItem(anotherQuoteItem);
            }

            return this;
        }