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); } }
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); }