コード例 #1
0
        public IActionResult Seguimiento(string id)
        {
            Orders order = _context.Orders.Where(o => o.order_number == id).FirstOrDefault();

            if (order != null)
            {
                OrderDetail detail = new OrderDetail();

                IRestResponse response = CallShopify($"orders/{order.id}.json", Method.GET, null);

                if (response.StatusCode.ToString().Equals("OK"))
                {
                    MasterOrder mo = JsonConvert.DeserializeObject <MasterOrder>(response.Content);
                    if (mo.order.shipping_lines.Count > 0)
                    {
                        order.shipping_price = mo.order.shipping_lines[0].price;
                        if (mo.order.shipping_lines[0].title.Contains("-"))
                        {
                            string place = mo.order.shipping_lines[0].title.Split("-")[1].Trim();
                            if (place.Contains("("))
                            {
                                place = place.Split("(")[0].Trim();
                            }
                            order.pickup_place = place;
                        }
                    }
                }
                else
                {
                    return(NotFound());
                }

                detail.Order = order;
                detail.Items = _context.Item.Where(o => o.order_id == order.id).ToList();

                foreach (Item item in detail.Items)
                {
                    KellyChild product = _context.KellyChild.FromSqlInterpolated($"GetProductChildInfo @CodigoPadre = {item.sku}").ToList()[0];
                    item.name = $"{item.title}{(product.Talla != "00" ? " - Talla " + product.Talla : "")}{(product.Taco != "00" ? " - Taco " + product.Taco : "")}";
                }

                detail.Ship                = _context.ShipAddress.Where(c => c.order_id == order.id).FirstOrDefault();
                detail.Status              = generateList(order);
                detail.Customer            = _context.Customer.Where(c => c.id == order.customer_id).FirstOrDefault();
                detail.Customer.first_name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(detail.Customer.first_name);
                detail.Customer.last_name  = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(detail.Customer.last_name);

                return(View(detail));
            }
            else
            {
                return(NotFound());
            }
        }
コード例 #2
0
        // GET: Orders/Edit/5
        public IActionResult Edit(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            OrderDetail detail = new OrderDetail();

            detail.Order = _context.Orders.Find(id);

            IRestResponse response = CallShopify($"orders/{id}.json", Method.GET, null);

            if (response.StatusCode.ToString().Equals("OK"))
            {
                MasterOrder mo = JsonConvert.DeserializeObject <MasterOrder>(response.Content);
                if (mo.order.shipping_lines.Count > 0)
                {
                    detail.Order.shipping_price = mo.order.shipping_lines[0].price;
                }
            }
            else
            {
                return(NotFound());
            }

            List <Item> items = _context.Item.Where(i => i.order_id.Equals(id)).ToList();

            detail.Bill     = _context.BillAddress.Where(b => b.order_id.Equals(id)).FirstOrDefault();
            detail.Ship     = _context.ShipAddress.Where(s => s.order_id.Equals(id)).FirstOrDefault();
            detail.Customer = _context.Customer.Where(c => c.id.Equals(detail.Order.customer_id)).FirstOrDefault();
            detail.Customer.default_address = _context.CustomerAddress.Where(d => (d.customer_id.Equals(detail.Order.customer_id)) && (d.id.Equals(detail.Order.customer_address_id))).FirstOrDefault();
            detail.Items = items;
            detail.Combo = getStateValues(detail.Order.status, detail.Order.fechaEstimada.Contains("para recojo") ? true : false);

            detail.Customer.default_address.zip = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(detail.Customer.default_address.zip.ToLower());
            detail.Ship.zip = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(detail.Ship.zip.ToLower());
            detail.Bill.zip = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(detail.Bill.zip.ToLower());

            if (detail.Order.financial_status == "pending")
            {
                detail.Order.financial_status = "Pendiente";
            }
            else
            {
                detail.Order.financial_status = "Pagado";
            }

            switch (detail.Order.gateway)
            {
            case "Bank Deposit":
                detail.Order.gateway = "Depósito Bancario";
                break;

            case "Cash on Delivery (COD)":
                detail.Order.gateway = "Contraentrega";
                break;

            case "mercado_pago":
                detail.Order.gateway = "Mercado Pago";
                break;
            }

            foreach (Item item in detail.Items)
            {
                KellyChild product = _context.KellyChild.FromSqlInterpolated($"GetProductChildInfo @CodigoPadre = {item.sku}").ToList()[0];
                item.name = $"{item.title}{(product.Talla != "00" ? " - Talla " + product.Talla : "")}{(product.Taco != "00" ? " - Taco " + product.Taco : "")}";
                Product p = _context.Product.Find(item.product_id);
                if (p != null)
                {
                    item.handle = p.Handle;
                    ProductImage pi = _context.ProductImage.Where(i => i.product_id.Equals(p.Id)).FirstOrDefault();
                    if (pi != null)
                    {
                        item.imgURL = pi.src;
                    }
                }
            }

            if (detail == null)
            {
                return(NotFound());
            }
            return(View(detail));
        }