예제 #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);
            }
        }
예제 #2
0
        private void UpdateBudgetInputRows(List <BudgetInputRow> dbRows, List <BudgetInputRow> clientRows)
        {
            //Make db rows match rows sent from client
            for (int rowIdx = 0; rowIdx < clientRows.Count; rowIdx++)
            {
                BudgetInputRow clientRow = clientRows[rowIdx];

                if (rowIdx < dbRows.Count)
                {
                    //Potentially modified row

                    BudgetInputRow dbRow = dbRows[rowIdx];

                    //Go through each relevant property, so we only change what's different
                    if (dbRow.Label != clientRow.Label)
                    {
                        dbRow.Label = clientRow.Label;
                    }

                    if (dbRow.Monthly != clientRow.Monthly)
                    {
                        dbRow.Monthly = clientRow.Monthly;
                    }

                    if (dbRow.PreTax != clientRow.PreTax)
                    {
                        dbRow.PreTax = clientRow.PreTax;
                    }

                    if (dbRow.RowNum != clientRow.RowNum)
                    {
                        dbRow.RowNum = clientRow.RowNum;
                    }

                    if (dbRow.Type != clientRow.Type)
                    {
                        dbRow.Type = clientRow.Type;
                    }
                }
                else
                {
                    //Added row
                    dbRows.Add(clientRow);
                }
            }

            //Remove any additional rows from db
            int numToRemove = dbRows.Count - clientRows.Count;

            if (numToRemove > 0)
            {
                dbRows.RemoveRange(clientRows.Count, numToRemove);
            }
        }