/// <summary> /// /// </summary> /// <param name="userId"></param> /// <param name="user"></param> /// <returns></returns> public async Task <bool> UpdateUserAsync(int userId, Models.TransferObjects.User user) { var found = await Context.Users.FindAsync(userId); if (found == null) { return(false); } found.FirstName = user.FirstName; found.LastName = user.LastName; found.PictureUrl = user.PictureUrl; Context.Users.Update(found); await Context.SaveChangesAsync(); return(true); }
internal async Task <int> InsertUserInternalAsync(Models.TransferObjects.User user, bool isVerified) { if (!PasswordCriteria.IsValid(user.Password)) { return(0); } var passwordHash = AuthenticationHelper.EncryptPassword(user.Password); var u = await Context.Users.AddAsync(new Models.DbModels.User { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, PictureUrl = user.PictureUrl, PasswordHash = passwordHash, IsVerified = isVerified }); await Context.SaveChangesAsync(); return(u.Entity.Id); }
/// <summary> /// /// </summary> /// <param name="user"></param> /// <returns></returns> public async Task <GenericManagerResponse <AuthToken, InsertUserResponse> > InsertUserAsync(Models.TransferObjects.User user) { var found = await Context.Users.FirstOrDefaultAsync(u => u.Email == user.Email); if (found == null) { var userId = await InsertUserInternalAsync(user, false); if (userId == 0) { return(new GenericManagerResponse <AuthToken, InsertUserResponse>(InsertUserResponse.PasswordCriteriaNotSatisfied, null)); } await SendAccountVerificationEmail(user.Email); var token = await authManager.GenerateTokenAsync(userId, user.DeviceId); return(new GenericManagerResponse <AuthToken, InsertUserResponse>(InsertUserResponse.Success, token)); } return(new GenericManagerResponse <AuthToken, InsertUserResponse>(InsertUserResponse.EmailExists, null)); }