public bool ChangeEmail(ChangeEmailTO emailDetails) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { var result = _authRepository.ChangeEmail(emailDetails.OldEmail, emailDetails.NewEmail); if (result) { scope.Complete(); var cacheItem = ApplicationCache <UserInfoTO> .GetCacheItem(d => d.Email == emailDetails.OldEmail); if (cacheItem != null) { var newCacheItem = new UserInfoTO() { Id = cacheItem.Id, Email = emailDetails.NewEmail, UserName = cacheItem.UserName, Roles = cacheItem.Roles }; ApplicationCache <UserInfoTO> .RemoveCacheItem(cacheItem); ApplicationCache <UserInfoTO> .AddCacheItem(newCacheItem); } return(true); } return(false); } }
public IHttpActionResult ChangeEmail(ChangeEmailTO emailDetails) { string identityUserName = HttpContext.Current.User.Identity.Name; bool emailExists = _authService.CheckIfEmailExists(emailDetails.NewEmail); if (emailExists) { return(BadRequest(UserENUM.EMAIL_ALREADY_TAKEN.ToString())); } emailDetails.OldEmail = _authService.GetUserEmail(identityUserName); bool result = _authService.ChangeEmail(emailDetails); if (result) { logger.Log(LogLevel.Info, "Email was changed for user: "******".\n"); return(Ok()); } return(BadRequest(UserENUM.UNABLE_CHANGE_EMAIL.ToString())); }