コード例 #1
0
ファイル: Program.cs プロジェクト: MarKamenov/TelerikAcademy
        // Write a program to model the bank system by classes and interfaces.
        // Identify the classes, interfaces, base classes and abstract actions
        // and implement the calculation of the interest functionality through overridden methods.
        private static void Main()
        {
            Client client1 = new ClientIndividual("Neo");
            Client client2 = new ClientCompany("Office 1");
            Client client3 = new ClientIndividual("Nakov");

            Account acc1 = new DepositAccount(client1, 5, "BG13TLRK01");
            Account acc2 = new LoanAccount(client2, 4.5m, "BG13TLRK02");
            Account acc3 = new MortgageAccount(client3, 8.8m, "BG13TLRK03");

            acc1.DepositMoney(1000);
            ((DepositAccount)acc1).WithdrawMoney(500);
            acc2.DepositMoney(10000);

            Bank bank = new Bank("New Bank");

            bank.AddAccount(acc1);
            bank.AddAccount(acc2);
            bank.AddAccount(acc3);

            Console.WriteLine(bank.Accounts);

            Console.WriteLine();
            Console.WriteLine("IBAN: {0} ({1}), Interest: {2:F2}", acc1.IBAN, acc1.Owner.Name, acc1.CalculateInterest(5));
            Console.WriteLine("IBAN: {0} ({1}), Interest: {2:F2}", acc2.IBAN, acc2.Owner.Name, acc2.CalculateInterest(6));
            Console.WriteLine("IBAN: {0} ({1}), Interest: {2:F2}", acc3.IBAN, acc3.Owner.Name, acc3.CalculateInterest(18));

            Console.WriteLine("\nRemoving account 1");
            bank.RemoveAccount(acc1);
            Console.WriteLine(bank.Accounts);
        }
