private IBillingTariff CreateTariff(TariffOption tariffType)
        {
            IBillingTariff tariff;

            switch (tariffType)
            {
            case TariffOption.FreeAtNight:
            {
                tariff = new FreeAtNightTariff(5, TariffOption.FreeAtNight, 100);
                break;
            }

            case TariffOption.FreeMinutesEasy:
            {
                tariff = new FreeMinutesTariff(new TimeSpan(0, 50, 0), 3, TariffOption.FreeMinutesEasy, 120);
                break;
            }

            case TariffOption.FreeMinutesStandart:
            {
                tariff = new FreeMinutesTariff(new TimeSpan(0, 100, 0), 2, TariffOption.FreeMinutesStandart, 150);
                break;
            }

            default:
            {
                tariff = new FreeMinutesTariff(new TimeSpan(0, 100, 0), 2, TariffOption.FreeMinutesStandart, 150);
                break;
            }
            }
            return(tariff);
        }
Exemple #2
0
 public FreeMinutesTariff(TimeSpan freeMinutes, int costPerMinute, TariffOption tariffType, int tariffCost)
 {
     FreeMinutes        = freeMinutes;
     CurrentFreeMinutes = freeMinutes;
     CostPerMinute      = costPerMinute;
     TariffType         = tariffType;
     TariffCostPerMonth = tariffCost;
 }
 public Contract(string firstName, string lastName, int terminalNumber,
                 TariffOption tariff, DateTime signDate)
 {
     SubscriberFirstName = firstName;
     SubscriberLastName  = lastName;
     TerminalNumber      = terminalNumber;
     Tariff   = tariff;
     SignDate = signDate;
 }
 public bool ChangeTariff(TariffOption tariff)
 {
     if (TariffUpdateDate <= DateTime.Now.AddMonths(-1))
     {
         Tariff = tariff;
         Console.WriteLine("\nTariff successfully change.");
         return(true);
     }
     else
     {
         Console.WriteLine("\nTariff already changed in this month.");
         return(false);
     }
 }
        public async Task <TariffOption> CreateAsync(int tariffId, int optionDescriptionId)
        {
            var query = from option in _context.TariffOptions
                        where option.TariffId == tariffId && option.TariffOptionDescriptionId == optionDescriptionId
                        select new TariffOption
            {
                TariffOptionDescriptionId = option.TariffOptionDescriptionId,
                TariffOptionDescription   = option.TariffOptionDescription,
                TariffId = option.TariffId,
                Tariff   = option.Tariff
            };

            if (query.FirstOrDefault() != null)
            {
                return(null);
            }

            var tariff = _context.Tariffs.FirstOrDefault(x => x.Id == tariffId);
            var tariffOptionDescription = _context.TariffOptionsDescriptions.FirstOrDefault(x => x.Id == optionDescriptionId);

            var tariffOption = new TariffOption
            {
                TariffOptionDescriptionId = optionDescriptionId,
                TariffOptionDescription   = tariffOptionDescription,
                TariffId = tariffId,
                Tariff   = tariff
            };

            _context.TariffOptions.Add(tariffOption);
            await _context.SaveChangesAsync();

            var userForLog = await _userManager.FindByEmailAsync(_httpContext.User.Identity.Name);

            _logger.LogInformation("UserName: {0} | UserId: {1} | Request: {2} | PostMessage: {3}",
                                   userForLog.UserName,
                                   userForLog.Id,
                                   _httpContext.Request.GetRawTarget(),
                                   $"An option Name:{tariffOptionDescription.Name}, Id: {tariffOptionDescription.Id} was assigned to a tariff Name: {tariff.Name}, Id: {tariff.Id}");

            return(tariffOption);
        }
 public void ChangeTariff(int number, TariffOption tariffType)
 {
     if (_billing.Repository.ContainsKey(number))
     {
         IBillingTariff currentTariff = _billing.Repository[number].Tariff;
         if (currentTariff.TariffType != tariffType)
         {
             if (_billing.Repository[number].Contract.ChangeTariff(tariffType))
             {
                 _billing.Repository[number].Tariff = CreateTariff(tariffType);
             }
         }
         else
         {
             Console.WriteLine("You alredy used this tariff.");
         }
     }
     else
     {
         Console.WriteLine("Abonunt with number {0} does not exist.", number);
     }
 }
        private ISubscriberInfo CreateSubscriberInfo(TariffOption tariffType, int number, IContract contract)
        {
            IBillingTariff tariff = CreateTariff(tariffType);

            return(new SubscriberInfo(number, tariff, contract));
        }
        public void SignContract(string firstName, string lastName, int terminalNumber, TariffOption tariffType)
        {
            if (!_billing.Repository.ContainsKey(terminalNumber))
            {
                IContract       newContract    = new Contract(firstName, lastName, terminalNumber, tariffType, DateTime.Now);
                ITerminal       newTerminal    = ProduseTerminal(terminalNumber);
                IPort           newPort        = ProdusePort(newTerminal);
                ISubscriberInfo subscriberInfo = CreateSubscriberInfo(tariffType, terminalNumber, newContract);

                _billing.AddSubscriberInfo(terminalNumber, subscriberInfo);
                _station.AddMapItem(terminalNumber, newPort, newTerminal);
            }
            else
            {
                Console.WriteLine("\nThis number alredy used. Please choose another number.\n");
            }
        }
 public FreeAtNightTariff(int costPerMinute, TariffOption tariffType, int tariffCost)
 {
     CostPerMinute      = costPerMinute;
     TariffType         = tariffType;
     TariffCostPerMonth = tariffCost;
 }