Exemple #1
0
        public async Task <bool> IsAccepted(Guid userAgreementId, Guid personId)
        {
            var userConsent = _userConsentRepository.Find(userAgreementId, p => p.PersonId == personId)?.Items?.FirstOrDefault();

            if (userConsent == null)
            {
                return(false);
            }

            if (userConsent.IsAccepted && userConsent.ExpiresOnUTC >= DateTime.UtcNow)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <IActionResult> Post([FromBody] UserConsent value)
        {
            if (value == null)
            {
                ModelState.AddModelError("Save", "No data passed");
                return(BadRequest(ModelState));
            }

            try
            {
                var userConsent = repository.Find(null, p => p.PersonId == SecurityContext.PersonId && p.UserAgreementID == value.UserAgreementID)?.Items?.FirstOrDefault();
                if (userConsent != null)
                {
                    userConsent.IsAccepted = value.IsAccepted;
                    if (value.IsAccepted)
                    {
                        userConsent.ExpiresOnUTC = DateTime.UtcNow.AddYears(1);
                    }
                    return(await base.PutEntity(userConsent.Id.ToString(), userConsent).ConfigureAwait(false));
                }
                else
                {
                    var userAgreementConsent = new UserConsent()
                    {
                        PersonId        = value.PersonId,
                        UserAgreementID = value.UserAgreementID,
                        IsAccepted      = value.IsAccepted,
                        ExpiresOnUTC    = DateTime.UtcNow.AddYears(1)
                    };
                    return(await base.PostEntity(userAgreementConsent));
                }
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }