Esempio n. 1
0
        public void addGoal([FromBody] string goaltoAdd)
        {
            try
            {
                GoalDB   _goal           = new GoalDB();
                string   goalToAddString = goaltoAdd;
                string[] elements        = goalToAddString.Split(',');
                foreach (string it in elements)
                {
                    string   _goalName   = elements[0];
                    decimal  _goalAmount = decimal.Parse(elements[1]);
                    DateTime _goalDate   = DateTime.Parse(elements[2]);
                    int      _userid     = Int32.Parse(FrontendController.Instance().userId());

                    _goal.goalName   = _goalName;
                    _goal.goalAmount = _goalAmount;
                    _goal.goalDate   = _goalDate;
                    _goal.userId     = _userid;
                }
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    context.GoalDB.Add(_goal);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
Esempio n. 2
0
 public void AddIncomeWeb([FromBody] string income)
 {
     try
     {
         IncomeDB _income           = new IncomeDB();
         string   incomeToAddString = income;
         string[] elements          = incomeToAddString.Split(',');
         foreach (string it in elements)
         {
             decimal  _incomeAmount = decimal.Parse(elements[0]);
             DateTime _incomeDate   = DateTime.Parse(elements[1]);
             int      _userid       = Int32.Parse(FrontendController.Instance().userId());
             _income.incomeAmount = _incomeAmount;
             _income.incomeDate   = _incomeDate;
             _income.userId       = _userid;
         }
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.IncomeDB.Add(_income);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }
Esempio n. 3
0
        public void AddExpenseWeb([FromBody] string expenseToAdd)
        {
            try
            {
                ExpenseDB _expense           = new ExpenseDB();
                string    expenseToAddString = expenseToAdd;
                string[]  elements           = expenseToAddString.Split(',');
                foreach (string it in elements)
                {
                    string   _expenseName   = elements[0];
                    decimal  _expenseAmount = decimal.Parse(elements[1]);
                    DateTime _expenseDate   = DateTime.Parse(elements[2]);
                    String   _category      = elements[3];
                    int      _userid        = Int32.Parse(FrontendController.Instance().userId());

                    _expense.expenseName     = _expenseName;
                    _expense.expenseAmount   = _expenseAmount;
                    _expense.expenseDate     = _expenseDate;
                    _expense.categoryId      = CategoriesController.Instance().getId(_category);
                    _expense.expenseCategory = CategoriesController.Instance().getCategory(_expense.categoryId);
                    _expense.UserId          = _userid;
                }
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    context.ExpenseDB.Add(_expense);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
Esempio n. 4
0
        public void AddExpenseWeb([FromBody] string recurringincomeadd)
        {
            try
            {
                ReccuringIncomeDB _recurringincome           = new ReccuringIncomeDB();
                string            reccuringIncomeToAddString = recurringincomeadd;
                string[]          elements = reccuringIncomeToAddString.Split(',');
                foreach (string it in elements)
                {
                    decimal  _reccuringIncomeAmount = decimal.Parse(elements[0]);
                    DateTime _reccuringDateFrom     = DateTime.Parse(elements[1]);
                    DateTime _reccuringDateUntil    = DateTime.Parse(elements[2]);
                    int      _userid = Int32.Parse(FrontendController.Instance().userId());

                    _recurringincome.reccuringincomeAmount    = _reccuringIncomeAmount;
                    _recurringincome.reccuringincomeDateFrom  = _reccuringDateFrom;
                    _recurringincome.reccuringincomeDateUntil = _reccuringDateUntil;
                    _recurringincome.userId = _userid;
                }
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    context.ReccuringIncomeDB.Add(_recurringincome);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
Esempio n. 5
0
        private static FrontendController _instance = null; //Singleton pattern

        public static FrontendController Instance()         //Lazy Load initiation
        {
            if (_instance == null)
            {
                _instance = new FrontendController();
            }
            return(_instance);
        }
Esempio n. 6
0
 [Route("add-income")] //Unusable
 //  [EnableCors("AllowOrigin")]
 public void AddIncome(decimal amount, DateTime date)
 {
     try
     {
         IncomeDB _income = new IncomeDB()
         {
             incomeAmount = amount,
             incomeDate   = date,
             userId       = Int32.Parse(FrontendController.Instance().userId())
         };
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.IncomeDB.Add(_income);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }
Esempio n. 7
0
 [Route("add-income-object")]               //Unusable
 //  [EnableCors("AllowOrigin")]
 public void PostNewIncome(IncomeDB income) //Models (general classes) in seperate project - lib
 {
     try
     {
         IncomeDB _income = new IncomeDB()
         {
             incomeAmount = income.incomeAmount,
             incomeDate   = income.incomeDate,
             userId       = Int32.Parse(FrontendController.Instance().userId())
         };
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.IncomeDB.Add(_income);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }
Esempio n. 8
0
 public void AddIncome(decimal amount, DateTime dateFrom, DateTime dateUntil)
 {
     try
     {
         ReccuringIncomeDB _income = new ReccuringIncomeDB()
         {
             reccuringincomeAmount    = amount,
             reccuringincomeDateFrom  = dateFrom,
             reccuringincomeDateUntil = dateUntil,
             userId = Int32.Parse(FrontendController.Instance().userInfo())
         };
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.ReccuringIncomeDB.Add(_income);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }
Esempio n. 9
0
 public void AddExpense(ExpenseDB expenseToAdd)
 {
     try
     {
         ExpenseDB _expense = new ExpenseDB()
         {
             expenseName     = expenseToAdd.expenseName,
             expenseAmount   = expenseToAdd.expenseAmount,
             expenseDate     = expenseToAdd.expenseDate,
             categoryId      = CategoriesController.Instance().getId(expenseToAdd.expenseCategory),
             expenseCategory = CategoriesController.Instance().getCategory(CategoriesController.Instance().getId(expenseToAdd.expenseCategory)),
             UserId          = Int32.Parse(FrontendController.Instance().userId())
         };
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.ExpenseDB.Add(_expense);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }