Esempio n. 1
0
        private decimal Price()
        {
            GetQuote lastPage = (GetQuote)Context.Handler;

            baseRate = BaseRate.calculate(lastPage.DOM, lastPage.Engine);
            return(PremiumCalculator.calculate(baseRate, lastPage.Bonus, lastPage.AdditionalDriverFlag));
        }
Esempio n. 2
0
        public static async Task <IEnumerable <BaseRate> > ImportLatestBaseRatesAsync()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            HttpResponseMessage response = null;
            string          result       = null;
            List <BaseRate> baseRates    = new List <BaseRate>();

            using (HttpClient client = ConfigureHttpClient())
            {
                foreach (string baseRateType in Enum.GetNames(typeof(BaseRate.RateType)))
                {
                    response = await client.GetAsync($"/webservices/VilibidVilibor/VilibidVilibor.asmx/getLatestVilibRate?RateType={baseRateType}");

                    if (response.IsSuccessStatusCode)
                    {
                        result = await response.Content.ReadAsStringAsync();
                    }

                    BaseRate baseRate = new BaseRate();
                    baseRate.Code  = (BaseRate.RateType)Enum.Parse(typeof(BaseRate.RateType), baseRateType);
                    baseRate.Date  = DateTime.Today;
                    baseRate.Value = GetBaseRate(result);

                    baseRates.Add(baseRate);
                }
            }

            return(baseRates);
        }
        public ActionResult Details(int?id, int?newBaseRateId)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Agreement agreement = db.Agreements.Find(id);

            if (agreement == null)
            {
                return(HttpNotFound());
            }

            if (newBaseRateId == null)
            {
                return(View(agreement));
            }

            BaseRate baseRate = db.BaseRates.Find(newBaseRateId);

            agreement.InterestRate      = InterBankRates.GetInterestRate(agreement.BaseRate.BaseRateCode, agreement.Margin);
            agreement.NewInterestRate   = InterBankRates.GetInterestRate(baseRate.BaseRateCode, agreement.Margin);
            agreement.InterestRatesDiff = agreement.InterestRate - agreement.NewInterestRate;
            agreement.NewBaseRateId     = (int)newBaseRateId;

            ViewBag.NewBaseRateId = GetBaseRatesDropdown();

            return(View(agreement));
        }
        /// <summary>
        /// Run the code example.
        /// </summary>
        /// <param name="user">The DFP user object running the code example.</param>
        public override void Run(DfpUser user)
        {
            // Get the BaseRateService.
            BaseRateService baseRateService =
                (BaseRateService)user.GetService(DfpService.v201605.BaseRateService);

            long baseRateId = long.Parse(_T("INSERT_BASE_RATE_ID_HERE"));

            // Create a statement to get the baseRate.
            StatementBuilder statementBuilder = new StatementBuilder()
                                                .Where("id = :id")
                                                .OrderBy("id ASC")
                                                .Limit(1)
                                                .AddValue("id", baseRateId);

            try {
                // Get base rates by statement.
                BaseRatePage page =
                    baseRateService.getBaseRatesByStatement(statementBuilder.ToStatement());

                BaseRate baseRate = page.results[0];

                // Update base rate value to $3 USD.
                Money newRate = new Money()
                {
                    currencyCode = "USD", microAmount = 3000000L
                };

                if (baseRate is ProductTemplateBaseRate)
                {
                    ((ProductTemplateBaseRate)baseRate).rate = newRate;
                }
                else if (baseRate is ProductBaseRate)
                {
                    ((ProductBaseRate)baseRate).rate = newRate;
                }

                // Update the base rates on the server.
                BaseRate[] baseRates = baseRateService.updateBaseRates(new BaseRate[] { baseRate });

                if (baseRates != null)
                {
                    foreach (BaseRate updatedBaseRate in baseRates)
                    {
                        Console.WriteLine("Base rate with ID ='{0}' and type '{1}' belonging to rate card " +
                                          "'{2}' was updated.", baseRate.id, baseRate.GetType().Name, baseRate.rateCardId);
                    }
                }
                else
                {
                    Console.WriteLine("No base rates updated.");
                }
            } catch (Exception e) {
                Console.WriteLine("Failed to update base rates. Exception says \"{0}\"",
                                  e.Message);
            }
        }
