Exemple #1
0
        private async Task <IActionResult> inputShippingInfo(ShippingInfoDto shippingInfo, int?orderId)
        {
            if (shippingInfo == null || orderId == null)
            {
                return(NotFound("No shipping address or order_id!"));
            }
            shippingInfo.orderId = orderId.GetValueOrDefault();
            var newShipping = new ShippingInfo();

            newShipping.orderId        = shippingInfo.orderId;
            newShipping.sender         = shippingInfo.sender;
            newShipping.sender_phone   = shippingInfo.sender_phone;
            newShipping.sender_address = shippingInfo.sender_address;
            newShipping.sender_city    = shippingInfo.sender_city;
            newShipping.sender_country = shippingInfo.sender_country;

            newShipping.receiver          = shippingInfo.receiver;
            newShipping.receiver_phone    = shippingInfo.receiver_phone;
            newShipping.receiver_address1 = shippingInfo.receiver_address1;
            newShipping.receiver_address2 = shippingInfo.receiver_address2;
            newShipping.receiver_address3 = shippingInfo.receiver_address3;
            newShipping.receiver_city     = shippingInfo.receiver_city;
            newShipping.receiver_country  = shippingInfo.receiver_country;
            newShipping.receiver_company  = shippingInfo.receiver_company;
            newShipping.receiver_contact  = shippingInfo.receiver_contact;
            newShipping.note = shippingInfo.note;

            await _context.ShippingInfo.AddAsync(newShipping);

            await _context.SaveChangesAsync();

            return(Ok());
        }