コード例 #2
0
        public virtual IActionResult GetCCW([FromQuery] string regi, [FromQuery] string plate, [FromQuery] string vin)
        {
            // check we have the right headers.
            if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(guid) || string.IsNullOrEmpty(directory))
            {
                return(new UnauthorizedResult());
            }

            // Check for the following data:
            // 1. registration
            // 2. plate
            // 3. decal

            VehicleDescription vehicle = null;

            if (regi != null)
            {
                // format the regi.
                try
                {
                    int registration = int.Parse(regi);
                    // zero padded, 8 digits
                    regi = registration.ToString("D8");
                }
                catch (Exception e)
                {
                    _logger.LogInformation("Exception occured parsing registration number " + regi);
                }

                try
                {
                    vehicle = _service.GetBCVehicleForRegistrationNumber(regi, userId, guid, directory);
                }
                catch (Exception e)
                {
                    vehicle = null;
                }
            }
            if (vehicle == null && plate != null) // check the plate.
            {
                try
                {
                    vehicle = _service.GetBCVehicleForLicensePlateNumber(plate, userId, guid, directory);
                }
                catch (Exception e)
                {
                    vehicle = null;
                }
            }
            if (vehicle == null && vin != null) // check the vin.
            {
                try
                {
                    vehicle = _service.GetBCVehicleForSerialNumber(vin, userId, guid, directory);
                }
                catch (Exception e)
                {
                    vehicle = null;
                }
            }
            if (vehicle == null)
            {
                return(new StatusCodeResult(404)); // Can't find the vehicle.
            }
            else
            {
                string  icbcRegistrationNumber = vehicle.registrationNumber;
                CCWData ccwdata  = null;
                bool    existing = false;
                if (_context.CCWDatas.Any(x => x.ICBCRegistrationNumber == icbcRegistrationNumber))
                {
                    ccwdata  = _context.CCWDatas.First(x => x.ICBCRegistrationNumber == icbcRegistrationNumber);
                    existing = true;

                    _logger.LogInformation("Found record for Registration # " + ccwdata.ICBCRegistrationNumber);
                }
                else
                {
                    _logger.LogInformation("Creating new record");
                    ccwdata = new CCWData();
                }
                // update the ccw record.

                ccwdata.ICBCBody               = vehicle.bodyCode;
                ccwdata.ICBCColour             = vehicle.colour;
                ccwdata.ICBCCVIPDecal          = vehicle.inspectionDecalNumber;
                ccwdata.ICBCCVIPExpiry         = vehicle.inspectionExpiryDate;
                ccwdata.ICBCFleetUnitNo        = SanitizeInt(vehicle.fleetUnitNumber);
                ccwdata.ICBCFuel               = vehicle.fuelTypeDescription;
                ccwdata.ICBCGrossVehicleWeight = SanitizeInt(vehicle.grossVehicleWeight);
                ccwdata.ICBCMake               = vehicle.make;
                ccwdata.ICBCModel              = vehicle.model;
                ccwdata.ICBCGrossVehicleWeight = SanitizeInt(vehicle.grossVehicleWeight);
                ccwdata.ICBCModelYear          = SanitizeInt(vehicle.modelYear);
                ccwdata.ICBCNetWt              = SanitizeInt(vehicle.netWeight);
                ccwdata.ICBCNotesAndOrders     = vehicle.cvipDataFromLastInspection;
                ccwdata.ICBCOrderedOn          = vehicle.firstOpenOrderDate;
                ccwdata.ICBCRateClass          = vehicle.rateClass;
                ccwdata.ICBCRebuiltStatus      = vehicle.statusCode;
                ccwdata.ICBCRegistrationNumber = vehicle.registrationNumber;
                ccwdata.ICBCRegOwnerAddr1      = vehicle.owner.mailingAddress1;
                ccwdata.ICBCRegOwnerAddr2      = vehicle.owner.mailingAddress2;
                ccwdata.ICBCRegOwnerCity       = vehicle.owner.mailingAddress3;
                ccwdata.ICBCRegOwnerName       = vehicle.owner.name1;
                ccwdata.ICBCRegOwnerPODL       = vehicle.principalOperatorDlNum;
                ccwdata.ICBCRegOwnerPostalCode = vehicle.owner.postalCode;
                ccwdata.ICBCRegOwnerProv       = vehicle.owner.mailingAddress4;
                ccwdata.ICBCRegOwnerRODL       = vehicle.owner.driverLicenseNumber;
                ccwdata.ICBCSeatingCapacity    = SanitizeInt(vehicle.seatingCapacity);
                ccwdata.ICBCVehicleType        = vehicle.vehicleType + " - " + vehicle.vehicleTypeDescription;

                ccwdata.ICBCVehicleIdentificationNumber = vehicle.serialNumber;

                ccwdata.NSCPlateDecal          = vehicle.decalNumber;
                ccwdata.NSCPolicyEffectiveDate = vehicle.policyStartDate;
                ccwdata.NSCPolicyExpiryDate    = vehicle.policyExpiryDate;
                ccwdata.NSCPolicyStatus        = vehicle.policyStatus + " - " + vehicle.policyStatusDescription;

                // policyAquiredCurrentStatusDate is the preferred field, however it is often null.
                if (vehicle.policyAcquiredCurrentStatusDate != null)
                {
                    ccwdata.NSCPolicyStatusDate = vehicle.policyAcquiredCurrentStatusDate;
                }
                else if (vehicle.policyTerminationDate != null)
                {
                    ccwdata.NSCPolicyStatusDate = vehicle.policyTerminationDate;
                }
                else if (vehicle.policyReplacedOnDate != null)
                {
                    ccwdata.NSCPolicyStatusDate = vehicle.policyReplacedOnDate;
                }
                else if (vehicle.policyStartDate != null)
                {
                    ccwdata.NSCPolicyStatusDate = vehicle.policyStartDate;
                }

                if (vehicle.owner != null)
                {
                    ccwdata.ICBCRegOwnerRODL = vehicle.owner.driverLicenseNumber;
                }
                ccwdata.ICBCLicencePlateNumber = vehicle.policyNumber;
                // these fields are the same.
                ccwdata.NSCPolicyNumber = vehicle.policyNumber;
                ccwdata.NSCClientNum    = vehicle.nscNumber;

                ccwdata.DateFetched = DateTime.UtcNow;

                // get the nsc client organization data.

                bool foundNSCData = false;

                if (!string.IsNullOrEmpty(ccwdata.NSCPolicyNumber))
                {
                    string organizationNameCode = "LE";
                    try
                    {
                        ClientOrganization clientOrganization = _service.GetCurrentClientOrganization(ccwdata.NSCClientNum, organizationNameCode, userId, guid, directory);
                        foundNSCData = true;
                        ccwdata.NSCCarrierConditions   = clientOrganization.nscInformation.carrierStatus;
                        ccwdata.NSCCarrierName         = clientOrganization.displayName;
                        ccwdata.NSCCarrierSafetyRating = clientOrganization.nscInformation.safetyRating;
                    }
                    catch (AggregateException ae)
                    {
                        _logger.LogInformation("Aggregate Exception occured during GetCurrentClientOrganization");
                        ae.Handle((x) =>
                        {
                            if (x is FaultException <CVSECommonException> ) // From the web service.
                            {
                                _logger.LogDebug("CVSECommonException:");
                                FaultException <CVSECommonException> fault = (FaultException <CVSECommonException>)x;
                                _logger.LogDebug("errorId: {0}", fault.Detail.errorId);
                                _logger.LogDebug("errorMessage: {0}", fault.Detail.errorMessage);
                                _logger.LogDebug("systemError: {0}", fault.Detail.systemError);
                                return(true);
                            }
                            return(true); // ignore other exceptions
                        });
                    }
                    catch (Exception e)
                    {
                        _logger.LogInformation("Unknown Error retrieving NSC data.");
                    }

                    // now try the individual service if there was no match.

                    if (foundNSCData == false)
                    {
                        try
                        {
                            ClientIndividual clientIndividual = _service.GetCurrentClientIndividual(ccwdata.NSCClientNum, organizationNameCode, userId, guid, directory);
                            foundNSCData = true;
                            ccwdata.NSCCarrierConditions   = clientIndividual.nscInformation.carrierStatus;
                            ccwdata.NSCCarrierName         = clientIndividual.displayName;
                            ccwdata.NSCCarrierSafetyRating = clientIndividual.nscInformation.safetyRating;
                        }
                        catch (AggregateException ae)
                        {
                            _logger.LogInformation("Aggregate Exception occured during GetCurrentClientIndividual");
                            ae.Handle((x) =>
                            {
                                if (x is FaultException <CVSECommonException> ) // From the web service.
                                {
                                    _logger.LogDebug("CVSECommonException:");
                                    FaultException <CVSECommonException> fault = (FaultException <CVSECommonException>)x;
                                    _logger.LogDebug("errorId: {0}", fault.Detail.errorId);
                                    _logger.LogDebug("errorMessage: {0}", fault.Detail.errorMessage);
                                    _logger.LogDebug("systemError: {0}", fault.Detail.systemError);
                                    return(true);
                                }
                                return(true); // ignore other exceptions
                            });
                        }
                        catch (Exception e)
                        {
                            _logger.LogInformation("Unknown Error retrieving Individual NSC data.");
                        }
                    }
                }

                if (ccwdata.Id > 0)
                {
                    _context.Update(ccwdata);
                }
                else
                {
                    _context.Add(ccwdata);
                }
                _context.SaveChanges();


                return(new ObjectResult(ccwdata));
            }
        }