Esempio n. 5
0
        // build up the requested analyses for this run from the list of analyzer params
        internal void PrepareAndStartCountingAnalyzers(CountingAnalysisParameters ap)
        {
            if (ap == null)
            {
                logger.TraceEvent(LogLevels.Error, 1519, "No counting analyzers specified");
                return;
            }

            bool good = false;

            foreach (SpecificCountingAnalyzerParams sap in ap)
            {
                if (!sap.Active) // skip disabled analyzers
                {
                    continue;
                }
                if (sap is BaseRate)
                {
                    BaseRate b = (BaseRate)sap;
                    good = State.Sup.AddRates(b.gateWidthTics);
                    if (!good)
                    {
                        // perhaps the gate is too large
                        // dev note : each analyzer should publish it's limits with constant attributes on the class
                        good = State.Sup.AddRates(b.gateWidthTics = (ulong)1e7);
                        logger.TraceEvent(LogLevels.Warning, 1512, "Rate analyzer gatewidth created with default {0} ticks", b.gateWidthTics);
                    }
                }
                else if (sap is Multiplicity)
                {
                    Multiplicity m = (Multiplicity)sap;
                    good = State.Sup.AddMultiplicity(m, m.FA);
                }
                else if (sap is Rossi)
                {
                    Rossi r = (Rossi)sap;
                    good = State.Sup.AddRossi(r.gateWidthTics);
                }
                else if (sap is Feynman)
                {
                    Feynman f = (Feynman)sap;
                    good = State.Sup.AddFeynman(f.gateWidthTics);
                }
                else if (sap is TimeInterval)
                {
                    TimeInterval ti = (TimeInterval)sap;
                    good = State.Sup.AddTimeInterval(ti.gateWidthTics);
                }
                else if (sap is Coincidence)
                {
                    Coincidence co = (Coincidence)sap;
                    good = State.Sup.AddCoincidenceMatrix(co);
                }
            }
        }
        public void BaseRate_GetInterestRate_Should_Return_Correct_Reate(decimal rate, decimal balance, decimal expected)
        {
            //Arrange
            var _sut = new BaseRate()
            {
                Rate = rate
            };

            //Act
            var interest = _sut.GetInterestRate(balance);

            //Assert
            Assert.Equal(expected, interest);
        }
Esempio n. 7
0
        public bool AddBaseRate(string currencyCode, string currencyName)
        {
            bool result = false;

            using (GrainBarrelContext gbc = new GrainBarrelContext())
            {
                BaseRate baseRate = new BaseRate()
                {
                    CurrencyCode = currencyCode, CurrencyName = currencyName
                };
                gbc.BaseRates.Add(baseRate);
                gbc.SaveChanges();
            }
            result = true;
            return(result);
        }
Esempio n. 8
0
        public IHttpActionResult UpdateAgreement(int id, [FromBody] BaseRate.RateType newBaseRateType)
        {
            Agreement agreement = db.Agreements.Include("Customer").SingleOrDefault(x => x.Id == id);

            if (agreement == null)
            {
                return(NotFound());
            }

            BaseRate.RateType oldBaseRateType = agreement.BaseRateType;
            agreement.BaseRateType = newBaseRateType;

            db.MarkAsModified(agreement);

            try
            {
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }

            // check if base rate record exists

            BaseRate currentBaseRate = db.BaseRates.SingleOrDefault(x => x.Code == oldBaseRateType);
            BaseRate newBaseRate     = db.BaseRates.SingleOrDefault(x => x.Code == newBaseRateType);

            if (currentBaseRate == null || newBaseRate == null)
            {
                // Better solution would be to throw a custom exception with an error message

                return(InternalServerError(new ArgumentNullException("Base Rate record was not found")));
            }

            // to client we need to return an agreement with an old base rate type
            agreement.BaseRateType = oldBaseRateType;

            var agremeentExtended = Agreements.GetExtendedAgreement(agreement, newBaseRateType, currentBaseRate.Value, newBaseRate.Value);

            return(Ok(agremeentExtended));
        }
