private UserResponse BuildResponse(User user) { return(new UserResponse { UserID = user.ID, Email = user.Email, IsAdmin = user.IsAdmin }); }
public async Task <IActionResult> Insert(UserCreationParameters parameters) { FirebaseAuthLink firebaseUser = null; User user = null; try { user = _repo.GetAll().FirstOrDefault(x => x.Email.ToLower() == parameters.Email.ToLower()); if (user == null) { firebaseUser = await _fireRepo.CreateUser(parameters.Email, parameters.Password); User u = new User() { Email = parameters.Email, IsAdmin = parameters.IsAdmin }; _repo.Insert(u); return(CreatedAtAction("GetByID", new { id = u.ID }, BuildResponse(u))); } else { return(ReturnUserFriendlyError(Errors.ExistingEmail)); } } catch { if (firebaseUser != null) { await _fireRepo.DeleteUser(firebaseUser.FirebaseToken); } if (user != null) { _repo.Delete(user.ID); } return(ReturnUserFriendlyError(Errors.Unknown)); } }
private bool IsSuperAdmin(User user) { return(user.ID == 1); }