Example #1
0
        public bool CreateAccount(User user)
        {
            BudgetDbContext db = new BudgetDbContext();

            //Check if username is already taken
            if (db.Users.Any(u => u.Username == user.Username))
            {
                return(false);
            }
            else
            {
                //Set defaults
                user.BudgetInputRows = BudgetInputRow.GetDefaults();
                user.TaxInfo         = TaxInfo.GetDefaults();

                //Encrypt password
                user.Salt     = Security.GetSalt();
                user.Password = Security.GetHash(user.Password, user.Salt);

                //Save user to db
                db.Users.Add(user);
                db.SaveChanges();

                return(true);
            }
        }
Example #2
0
        public int GetUserId(string username)
        {
            BudgetDbContext db    = new BudgetDbContext();
            var             query = from u in db.Users
                                    where u.Username == username
                                    select u;

            return(query.Single().Id);
        }
Example #3
0
        public BudgetInputRow[] LoadBudgetInputs(string username, BudgetInputTypes budgetInputType)
        {
            BudgetDbContext db = new BudgetDbContext();

            var user = db.Users
                       .Include(u => u.BudgetInputRows)
                       .Where(u => u.Username == username)
                       .Single();

            return(user.BudgetInputRows.Where(bir => bir.Type == budgetInputType).ToArray());
        }
Example #4
0
        public TaxInfo LoadTaxInfo(string username)
        {
            BudgetDbContext db = new BudgetDbContext();

            User user = db.Users
                        .Include(u => u.TaxInfo)
                        .ThenInclude(ti => ti.DeductionsAndCredits)
                        .Include(u => u.TaxInfo)
                        .ThenInclude(ti => ti.AdditionalTaxes)
                        .Where(u => u.Username == username)
                        .Single();

            return(user.TaxInfo);
        }
Example #5
0
        public bool Save(int userId, List <BudgetInputRow> budgetInputRows, TaxInfo taxInfo)
        {
            BudgetDbContext db = new BudgetDbContext();

            User user = db.Users
                        .Include(u => u.BudgetInputRows)
                        .Include(u => u.TaxInfo)
                        .ThenInclude(ti => ti.DeductionsAndCredits)
                        .Include(u => u.TaxInfo)
                        .ThenInclude(ti => ti.AdditionalTaxes)
                        .Where(u => u.Id == userId)
                        .Single();

            UpdateBudgetInputRows(user.BudgetInputRows, budgetInputRows);
            UpdateTaxInfo(user.TaxInfo, taxInfo);

            db.SaveChanges();

            return(true);
        }
Example #6
0
        public bool ValidateUser(User user)
        {
            if (user == null)
            {
                return(false);
            }

            BudgetDbContext db    = new BudgetDbContext();
            var             query = from u in db.Users
                                    where u.Username == user.Username && ValidatePassword(user.Password, u)
                                    select u;

            try
            {
                query.Single();
            }
            catch
            {
                return(false);
            }

            return(true);
        }