Esempio n. 1
0
        private void AddNewPackageToSystem()
        {
            if (!_userService.CheckIfThereIsAtLeastOnePossibleSender())
            {
                Console.WriteLine("\n" + "Database empty - there are no possible senders!" + "\n");
                return;
            }

            if (!_vehicleService.CheckIfThereIsAtLeasOneCourierVehicle())
            {
                Console.WriteLine("\n" + "There are no courier vehicles added to the system!" + "\n");
                return;
            }

            Console.WriteLine("\n" + "Adding a new package to the system");

            var newPackage  = new Package();
            var senderEmail = _ioHelper.GetTextFromUser("Enter sender's email");

            if (!_userService.CheckIfSenderIsInDatabase(senderEmail))
            {
                Console.WriteLine("Sender is not in database!");
                return;
            }
            newPackage.Sender   = _userService.GetSenderByEmail(senderEmail);
            newPackage.Receiver = _ioHelper.GetPackageReceiver(newPackage.Sender.Address);

            if (newPackage.Receiver == null)
            {
                return;
            }

            newPackage.Weight = _ioHelper.GetPackageWeight();

            _packageService.AddNewPackageAsync(newPackage).Wait();

            Console.WriteLine("\n" + "Package added!");
        }
 public async Task PostPackage([FromBody] Package package)
 {
     await _packageService.AddNewPackageAsync(package);
 }