コード例 #1
0
        public ActionResult thankyou(int id)
        {
            try
            {
                TblOrder order = orderService.GetByPrimaryKey(id);
                if (order == null)
                {
                    return(RedirectToAction("index", "cart"));
                }

                List <LineItem> lineItems = lineItemService.GetByOrderID(order.OrderID);
                foreach (var item in lineItems)
                {
                    if (item.VariantName == "Default Title")
                    {
                        var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                        item.ImageUrl = thumb;
                    }
                    else
                    {
                        Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                        if (variant != null)
                        {
                            TblImage image = imageService.GetByPrimaryKey(variant.ImageID);
                            if (image != null)
                            {
                                item.ImageUrl = image.ImageUrl;
                            }
                        }
                    }
                }

                ThankyouViewModel thankyouViewModel = new ThankyouViewModel();
                thankyouViewModel.CustomerEmail     = order.CustomerEmail;
                thankyouViewModel.LineItems         = lineItems;
                thankyouViewModel.ShippingAddressID = order.ShippingAddressID;
                thankyouViewModel.ShippingAddress   = shippingAddressService.GetByPrimaryKey(thankyouViewModel.ShippingAddressID == null ? 0 : thankyouViewModel.ShippingAddressID.Value);
                thankyouViewModel.BillingAddresID   = order.BillingAddressID;
                thankyouViewModel.BillingAddress    = billingAddressService.GetByPrimaryKey(thankyouViewModel.BillingAddresID == null ? 0 : thankyouViewModel.BillingAddresID.Value);
                thankyouViewModel.TotalSubPrice     = order.TotalCount;
                thankyouViewModel.TotalShipping     = order.TotalShipping;
                thankyouViewModel.TotalPrice        = order.TotalCount + order.TotalShipping;
                return(View(thankyouViewModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                throw;
            }
        }
コード例 #2
0
        public ActionResult detail(int id, string strMessage = "")
        {
            try
            {
                string strError = "", strSuccess = "";
                if (!string.IsNullOrEmpty(strMessage))
                {
                    if (strMessage.Equals("bill1"))
                    {
                        strSuccess = "Xác nhận thanh toán thành công";
                    }
                    else if (strMessage.Equals("bill0"))
                    {
                        strError = "Xác nhận thanh toán thất bại";
                    }
                    else if (strMessage.Equals("delivery1"))
                    {
                        strSuccess = "Cập nhật thông tin giao hàng thành công";
                    }
                    else if (strMessage.Equals("delivery0"))
                    {
                        strError = "Cập nhật thông tin giao hàng thất bại";
                    }
                    else if (strMessage.Equals("update1"))
                    {
                        strSuccess = "Cập nhật thông tin đơn hàng thành công";
                    }
                    else if (strMessage.Equals("update0"))
                    {
                        strError = "Cập nhật thông tin đơn hàng thất bại";
                    }
                    else if (strMessage.Equals("addShippingAddress1"))
                    {
                        strSuccess = "Thêm mới địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("addShippingAddress0"))
                    {
                        strError = "Thêm mới địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editShippingAddress1"))
                    {
                        strSuccess = "Sửa địa chỉ giao hàng thành công";
                    }
                    else if (strMessage.Equals("editShippingAddress0"))
                    {
                        strError = "Sửa địa chỉ giao hàng thất bại";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strSuccess = "Sửa điạ chỉ email của khách hàng thành công";
                    }
                    else if (strMessage.Equals("editEmail1"))
                    {
                        strError = "Sửa điạ chỉ email của khách hàng thất bại";
                    }
                }
                ViewBag.strSuccess = strSuccess;
                ViewBag.strError   = strError;

                TblOrder order = orderService.GetByPrimaryKey(id);
                if (order == null)
                {
                    return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
                }
                order.OrderName = "#" + (Common.BaseNumberOrder + order.Number).ToString() + " " + SDateTime.ToDateTime(order.CreatedDateTime);

                DetailOrderModel detailOrderModel = new DetailOrderModel();
                detailOrderModel.OrderID        = order.OrderID;
                detailOrderModel.CustomerEmail  = order.CustomerEmail;
                detailOrderModel.CustomerID     = order.CustomerID;
                detailOrderModel.Customer       = customerService.GetByPrimaryKey(SNumber.ToNumber(order.CustomerID));
                detailOrderModel.BillingStatus  = order.BillingStatus;
                detailOrderModel.ShippingStatus = order.ShippingStatus;
                detailOrderModel.TotalCount     = order.TotalCount;
                detailOrderModel.OrderName      = order.OrderName;
                detailOrderModel.OrderNote      = order.OrderNote;
                detailOrderModel.Tags           = order.Tags;
                detailOrderModel.ListTag        = tagService.GetByTableNameID((int)Common.TableName.TblOrder);

                detailOrderModel.BillingAddressID = SNumber.ToNumber(order.BillingAddressID);
                detailOrderModel.BillingAddress   = billingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.BillingAddressID));
                if (detailOrderModel.BillingAddress != null)
                {
                    detailOrderModel.BillingAddress.Countries = countryService.GetAll();
                }

                detailOrderModel.ShippingAddressID = SNumber.ToNumber(order.ShippingAddressID);
                detailOrderModel.ShippingAddress   = shippingAddressService.GetByPrimaryKey(SNumber.ToNumber(order.ShippingAddressID));
                if (detailOrderModel.ShippingAddress == null)
                {
                    detailOrderModel.ShippingAddress = new ShippingAddress();
                }
                detailOrderModel.ShippingAddress.Countries = countryService.GetAll();

                if (order.OrderID > 0)
                {
                    List <LineItem> lineItems = lineItemService.GetByOrderID(order.OrderID);
                    foreach (var item in lineItems)
                    {
                        if (item.VariantName == "Default Title")
                        {
                            var thumb = ImageService.GetPathImageFirstOfProduct(item.ProductID);
                            item.ImageUrl = thumb;
                        }
                        else
                        {
                            Variant variant = variantService.GetByPrimaryKey(item.VariantID);
                            if (variant != null)
                            {
                                TblImage image = imageService.GetByPrimaryKey(variant.ImageID);
                                if (image != null)
                                {
                                    item.ImageUrl = image.ImageUrl;
                                }
                            }
                        }

                        if (item.ShippingStatus == null)
                        {
                            detailOrderModel.LineItemsPending.Add(item);
                        }
                        else
                        {
                            detailOrderModel.LineItemsPaid.Add(item);
                        }
                    }
                }
                return(View(detailOrderModel));
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(RedirectToAction("", "orders", new { strMessage = "notExist" }));
            }
        }