Example #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());
            }
        }
Example #2
0
        public bool AttemptLogin(String userName, String password)
        {
            String passwordFromDatabase = "";

            System.Collections.Generic.List <Smart_Saver_API.Models.LoginDB> logins = new System.Collections.Generic.List <Smart_Saver_API.Models.LoginDB>();


            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    logins = context.LoginDB.ToList();
                }
            }
            catch (Exception e)
            {
                //_logger?.LogError(e.ToString());
            }

            bool userFound = false;

            foreach (Smart_Saver_API.Models.LoginDB oneUser in logins)
            {
                if (oneUser.Username == userName)
                {
                    passwordFromDatabase = oneUser.Password;
                    userFound            = true;
                    break;
                }
            }

            return((passwordFromDatabase == password) && userFound);
        }
Example #3
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());
            }
        }
Example #4
0
        public IEnumerable <ExpenseDB> ParseOneUserExpenses(String username, string password)
        {
            LoginController loginC = new LoginController();

            int userId = loginC.UserId(username, password);

            List <ExpenseDB> expenses = new List <ExpenseDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    expenses = context.ExpenseDB.ToList();
                }
            }
            catch (Exception e)
            {
                _logger?.LogError(e.ToString());
            }

            List <ExpenseDB> userExpenses = new List <ExpenseDB>();

            foreach (ExpenseDB oneExpense in expenses)
            {
                if (oneExpense.UserId == userId)
                {
                    userExpenses.Add(oneExpense);
                }
            }

            return(userExpenses);
        }
Example #5
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());
            }
        }
Example #6
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());
     }
 }
Example #7
0
        public decimal GetCategoryExpenseAmount(string neededCategory)
        {
            List <ExpenseDB> expenses = new List <ExpenseDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    expenses = context.ExpenseDB.ToList();
                    var categories = from expense in expenses
                                     group expense.expenseAmount by expense.expenseCategory into categoryGroup //<-----------------------------------LINQ
                                     select new { Name = categoryGroup.Key, Amount = categoryGroup.Sum() };
                    foreach (var category in categories)
                    {
                        if (category.Name == neededCategory)
                        {
                            return(category.Amount);
                        }
                    }
                    //If category wasn;t found throw exception
                    throw new Exception("Specified category was not found in the database.");
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
                return(-1);
            }
        }
Example #8
0
        public IEnumerable <GoalDB> ParseOneUserGoal(String username, String password) //Do not use this for several goals
        {
            LoginController loginC = new LoginController();

            int userId = loginC.UserId(username, password);

            List <GoalDB> newGoal = new List <GoalDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    newGoal = context.GoalDB.ToList();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(message: e.ToString());
            }

            List <GoalDB> oneUserGoals = new List <GoalDB>();

            foreach (GoalDB oneGoal in newGoal)
            {
                if (oneGoal.userId == userId)
                {
                    oneUserGoals.Add(oneGoal);
                }
            }

            return(oneUserGoals);
        }
Example #9
0
        public IEnumerable <Smart_Saver_API.Models.IncomeDB> parseOneUserIncomes(String username, string password)
        {
            LoginController loginC = new LoginController();

            int userId = loginC.UserId(username, password);

            List <IncomeDB> income = new List <IncomeDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    income = context.IncomeDB.ToList();
                }
            }
            catch (Exception e)
            {
                _logger?.LogError(e.ToString());
            }

            List <IncomeDB> userIncome = new List <IncomeDB>();

            foreach (IncomeDB oneIncome in income)
            {
                if (oneIncome.userId == userId)
                {
                    userIncome.Add(oneIncome);
                }
            }

            return(userIncome);
        }
Example #10
0
        public IEnumerable <Smart_Saver_API.Models.IncomeDB> ParseIncomes()
        {
            List <IncomeDB> income = new List <IncomeDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    income = context.IncomeDB.ToList();
                }
            }catch (Exception e)
            {
                _logger?.LogError(e.ToString());
            }
            return(income);
        }
Example #11
0
        public IEnumerable <GoalDB> ParseGoal() //Do not use this for several goals
        {
            List <GoalDB> newGoal = new List <GoalDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    newGoal = context.GoalDB.ToList();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(message: e.ToString());
            }
            return(newGoal);
        }
        public string getCategory(int index)
        {
            List <CategoriesDB> ExpenseCategories = new List <CategoriesDB>();

            using (var context = new Data.Smart_Saver_APIContext())
            {
                ExpenseCategories = context.CategoriesDB.ToList();
            }
            foreach (var category1 in ExpenseCategories)
            {
                if (category1.categoryId == index)
                {
                    return(category1.categoryName);
                }
            }
            return(null);
        }
