private async Task <Entity.User> EnsureUniquenessOfEmailAndUsernameOnEditAsync(Entity.User user) { var result = await Context .FindAsync(user.Id); if (result != null) { if (result.Email != user.Email) { user.AddNotification(WeatherAttackNotifications.User.EmailCannotBeChanged); } if (result.Username != user.Username) { user.AddNotification(WeatherAttackNotifications.User.UsernameCannotBeChanged); } } return(user); }
private async Task <Entity.User> EnsureUniquenessOfEmailAndUsernameOnAddAsync(Entity.User user) { var result = await Context .GetAsync(u => u.Username == user.Username || u.Email == user.Email); if (result != null) { if (result.Any(r => r.Email == user.Email)) { user.AddNotification(WeatherAttackNotifications.User.EmailAlreadyInUse); } if (result.Any(r => r.Username == user.Username)) { user.AddNotification(WeatherAttackNotifications.User.UsernameAlreadyInUse); } } return(user); }