public User Create(User user, string password) { // create password byte[] passwordHash, passwordSalt; passwordHash = GenerateHashPassword(password, out passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; // add user _context.Users.Add(user); try { _context.SaveChanges(); } catch (Exception ex) { _logger.LogCritical("Exception while SaveChanges", ex); throw new Exception(ex.Message); } // created succefful return(user); }
public bool Save() { var AddedEntities = _context.ChangeTracker.Entries().Where(E => E.State == EntityState.Added).ToList(); AddedEntities.ForEach(E => { string displayName = E.Metadata.DisplayName(); if (displayName == "Card" || displayName == "Taskboard") { E.Property("Created").CurrentValue = DateTime.Now; } }); var EditedEntities = _context.ChangeTracker.Entries().Where(E => E.State == EntityState.Modified).ToList(); EditedEntities.ForEach(E => { string displayName = E.Metadata.DisplayName(); if (displayName == "Card" || displayName == "Taskboard") { E.Property("Updated").CurrentValue = DateTime.Now; } }); return(_context.SaveChanges() >= 0); }