private void UpdateTaxInfo(TaxInfo dbTaxInfo, TaxInfo clientTaxInfo) { //Update singular properties if (dbTaxInfo.FilingStatus != clientTaxInfo.FilingStatus) { dbTaxInfo.FilingStatus = clientTaxInfo.FilingStatus; } if (dbTaxInfo.Exemptions != clientTaxInfo.Exemptions) { dbTaxInfo.Exemptions = clientTaxInfo.Exemptions; } if (dbTaxInfo.TaxYear != clientTaxInfo.TaxYear) { dbTaxInfo.TaxYear = clientTaxInfo.TaxYear; } if (dbTaxInfo.State != clientTaxInfo.State) { dbTaxInfo.State = clientTaxInfo.State; } //Update DeductionsAndCredits UpdateDeductionsAndCredits(dbTaxInfo.DeductionsAndCredits, clientTaxInfo.DeductionsAndCredits); //Update AdditionalTaxes UpdateAdditionalTaxes(dbTaxInfo.AdditionalTaxes, clientTaxInfo.AdditionalTaxes); }
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); } }
internal static TaxInfo GetDefaults() { TaxInfo taxInfo = new TaxInfo(); //If you update the defaults, also update in budget.service.ts taxInfo.FilingStatus = 0; taxInfo.Exemptions = 1; taxInfo.TaxYear = 2018; taxInfo.State = 0; taxInfo.DeductionsAndCredits = new List <DeductionOrCreditRow>(); taxInfo.AdditionalTaxes = new List <AdditionalTaxRow>(); return(taxInfo); }
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); }