Esempio n. 9
0
        public bool UpdateBaseRate(string currencyCode, string currencyName)
        {
            bool result = false;

            using (GrainBarrelContext gbc = new GrainBarrelContext())
            {
                var      target   = gbc.BaseRates.SingleOrDefault(b => b.CurrencyCode == currencyCode);
                BaseRate baseRate = new BaseRate()
                {
                    CurrencyCode = currencyCode, CurrencyName = currencyName
                };
                if (target != null)
                {
                    target = baseRate;
                    gbc.SaveChanges();
                    result = true;
                }
            }
            return(result);
        }
Esempio n. 10
0
        public ActionResult GetNewInterestRate(int?id, int?val)
        {
            if (id != null && val != null)
            {
                Agreement agreement = db.Agreements.Find(id);
                BaseRate  baseRate  = db.BaseRates.Find(val);

                var InterestRate    = InterBankRates.GetInterestRate(agreement.BaseRate.BaseRateCode, agreement.Margin);
                var NewInterestRate = InterBankRates.GetInterestRate(baseRate.BaseRateCode, agreement.Margin);
                return(Json(new {
                    Success = "true",
                    Data = new {
                        CurrentInterestRate = InterestRate,
                        NewInterestRate = NewInterestRate,
                        InterestRatesDiff = InterestRate - NewInterestRate
                    }
                }));
            }
            return(Json(new { Success = "false" }));
        }
Esempio n. 11
0
        public void Write(Lib.XmlExporter xml, Data.IInvoice pool, Event evt)
        {
            xml.Writer.WriteStartElement("KSG_KPG");

            xml.WriteIfValid("N_KSG", KsgNumber);
            xml.Writer.WriteElementString("VER_KSG", Version.ToString());
            xml.WriteBool("KSG_PG", SubgroupUsed);
            xml.WriteIfValid("N_KPG", KpgNumber);

            xml.Writer.WriteElementString("KOEF_Z", QuotExpense.ToString("F5", Options.NumberFormat));
            xml.Writer.WriteElementString("KOEF_UP", QuotManagement.ToString("F5", Options.NumberFormat));
            xml.Writer.WriteElementString("BZTSZ", BaseRate.ToString("F2", Options.NumberFormat));
            xml.Writer.WriteElementString("KOEF_D", QuotDifference.ToString("F5", Options.NumberFormat));
            xml.Writer.WriteElementString("KOEF_U", QuotGroupLevel.ToString("F5", Options.NumberFormat));

            // TODO: D4 Multiple
            xml.WriteIfValid("CRIT", AuxCriterion);

            // TODO:
            // D4: SL_K
            xml.WriteBool("SL_K", KslpUsed);

            List <ComplexityQuotient> qs = pool.LoadComplexityQuotients().ToList();

            if (qs.Count() > 0)
            {
                double acc = qs.Select(q => q.Quotient).Aggregate(1.0, (a, b) => { return(a * b); });
                if (acc > 0)
                {
                    xml.Writer.WriteElementString("IT_SL", acc.ToString("F5", Options.NumberFormat));
                    foreach (ComplexityQuotient q in qs)
                    {
                        q.Write(xml, pool);
                    }
                }
            }

            // TODO: D4 SL_KOEF УМ

            xml.Writer.WriteEndElement();
        }
Esempio n. 12
0
 public bool Transfer(BaseRate ba, RateResult rates)
 {
     if (rates == null)
         return true;
     bool res = true;
     try
     {
         RatesResultEnhanced rrm = new RatesResultEnhanced(rates.numCompletedGates, ba.gateWidthTics);
         rrm.totaltime = new TimeSpan(this.TS.Ticks);
         countresults.Add(ba, rrm);
         rrm.TransferRawResult(rates);
     }
     catch (OutOfMemoryException e)
     {
         ba.reason = "BaseRate transfer " + e.Message;
         res = false;
         logger.TraceEvent(LogLevels.Error, 87405, ba.reason);
     }
     return res;
 }
Esempio n. 13
0
 public void MarkAsModified(BaseRate baseRate)
 {
     Entry(baseRate).State = EntityState.Modified;
 }
Esempio n. 14
0
 public void MarkAsModified(BaseRate baseRate)
 {
 }