Example #1
0
        private async Task <bool> PostRtsPickupFormat(RtsPickupFormat rtsPickupFormat, bool doPosting)
        {
            if (!doPosting)
            {
                return(true);
            }
            Console.WriteLine($"Posting: {rtsPickupFormat.ConsignmentNo} {rtsPickupFormat.PickupNo} {rtsPickupFormat.AccountNo}");

            var json       = JsonConvert.SerializeObject(rtsPickupFormat);
            var content    = new StringContent(json, Encoding.UTF8, "application/json");
            var requestUri = "/api/rts-pickup-formats";
            var response   = await m_ostClient.PostAsync(requestUri, content);

            Console.WriteLine($"RequestUri: {response.RequestMessage.RequestUri}");
            Console.WriteLine($"Status: {(int)response.StatusCode} {response.ReasonPhrase}");
            if (!response.IsSuccessStatusCode)
            {
                Console.WriteLine("Aborting .....");
                return(false);
            }

            var output = await response.Content.ReadAsStringAsync();

            var rtsPickupFormatId = JObject.Parse(output).SelectToken("$.id").Value <string>();

            Console.WriteLine($"Posted: {rtsPickupFormatId}");
            Console.WriteLine("");

            return(true);
        }
Example #2
0
        public async Task GetRtsPickupEvent(RtsPickupFormat item)
        {
            var context = new SphDataContext();
            var consignmentRequestsPickup = new List <ConsigmentRequest>();
            var consignmentRequestsCart   = new List <ConsigmentRequest>();

            //Check data receive from scanner
            if (item.PickupNo == null || item.PickupNo == "" ||
                item.AccountNo == null || item.AccountNo == "" ||
                item.ConsignmentNo == null || item.ConsignmentNo == "")
            {
                Console.WriteLine($"Incomplete mandotary data.");
            }
            else
            {
                consignmentRequestsPickup = await GetConsignmentRequestAsync(item.PickupNo, "true");

                if (consignmentRequestsPickup.Count > 0) //Pickup exist
                {
                    //Clone
                    ConsigmentRequest consignmentRequestPickup = CloneConsignmentRequestPickup(consignmentRequestsPickup);

                    consignmentRequestsCart = await GetConsignmentRequestAsync(item.PickupNo, "false");

                    if (consignmentRequestsCart.Count > 0) //Cart exist
                    {
                        //Clone
                        ConsigmentRequest consignmentRequestCart = CloneConsignmentRequestCart(consignmentRequestsCart);

                        //Move
                        var needSaving = MoveConsignmentFromCartToPickup(item.ConsignmentNo, item.ActualWeight, consignmentRequestCart, consignmentRequestPickup);

                        //Save
                        if (needSaving)
                        {
                            await SaveChanges(context, consignmentRequestPickup, consignmentRequestCart);
                        }
                    }
                    else //Cart not exist
                    {
                        //Fall through, there is no consignmentRequest with the scanner`s PickupNo

                        consignmentRequestsCart = await GetConsignmentRequestByAccountNoAsync(item.AccountNo, item.ConsignmentNo, "false");

                        if (consignmentRequestsCart.Count > 0) //Cart exist (no pickupNo)
                        {
                            //Clone
                            ConsigmentRequest consignmentRequestCart = CloneConsignmentRequestCart(consignmentRequestsCart);

                            //Move
                            var needSaving = MoveConsignmentFromCartToPickup(item.ConsignmentNo, item.ActualWeight, consignmentRequestCart, consignmentRequestPickup);

                            //Save
                            if (needSaving)
                            {
                                await SaveChanges(context, consignmentRequestPickup, consignmentRequestCart);
                            }
                        }
                        else
                        {
                            //Fall through
                        }
                    }
                }
                else //Pickup not exist
                {
                    consignmentRequestsCart = await GetConsignmentRequestAsync(item.PickupNo, "false");

                    if (consignmentRequestsCart.Count > 0) //Cart exist
                    {
                        //Clone
                        ConsigmentRequest consignmentRequestCart = CloneConsignmentRequestCart(consignmentRequestsCart);

                        //Create
                        ConsigmentRequest consignmentRequestPickup = CreateNewConsignmentRequestPickup(consignmentRequestCart);

                        //Set IsPickedUp
                        consignmentRequestPickup.Pickup.IsPickedUp = true;

                        //Set IsPaid
                        consignmentRequestPickup.Payment.IsPaid = true;

                        //Move
                        var needSaving = MoveConsignmentFromCartToPickup(item.ConsignmentNo, item.ActualWeight, consignmentRequestCart, consignmentRequestPickup);

                        //Save
                        if (needSaving)
                        {
                            Console.WriteLine($"Pickup created");
                            await SaveChanges(context, consignmentRequestPickup, consignmentRequestCart);
                        }
                    }
                    else //Cart not exist
                    {
                        //Fall through, there is no consignmentRequest with the scanner`s PickupNo

                        consignmentRequestsCart = await GetConsignmentRequestByAccountNoAsync(item.AccountNo, item.ConsignmentNo, "false");

                        if (consignmentRequestsCart.Count > 0) //Cart exist (no pickupNo)
                        {
                            //Clone
                            ConsigmentRequest consignmentRequestCart = CloneConsignmentRequestCart(consignmentRequestsCart);

                            //Create
                            ConsigmentRequest consignmentRequestPickup = CreateNewConsignmentRequestPickup(consignmentRequestCart);

                            //Set Pickup.Number
                            consignmentRequestPickup.Pickup.Number = item.PickupNo;

                            //Set IsPickedUp
                            consignmentRequestPickup.Pickup.IsPickedUp = true;

                            //Set IsPaid
                            consignmentRequestPickup.Payment.IsPaid = true;

                            //Move
                            var needSaving = MoveConsignmentFromCartToPickup(item.ConsignmentNo, item.ActualWeight, consignmentRequestCart, consignmentRequestPickup);

                            //Save
                            if (needSaving)
                            {
                                Console.WriteLine($"Pickup created");
                                await SaveChanges(context, consignmentRequestPickup, consignmentRequestCart);
                            }
                        }
                        else
                        {
                            //Fall through
                        }
                    }
                }
            }
        }