public async Task <ActionResult <DebtModelRead> > GetDebtModel(string mode)
        {
            switch (mode)
            {
            case "now":
                InternalIncreaseModel dbmodel = await _db.GetInternalDebtInfo();

                DebtModelRead model = new DebtModelRead {
                    Day = dbmodel.Time, Debt = dbmodel.Debt, Increase = dbmodel.Increase
                };
                if (model is not null)
                {
                    TimeSpan timeElapsed = DateTime.Now - model.Day;
                    double   increase    = timeElapsed.TotalSeconds * model.Increase;
                    model.Debt += increase;
                    model.Day   = DateTime.Now;
                    return(Ok(model));
                }
                else
                {
                    return(NotFound());
                }

            case "last":
                return(await GetDebtModel());

            default: return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public async Task CalculateAndInsertNewInfo()
        {
            List <InternalDebtModel> internalDebts = _context.InternalDebtsAPI.ToList();
            InternalIncreaseModel    internalModel = _converter.ConvertInternalFromBaseModel(CalculateIncreaseModel(internalDebts));

            _context.InternalDebtsInfo.Add(internalModel);

            List <ExternalDebtModel> externalDebts = _context.ExternalDebtsAPI.ToList();
            ExternalIncreaseModel    externalModel = _converter.ConvertExternalFromBaseModel((CalculateIncreaseModel(externalDebts)));

            _context.ExternalDebtsInfo.Add(externalModel);

            _context.SaveChanges();
        }
        public async Task <ActionResult <DebtModelRead> > GetDebtModel()
        {
            InternalIncreaseModel dbmodel = await _db.GetInternalDebtInfo();

            //TODO:add automapper
            DebtModelRead model = new DebtModelRead {
                Day = dbmodel.Time, Debt = dbmodel.Debt, Increase = dbmodel.Increase
            };

            if (model is not null)
            {
                return(Ok(model));
            }
            else
            {
                return(NotFound());
            }
        }
        public async Task <InternalIncreaseModel> GetInternalDebtInfo()
        {
            InternalIncreaseModel model = await _context.InternalDebtsInfo.OrderBy(x => x.Time).LastOrDefaultAsync();

            return(model);
        }
        public InternalIncreaseModel ConvertInternalFromBaseModel(IncreaseModelBase model)
        {
            InternalIncreaseModel internalModel = new InternalIncreaseModel(model.Time, model.Debt, model.Increase);

            return(internalModel);
        }