Exemple #2
0
        public async Task <IActionResult> orderDetail(int?order_id)
        {
            if (order_id == null)
            {
                _logger.LogInformation($"Order with id {order_id} was null.");
                return(NotFound());
            }

            if (!await _context.Orders.AnyAsync(o => o.Id == order_id))
            {
                _logger.LogInformation($"Order with id {order_id} wasn't found.");
                return(NotFound());
            }
            else
            {
                _logger.LogInformation($"Order with id {order_id} was found.");
            }

            try
            {
                var orderDetail = new OrderDetailDto();

                var myOrder = _context.Orders.Where(o => o.Id == order_id)
                              .Include(b => b.shippinginfo)
                              .Include(b => b.invoiceFreight)
                              .Join(_context.Invoice.Select(i => new { i.InvoiceNumber, i.Paid, i.PaymentType, i.Freight, i.Total, i.Tax, i.Price }),
                                    (b => b.InvoiceNumber),
                                    (i => i.InvoiceNumber),
                                    (b, i) => new { b.shippinginfo, b.invoiceFreight, b.Id, b.ShippingMethod, b.InvoiceNumber, b.PoNumber, b.CustomerGst, b.CardId, i.Freight, OrderTotal = i.Price, i.Total, i.Tax, b.WebOrderStatus, b.Status, i.Paid, i.PaymentType })

                              .Join(_context.Enum.Where(e => e.Class == "payment_method"),
                                    (b => (int)b.PaymentType),
                                    (e => e.Id),
                                    (b, e) => new { b.shippinginfo, b.invoiceFreight, b.Id, b.ShippingMethod, b.InvoiceNumber, b.PoNumber, b.CustomerGst, b.CardId, b.Freight, b.OrderTotal, b.Total, b.Tax, b.WebOrderStatus, b.Status, b.Paid, PaymentType = e.Name })

                              //.Join(_context.Enum.Where(e => e.Class == "web_order_status"),
                              //(b => b.WebOrderStatus),
                              //(e => e.Id),
                              //(b, e) => new { b.shippinginfo, b.invoiceFreight, b.Id, b.ShippingMethod, b.InvoiceNumber, b.PoNumber, b.CustomerGst, b.CardId, b.Freight, b.OrderTotal, b.Total, b.Tax, WebOrderStatus = e.Name, b.Paid, b.PaymentType })

                              .FirstOrDefault();
                if (myOrder == null)
                {
                    _logger.LogInformation($"Order with id {order_id} was null.");
                    return(NotFound());
                }

                var customerGst = myOrder.CustomerGst;

                var orderItem = _context.OrderItem.Where(o => o.Id == order_id)
                                .Select(oi => new OrderItemDto
                {
                    Kid          = oi.Kid,
                    Id           = oi.Id,
                    Code         = oi.Code,
                    SupplierCode = oi.SupplierCode,
                    Quantity     = oi.Quantity,
                    ItemName     = oi.ItemName,
                    ItemNameCn   = oi.ItemNameCn,
                    CommitPrice  = oi.CommitPrice,
                    PriceGstInc  = Math.Round(oi.CommitPrice * Convert.ToDecimal(1 + customerGst), 2),
                    Cat          = oi.Cat,
                    Note         = oi.Note
                }).ToListAsync();

                var shippingInfo = myOrder.shippinginfo
                                   .Select(s => new ShippingInfoDto
                {
                    id                = s.id,
                    sender            = s.sender,
                    orderId           = s.orderId,
                    sender_phone      = s.sender_phone,
                    sender_address    = s.sender_address,
                    sender_city       = s.sender_city,
                    sender_country    = s.receiver_country,
                    receiver          = s.receiver,
                    receiver_company  = s.receiver_company,
                    receiver_address1 = s.receiver_address1,
                    receiver_address2 = s.receiver_address2,
                    receiver_address3 = s.receiver_address3,
                    receiver_city     = s.receiver_city,
                    receiver_country  = s.receiver_country,
                    receiver_phone    = s.receiver_phone,
                    receiver_contact  = s.receiver_contact,
                    note              = s.note
                })
                                   .FirstOrDefault();

                if (shippingInfo == null)
                {
                    shippingInfo = new ShippingInfoDto
                    {
                        sender            = "",
                        sender_phone      = "",
                        sender_address    = "",
                        sender_city       = "",
                        sender_country    = "",
                        receiver          = "",
                        receiver_company  = "",
                        receiver_address1 = "",
                        receiver_address2 = "",
                        receiver_address3 = "",
                        receiver_city     = "",
                        receiver_country  = "",
                        receiver_phone    = "",
                        receiver_contact  = "",
                        note = ""
                    };
                }



                List <FreightInfoDto> freightInfo = myOrder.invoiceFreight
                                                    .Select(i => new FreightInfoDto
                {
                    ship_name = i.ShipName,
                    ship_desc = i.ShipDesc,
                    ship_id   = i.ShipId.Value,
                    ticket    = i.Ticket,
                    price     = i.Price
                }).ToList();

                orderDetail.invoice_number  = myOrder.InvoiceNumber.Value;
                orderDetail.po_number       = myOrder.PoNumber;
                orderDetail.card_id         = myOrder.CardId;
                orderDetail.freight         = (double)myOrder.Freight * (1 + customerGst);
                orderDetail.order_id        = myOrder.Id;
                orderDetail.total           = (double)myOrder.Total;
                orderDetail.sub_total       = (double)myOrder.OrderTotal;
                orderDetail.tax             = (double)myOrder.Tax;
                orderDetail.payment_method  = (myOrder.PaymentType);
                orderDetail.status          = _isettings.getOrderStatus(Convert.ToInt32(myOrder.Status));// (myOrder.WebOrderStatus);
                orderDetail.paid            = _iorder.getOrderPaymentStatus(order_id ?? 0);
                orderDetail.orderItems      = await orderItem;
                orderDetail.shippingInfo    = shippingInfo;
                orderDetail.shipping_method = myOrder.ShippingMethod;
                orderDetail.freightInfo     = freightInfo;

                return(Ok(orderDetail));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, $"Exception while getting order detail with order_id {order_id}.");

                return(StatusCode(500, "A problem happened while handling your request."));
            }
        }
