예제 #1
0
        private double CalculateTimeUntilMidnight()
        {
            var      warpedNowTime = _timeCalculator.GetCurrentWarpedTime();
            TimeSpan timerInterval = new DateTime(warpedNowTime.Year, warpedNowTime.Month, warpedNowTime.Day, 23, 59, 59, 999) - warpedNowTime;

            double timerIntervalInMiliseconds = Math.Round(timerInterval.TotalSeconds * 1000 / timeWarpFactor);

            return(timerIntervalInMiliseconds);
        }
예제 #2
0
        private void LogIn()
        {
            var loggedCourierId = _menuOptions.LogInUser();

            if (loggedCourierId != 0)
            {
                _loggedCourierId = loggedCourierId;
                _loggedIn        = true;

                CourierSetup();

                _logInDate = _timeCalculator.GetCurrentWarpedTime();
            }
        }
예제 #3
0
        public async Task AddNewPackageAsync(Package newPackage)
        {
            newPackage.Number       = Guid.NewGuid();
            newPackage.DateOfAdding = _timeCalculator.GetCurrentWarpedTime();
            newPackage.State        = Package.PackageState.AwaitingAddingToPackingList;

            using (var context = _dbContextFactoryMethod())
            {
                context.Users.Attach(newPackage.Sender);
                context.Users.Attach(newPackage.Receiver);
                context.Packages.Add(newPackage);
                await context.SaveChangesAsync();
            }
        }
예제 #4
0
        public void ExportCourierPackingListToJsonFile(List <Package> packagesForPackingList, int courierId)
        {
            string systemDrivePath = Path.GetPathRoot(Environment.SystemDirectory);
            string targetPath      = $"{systemDrivePath}shipping_lists";

            Directory.CreateDirectory(targetPath);

            var    listGenerationDate = _timeCalculator.GetCurrentWarpedTime().ToString("yyyy-MM-dd");
            string fileName           = $"{courierId}_{listGenerationDate}.json";
            string filePath           = Path.Combine(targetPath, $"{fileName}");

            AddPackingListInfo(courierId, fileName, targetPath, packagesForPackingList.Count);

            var jsonData = JsonConvert.SerializeObject(packagesForPackingList, Formatting.Indented);

            File.WriteAllText(filePath, jsonData);
        }
예제 #5
0
        public void MarkPackageAsDelivered(List <Package> currentPackingList)
        {
            int userChoice = _ioHelper.GetIntFromUser("Choose package");
            int score;

            if (userChoice <= 0 || userChoice > currentPackingList.Count)
            {
                Console.WriteLine("There is no package with that id");
                return;
            }

            score = _packagesService.DeliverPackage(currentPackingList[userChoice - 1].Id,
                                                    currentPackingList[userChoice - 1].EtaToReceiver,
                                                    _timeCalculator.GetCurrentWarpedTime());

            if (score == 0)
            {
                Console.WriteLine("You have already marked this package as delivered");
                return;
            }

            Console.WriteLine($"Your score for delivering this package is: {score}");
        }
예제 #6
0
 private void GetCurrentDate()
 {
     Console.WriteLine($"Current real time: {_timeCalculator.GetCurrentRealTime()}");
     Console.WriteLine($"Current warped time: {_timeCalculator.GetCurrentWarpedTime()}");
 }