Example #13
0
        public IEnumerable <ExpenseDB> ParseExpenses()
        {
            List <ExpenseDB> expenses = new List <ExpenseDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    expenses = context.ExpenseDB.ToList();
                }
            }
            catch (Exception e)
            {
                _logger?.LogError(e.ToString());
            }
            return(expenses);
        }
Example #14
0
        public void ClearExpenseDB()
        {
            var expenses = ParseExpenses();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    context.ExpenseDB.RemoveRange(expenses);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
Example #15
0
        public decimal GetTotalExpenseAmount()
        {
            List <ExpenseDB> expenses    = new List <ExpenseDB>();
            Decimal          totalAmount = 0;

            using (var context = new Data.Smart_Saver_APIContext())
            {
                expenses = context.ExpenseDB.ToList();

                foreach (var _expenses in expenses)
                {
                    totalAmount += _expenses.expenseAmount;
                }
            }

            return(totalAmount);
        }
Example #16
0
        public string userInfo()
        {
            List <UserDB> user  = new List <UserDB>();
            List <string> listA = new List <string>();

            using (var context = new Data.Smart_Saver_APIContext())
            {
                user = context.UserDB.ToList();

                foreach (var _user in user)
                {
                    listA.Add(_user.userName);
                    listA.Add(_user.userSurname);
                    listA.Add(_user.userAge.ToString());
                }
            }
            return(listA[1] + " " + listA[2]);
        }
        public int getId(string categoryname)
        {
            List <CategoriesDB> ExpenseCategories = new List <CategoriesDB>();
            int z = 1;

            using (var context = new Data.Smart_Saver_APIContext())
            {
                ExpenseCategories = context.CategoriesDB.ToList();
            }
            foreach (var category1 in ExpenseCategories)
            {
                if (category1.categoryName == categoryname)
                {
                    return(category1.categoryId);
                }
                z++;
            }
            return(-1);
        }
Example #18
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());
     }
 }
Example #19
0
        public void RemoveExpenseCategory(string neededCategory)     //unusable because it can be more categories with the same name
        {
            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    var expenses = context.ExpenseDB.Where(p => p.expenseCategory == neededCategory)
                                   .FirstOrDefault();

                    if (expenses is ExpenseDB)
                    {
                        context.Remove(expenses);
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e.ToString());
            }
        }
Example #20
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());
     }
 }
Example #21
0
        public int UserId(String username, String password)
        {
            System.Collections.Generic.List <Smart_Saver_API.Models.LoginDB> logins = new System.Collections.Generic.List <Smart_Saver_API.Models.LoginDB>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    logins = context.LoginDB.ToList();
                }
            }
            catch (Exception e)
            {
                //_logger?.LogError(e.ToString());
            }

            Smart_Saver_API.Models.LoginDB foundUser = new Smart_Saver_API.Models.LoginDB();

            bool userFound = false;

            foreach (Smart_Saver_API.Models.LoginDB oneUser in logins)
            {
                if (oneUser.Username == username)
                {
                    foundUser = oneUser;
                    userFound = true;
                    if (password == foundUser.Password)
                    {
                        return(oneUser.UserId);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }

            return(-1);
        }
Example #22
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());
     }
 }
 public void AddCategory([FromBody] string category)
 {
     try
     {
         CategoriesDB _category           = new CategoriesDB();
         string       categoryToAddString = category;
         string[]     elements            = categoryToAddString.Split(',');
         foreach (string it in elements)
         {
             string _categoryName = elements[0];
             _category.categoryName = _categoryName;
         }
         using (var context = new Data.Smart_Saver_APIContext())
         {
             context.CategoriesDB.Add(_category);
             context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         _logger.LogError(e.ToString());
     }
 }
        public List <string> parseCategories()
        {
            List <CategoriesDB> ExpenseCategories = new List <CategoriesDB>();
            List <string>       expenses          = new List <string>();

            try
            {
                using (var context = new Data.Smart_Saver_APIContext())
                {
                    ExpenseCategories = context.CategoriesDB.ToList();
                }

                foreach (var _expense in ExpenseCategories)
                {
                    expenses.Add(_expense.categoryName);
                }
            }
            catch (Exception e)
            {
                _logger?.LogError(e.ToString());
            }

            return(expenses);
        }
Example #25
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());
     }
 }