コード例 #3
0
ファイル: CCWDataService.cs プロジェクト: sauru22/schoolbus
        public CCWData GetCCW(string regi, string plate, string vin, string userId, string guid, string directory)
        {
            // check we have the right headers.
            if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(guid) || string.IsNullOrEmpty(directory))
            {
                return(null);
            }

            var batchUser = _configuration.GetValue <string>("CCW_USER_ID");
            var logPrefix = batchUser == userId ? "[Hangfire]" : "";

            // Check for the following data:
            // 1. registration
            // 2. plate
            // 3. decal

            VehicleDescription vehicle = null;

            if (regi != null)
            {
                // format the regi.
                try
                {
                    int registration = int.Parse(regi);
                    // zero padded, 8 digits
                    regi = registration.ToString("D8");
                }
                catch (Exception)
                {
                    _logger.LogInformation($"{logPrefix} Exception occured parsing registration number {regi}.");
                }

                vehicle = _ccwService.GetBCVehicleForRegistrationNumber(regi, userId, guid, directory);
            }

            if (vehicle == null && plate != null) // check the plate.
            {
                vehicle = _ccwService.GetBCVehicleForLicensePlateNumber(plate, userId, guid, directory);
            }

            if (vehicle == null && vin != null) // check the vin.
            {
                vehicle = _ccwService.GetBCVehicleForSerialNumber(vin, userId, guid, directory);
            }

            if (vehicle == null)
            {
                return(null);
            }

            string icbcRegistrationNumber = vehicle.registrationNumber;

            CCWData ccwdata = null;

            if (_context.CCWDatas.Any(x => x.ICBCRegistrationNumber == icbcRegistrationNumber))
            {
                ccwdata = _context.CCWDatas.First(x => x.ICBCRegistrationNumber == icbcRegistrationNumber);
                _logger.LogInformation($"{logPrefix} Found CCW record for Registration # " + ccwdata.ICBCRegistrationNumber);
            }
            else
            {
                _logger.LogInformation($"{logPrefix} Creating new CCW record");
                ccwdata = new CCWData();
            }

            // update the ccw record.
            ccwdata.ICBCBody               = vehicle.bodyCode;
            ccwdata.ICBCColour             = vehicle.colour;
            ccwdata.ICBCCVIPDecal          = vehicle.inspectionDecalNumber;
            ccwdata.ICBCCVIPExpiry         = vehicle.inspectionExpiryDate;
            ccwdata.ICBCFleetUnitNo        = SanitizeInt(vehicle.fleetUnitNumber);
            ccwdata.ICBCFuel               = vehicle.fuelTypeDescription;
            ccwdata.ICBCGrossVehicleWeight = SanitizeInt(vehicle.grossVehicleWeight);
            ccwdata.ICBCMake               = vehicle.make;
            ccwdata.ICBCModel              = vehicle.model;
            ccwdata.ICBCGrossVehicleWeight = SanitizeInt(vehicle.grossVehicleWeight);
            ccwdata.ICBCModelYear          = SanitizeInt(vehicle.modelYear);
            ccwdata.ICBCNetWt              = SanitizeInt(vehicle.netWeight);
            ccwdata.ICBCNotesAndOrders     = vehicle.cvipDataFromLastInspection;
            ccwdata.ICBCOrderedOn          = vehicle.firstOpenOrderDate;
            ccwdata.ICBCRateClass          = vehicle.rateClass;
            ccwdata.ICBCRebuiltStatus      = vehicle.statusCode;
            ccwdata.ICBCRegistrationNumber = vehicle.registrationNumber;
            ccwdata.ICBCRegOwnerAddr1      = vehicle.owner.mailingAddress1;
            ccwdata.ICBCRegOwnerAddr2      = vehicle.owner.mailingAddress2;
            ccwdata.ICBCRegOwnerCity       = vehicle.owner.mailingAddress3;
            ccwdata.ICBCRegOwnerName       = vehicle.owner.name1;
            ccwdata.ICBCRegOwnerPODL       = vehicle.principalOperatorDlNum;
            ccwdata.ICBCRegOwnerPostalCode = vehicle.owner.postalCode;
            ccwdata.ICBCRegOwnerProv       = vehicle.owner.mailingAddress4;
            ccwdata.ICBCRegOwnerRODL       = vehicle.owner.driverLicenseNumber;
            ccwdata.ICBCSeatingCapacity    = SanitizeInt(vehicle.seatingCapacity);
            ccwdata.ICBCVehicleType        = vehicle.vehicleType + " - " + vehicle.vehicleTypeDescription;

            ccwdata.ICBCVehicleIdentificationNumber = vehicle.serialNumber;

            ccwdata.NSCPlateDecal          = vehicle.decalNumber;
            ccwdata.NSCPolicyEffectiveDate = vehicle.policyStartDate;
            ccwdata.NSCPolicyExpiryDate    = vehicle.policyExpiryDate;
            ccwdata.NSCPolicyStatus        = vehicle.policyStatus + " - " + vehicle.policyStatusDescription;

            // policyAquiredCurrentStatusDate is the preferred field, however it is often null.
            if (vehicle.policyAcquiredCurrentStatusDate != null)
            {
                ccwdata.NSCPolicyStatusDate = vehicle.policyAcquiredCurrentStatusDate;
            }
            else if (vehicle.policyTerminationDate != null)
            {
                ccwdata.NSCPolicyStatusDate = vehicle.policyTerminationDate;
            }
            else if (vehicle.policyReplacedOnDate != null)
            {
                ccwdata.NSCPolicyStatusDate = vehicle.policyReplacedOnDate;
            }
            else if (vehicle.policyStartDate != null)
            {
                ccwdata.NSCPolicyStatusDate = vehicle.policyStartDate;
            }

            if (vehicle.owner != null)
            {
                ccwdata.ICBCRegOwnerRODL = vehicle.owner.driverLicenseNumber;
            }

            ccwdata.ICBCLicencePlateNumber = vehicle.policyNumber;
            // these fields are the same.
            ccwdata.NSCPolicyNumber = vehicle.policyNumber;
            ccwdata.NSCClientNum    = vehicle.nscNumber;

            ccwdata.DateFetched = DateTime.UtcNow;

            // get the nsc client organization data.

            bool foundNSCData = false;

            if (!string.IsNullOrEmpty(ccwdata.NSCPolicyNumber))
            {
                string organizationNameCode = "LE";

                ClientOrganization clientOrganization = _ccwService.GetCurrentClientOrganization(ccwdata.NSCClientNum, organizationNameCode, userId, guid, directory);

                if (clientOrganization != null)
                {
                    foundNSCData = true;
                    ccwdata.NSCCarrierConditions   = clientOrganization.nscInformation.carrierStatus;
                    ccwdata.NSCCarrierName         = clientOrganization.displayName;
                    ccwdata.NSCCarrierSafetyRating = clientOrganization.nscInformation.safetyRating;
                }

                // now try the individual service if there was no match.
                if (foundNSCData == false)
                {
                    ClientIndividual clientIndividual = _ccwService.GetCurrentClientIndividual(ccwdata.NSCClientNum, organizationNameCode, userId, guid, directory);

                    if (clientIndividual != null)
                    {
                        foundNSCData = true;
                        ccwdata.NSCCarrierConditions   = clientIndividual.nscInformation.carrierStatus;
                        ccwdata.NSCCarrierName         = clientIndividual.displayName;
                        ccwdata.NSCCarrierSafetyRating = clientIndividual.nscInformation.safetyRating;
                    }
                }
            }

            if (ccwdata.Id > 0)
            {
                var bus = _context.SchoolBuss.FirstOrDefault(x => x.CCWDataId == ccwdata.Id);

                var changes = _context.GetChanges(ccwdata, "DateFetched");

                if (bus != null && changes.Count > 0)
                {
                    var ccwNotification = (new CCWNotification
                    {
                        HasBeenViewed = false,
                    });

                    bus.CCWNotifications.Add(ccwNotification);

                    foreach (var change in changes)
                    {
                        ccwNotification.CCWNotificationDetails.Add(new CCWNotificationDetail
                        {
                            ColName        = change.ColName,
                            ColDescription = change.ColDescription,
                            ValueFrom      = change.ValueFrom,
                            ValueTo        = change.ValueTo
                        });
                    }
                }
            }
            else
            {
                _context.Add(ccwdata);
            }

            _logger.LogInformation($"{logPrefix} CCW data has been added/updated.");
            _context.SaveChanges();

            return(ccwdata);
        }