public async Task <IActionResult> GetByIdAsync([FromBody] string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(_exceptionHandler.HandleException(new NullReferenceException("Parameter id is required. Id  was null or empty."), isServerSideException: false));
            }

            IPLUserAccount userAccount;

            try
            {
                var efUserAccount = await _accountAdapter.ReadByIdAsync(id);

                userAccount = new PLUserAccount();

                PropertyCopier <DALUserAccount, PLUserAccount> .Copy((DALUserAccount)efUserAccount, (PLUserAccount)userAccount);

                if (string.IsNullOrEmpty(userAccount.Id) || string.IsNullOrEmpty(userAccount.Email))
                {
                    throw new NullReferenceException("UserAccount has either no Id or email. Probably something went wrong during copying or retreiving data.");
                }
            }
            catch (Exception ex)
            {
                return(_exceptionHandler.HandleException(ex, isServerSideException: true));
            }

            return(Ok(userAccount));
        }
        public async Task <IActionResult> CreateByAccount([FromBody] PLUserAccount userAccount)
        {
            if (!ModelState.IsValid)
            {
                return(_exceptionHandler.HandleException(new Exception("ModelState invalid"), isServerSideException: false));
            }

            try
            {
                var newUserAccount = await _accountAdapter.CreateByAccountAsync(userAccount);

                if (newUserAccount != null && !string.IsNullOrEmpty(newUserAccount.Id) && !string.IsNullOrEmpty(newUserAccount.Email))
                {
                    return(new CreatedAtActionResult(
                               actionName: Constants.AccountControllerEndpoints.CREATE_BY_ACCOUNT,
                               controllerName: Constants.APIControllers.ACCOUNT,
                               routeValues: RouteData.Values,
                               value: newUserAccount));
                }
                else
                {
                    throw new Exception("Creating account failed. The user account was null or had no id after an attempt to create it");
                }
            }
            catch (Exception ex)
            {
                return(_exceptionHandler.HandleException(ex, isServerSideException: true));
            }
        }
        public async Task <IActionResult> UpdateByAccount([FromBody] PLUserAccount userAccount)
        {
            if (ModelState.IsValid == false)
            {
                return(_exceptionHandler.HandleException(new Exception("ModelState invalid"), isServerSideException: false));
            }

            var result = await _accountAdapter.WriteAsync(userAccount);

            if (result.Succeeded == false)
            {
                return(_exceptionHandler.HandleException(new Exception("Something went wrong while updating the user account"), isServerSideException: true));
            }

            return(Ok());
        }
        public async Task <IActionResult> GetByEmailAsync()
        {
            if (!ModelState.IsValid)
            {
                return(_exceptionHandler.HandleException(new NullReferenceException("ModelState was invalid"), isServerSideException: false));
            }

            IPLUserAccount plUserAccount;

            try
            {
                string email = User.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.Email).Value;

                if (String.IsNullOrEmpty(email))
                {
                    throw new NullReferenceException("Email could not be retreived/parsed from the claims");
                }

                var dalUserAccount = await _accountAdapter.ReadByEmailAsync(email);

                plUserAccount = new PLUserAccount();

                PropertyCopier <DALUserAccount, PLUserAccount> .Copy((DALUserAccount)dalUserAccount, (PLUserAccount)plUserAccount);

                if (string.IsNullOrEmpty(plUserAccount.Id))
                {
                    throw new NullReferenceException("UserAccount has no Id . Probably something went wrong during copying or retreiving data.");
                }

                if (string.IsNullOrEmpty(plUserAccount.Email))
                {
                    throw new NullReferenceException("UserAccount has no email. Probably something went wrong during copying or retreiving data.");
                }
            }
            catch (Exception ex)
            {
                return(_exceptionHandler.HandleException(ex, isServerSideException: true));
            }

            return(Ok(plUserAccount));
        }