Esempio n. 1
0
        public async Task <ActionResult> SetEmailStatusAsync(PatchEmailStatus param,
                                                             [FromServices] ICreyService <AccountRepository> accounts,
                                                             [FromServices] IIDInfoAccessor idInfo,
                                                             [FromServices] CreyRestClient creyRestClient)
        {
            var sessionInfo = idInfo.GetSessionInfo();
            await accounts.Value.SetEmailStatusAsync(sessionInfo.AccountId, param);

            return(Ok());
        }
        public async Task SetEmailStatusAsync(int accountId, PatchEmailStatus param)
        {
            //early exit, if PatchEmail gets more attributes (ex email about notifications), it have to be refactored
            if (!param.Newsletter.HasValue)
            {
                return;
            }

            var user = await FindUserByAccountIdAsync(accountId)
                       ?? throw new ItemNotFoundException($"No user exists for account ID {accountId}");

            if (user.NewsletterSubscribed == param.Newsletter)
            {
                return;
            }
            user.NewsletterSubscribed = param.Newsletter.Value;

            await appDBContext_.SaveChangesAsync();
        }