public ConsentGroupModel Create(ConsentGroup entity) { var consentGroupModel = new ConsentGroupModel() { Name = entity.Name, Description = entity.Description, Id = entity.Id }; if (entity.Consents?.Any() ?? false) { consentGroupModel.Consents = entity.Consents.Select(Create).ToList(); } return(consentGroupModel); }
public ConsentGroupModel Create(ConsentGroup consentGroup, int[] acceptedConsentIds, int[] deniedConsentIds) { var model = Create(consentGroup); foreach (var consentModel in model.Consents) { if (acceptedConsentIds.Contains(consentModel.Id)) { consentModel.ConsentStatus = ConsentStatus.Accepted; } else if (deniedConsentIds.Contains(consentModel.Id)) { consentModel.ConsentStatus = ConsentStatus.Denied; } else { consentModel.ConsentStatus = ConsentStatus.NotSelected; } } return(model); }
public void User_Consents_Tests_Succeeds() { var user = new User() { Name = "Test User", CreatedOn = DateTime.UtcNow, UpdatedOn = DateTime.UtcNow, LastLoginDate = null, Active = true }; _userService.Insert(user); var consentGroup = new ConsentGroup() { Name = "Test Consent Group", Description = "Test" }; _consentGroupService.Insert(consentGroup); var consents = new List <Consent>() { new Consent() { Title = "Group Consent", ConsentGroupId = consentGroup.Id, Published = true }, new Consent() { Title = "Group Consent 2", ConsentGroupId = consentGroup.Id, IsRequired = true, Published = true }, new Consent() { Title = "Default Consent", OneTimeSelection = true, Published = true } }; _consentService.Insert(consents.ToArray()); _gdprService.SetUserConsents(user.Id, new Dictionary <int, ConsentStatus>() { { consents[0].Id, ConsentStatus.Denied }, { consents[1].Id, ConsentStatus.Accepted }, }); var userConsents = _gdprService.GetUserConsents(user.Id); Assert.AreEqual(2, userConsents.Count); Assert.IsFalse(_gdprService.IsConsentAccepted(user.Id, consents[0].Id)); Assert.IsTrue(_gdprService.IsConsentAccepted(user.Id, consents[1].Id)); Assert.IsFalse(_gdprService.IsConsentAccepted(user.Id, consents[2].Id)); Assert.IsTrue(_gdprService.AreConsentsActedUpon(user.Id, consents[0].Id, consents[1].Id)); Assert.IsFalse(_gdprService.AreConsentsActedUpon(user.Id, consents[0].Id, consents[1].Id, consents[2].Id)); var pendingConsents = _gdprService.GetPendingConsents(user.Id); Assert.AreEqual(1, pendingConsents.Count); }