Пример #1
0
        public void CreateFare(Fare fare, string operatorCode)
        {
            var selectedOperator = _operatorService.GetOperatorByCode(operatorCode);

            if (selectedOperator == null)
            {
                selectedOperator = new Operator {
                    Id = Guid.NewGuid(), Code = operatorCode
                };
                _operatorService.Create(selectedOperator);
            }

            // check for any active fare in selected operator
            if (!FareService.GetFares()
                .Any(f => {
                var span = DateTimeOffset.UtcNow - f.CreatedOn;
                var months = Math.Floor(span.TotalDays / 30);     // for simplicity

                return(f.OperatorId == selectedOperator.Id && f.Status == 1 && months <= 6);
            }))
            {
                fare.OperatorId = selectedOperator.Id;
                fare.Status     = 1;
                fare.CreatedOn  = DateTimeOffset.UtcNow;
                FareService.Create(fare);
            }
            else
            {
                throw new Exception($"Erro: não é possível cadastrar nova tarifa para {operatorCode}.\n" +
                                    "Motivo: { operatorCode } possui uma tarifa ativa.");
            }
        }
Пример #2
0
        public void CreateFare(Fare fare, string operatorCode)
        {
            var selectedOperator = _operatorService.GetOperatorByCode(operatorCode);

            fare.OperatorId = selectedOperator.Id;

            FareService.Create(fare);
        }