/// <summary> /// Creates a new user /// </summary> /// <param name="newUser">The <see cref="User"></see></param> #region Private Methods private void CreateUser(User newUser) { try { string newPass; if (newUser.PasswordHash.Trim() == string.Empty) { var randomWordPass = GenerateRandomPassword(); newPass = Authentication.Compute(randomWordPass); } else { newPass = newUser.PasswordHash; } var user = new User { Username = newUser.Email, Email = newUser.Email, PasswordHash = newPass, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now, }; using (var ctx = new MyBillsContext()) { ctx.Entry(newUser).State = EntityState.Unchanged; ctx.Users.Add(user); ctx.SaveChanges(); newUser.Id = user.Id; } _logRepository.WriteLog(LogLevel.Debug, "UserRepository.CreateUser", $"New User Created - {user.Email}"); } catch (Exception ex) { _logRepository.WriteLog(LogLevel.Error, "UserRepository.CreateUser", ex.Message, ex); } }
/// <summary> /// Updates an existing bill /// </summary> /// <param name="bill">The bill to update</param> public void UpdateBill(Bill bill) { using var ctx = new MyBillsContext(); ctx.Entry(bill).State = EntityState.Modified; ctx.SaveChanges(); }