Exemple #3
0
        public async Task <IActionResult> SendOrderToSupplier(int order_id)
        {
            var hasOrder = await _context.Orders.AnyAsync(o => o.Id == order_id);

            if (!hasOrder)
            {
                return(BadRequest("order " + order_id + " not exists! "));
            }

            var dealerId = _config["DealerId"];
            var apiUrl   = _config["ApiUrl"];
            var siteName = _config["SiteName"];

            var sales_note      = _context.Orders.Where(o => o.Id == order_id).FirstOrDefault().SalesNote;
            var shipping_method = _context.Orders.Where(o => o.Id == order_id).FirstOrDefault().ShippingMethod;
            var freight         = _context.Orders.Where(o => o.Id == order_id).FirstOrDefault().Freight;
            var shippingInfo    = _context.ShippingInfo.Where(o => o.orderId == order_id).FirstOrDefault();
            var shppingInfoDto  = new ShippingInfoDto();

            if (shippingInfo != null)
            {
                shppingInfoDto = new ShippingInfoDto()
                {
                    id                = shippingInfo.id,
                    sender            = shippingInfo.sender,
                    sender_phone      = shippingInfo.sender_phone,
                    sender_address    = shippingInfo.sender_address,
                    sender_city       = shippingInfo.sender_city,
                    sender_country    = shippingInfo.sender_country,
                    orderId           = shippingInfo.orderId,
                    note              = shippingInfo.note,
                    receiver          = shippingInfo.receiver,
                    receiver_address1 = shippingInfo.receiver_address1,
                    receiver_address2 = shippingInfo.receiver_address2,
                    receiver_address3 = shippingInfo.receiver_address3,
                    receiver_city     = shippingInfo.receiver_city,
                    receiver_company  = shippingInfo.receiver_company,
                    receiver_contact  = shippingInfo.receiver_contact,
                    receiver_country  = shippingInfo.receiver_country,
                    receiver_phone    = shippingInfo.receiver_phone,
                    receiver_zip      = shippingInfo.zip,
                    oversea           = false
                };
            }
            else
            {
                shppingInfoDto = null;
            }

            var orderItems = _context.OrderItem.Where(oi => oi.Id == order_id)
                             .Select(i => new CartItemDto
            {
                code          = i.Code.ToString(),
                quantity      = i.Quantity.ToString(),
                barcode       = i.Barcode,
                name          = i.ItemName,
                id            = i.Id,
                note          = i.Note,
                supplier_code = i.SupplierCode
            }).ToList();

            var newCreateOrderByDealerId = new CreateOrderByDealerIdDto()
            {
                freight         = freight,
                sales_note      = sales_note,
                shipping_method = shipping_method,
                ShippingInfo    = shppingInfoDto,
                cartItems       = orderItems
            };

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(apiUrl);
                    //check if this order has been sent already!
                    var responseTask = client.GetAsync("/" + siteName + "/api/dealer/order/po/eCom_Managment_" + order_id);
                    responseTask.Wait();
                    var final = responseTask.Result;
                    if (final.IsSuccessStatusCode)
                    {
                        var readTask = final.Content.ReadAsAsync <bool>();
                        readTask.Wait();
                        var myfinal = readTask.Result;
                        if (myfinal)
                        {
                            return(BadRequest("order exists already!"));
                        }
                    }

                    var content  = newCreateOrderByDealerId;
                    var postTask = client.PostAsJsonAsync <CreateOrderByDealerIdDto>("/" + siteName + "/api/dealer/order/createOrderByDealerId/" + dealerId + "/" + order_id, content);
                    postTask.Wait();

                    var reault = postTask.Result;
                    if (reault.IsSuccessStatusCode)
                    {
                        return(Ok("order sent!"));
                    }
                    else
                    {
                        return(BadRequest("something wrong!"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.ToString()));
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ShippingInfo"/> class.
 /// </summary>
 /// <param name="dto">Dto to base the class on.</param>
 internal ShippingInfo(ShippingInfoDto dto)
 {
     this.Price     = dto.Price;
     this.Shipments = dto.Shipments.Select(s => new Shipment(s));
 }