Esempio n. 1
0
        public string SaveContent([FromBody] SaveContentRequestBody data)
        {
            var contentType = ContentTypeProvider.Get(data.ContentTypeId);

            var b = (IContent)JsonConvert.DeserializeObject(data.Content, contentType.Type);

            if (b.Id != null)
            {
                var a = (IContent)typeof(IContainerSpecificContentGetter).GetMethod(nameof(ContainerSpecificContentGetter.Get)).MakeGenericMethod(contentType.Type).Invoke(ContainerSpecificContentGetter, new[] { data.Id, null, contentType.Container });

                foreach (var propertyDefinition in PropertyDefinitionProvider.GetFor(contentType.Id))
                {
                    var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault();

                    if (display != null && display.GetAutoGenerateField() == false)
                    {
                        continue;
                    }

                    propertyDefinition.Setter(a, propertyDefinition.Getter(b));
                }

                ContainerSpecificContentUpdater.Update(a, contentType.Container);

                return("Updated");
            }
            else
            {
                ContainerSpecificContentCreator.Create(b, contentType.Container);

                return("Saved");
            }
        }
Esempio n. 2
0
        public async Task SetPhoneNumberConfirmedAsync(User user, bool confirmed, CancellationToken cancellationToken)
        {
            user.PhoneNumberConfirmed = confirmed;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 3
0
        public async Task SetPhoneNumberAsync(User user, string phoneNumber, CancellationToken cancellationToken)
        {
            user.PhoneNumber = phoneNumber;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 4
0
        public async Task SetNormalizedEmailAsync(User user, string normalizedEmail, CancellationToken cancellationToken)
        {
            user.NormalizedEmail = normalizedEmail;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 5
0
        public async Task SetPasswordHashAsync(User user, string passwordHash, CancellationToken cancellationToken)
        {
            user.PasswordHash = passwordHash;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 6
0
        public async Task RemoveLoginAsync(User user, string loginProvider, string providerKey, CancellationToken cancellationToken)
        {
            user.Logins.Remove(user.Logins.Single(l => l.ProviderKey == providerKey));

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 7
0
        public async Task AddLoginAsync(User user, UserLoginInfo login, CancellationToken cancellationToken)
        {
            user.Logins.Add(login);

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 8
0
        public async Task <IdentityResult> UpdateAsync(User user, CancellationToken cancellationToken)
        {
            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }

            return(IdentityResult.Success);
        }
Esempio n. 9
0
        public async Task SetUserNameAsync(User user, string userName, CancellationToken cancellationToken)
        {
            user.Username = userName;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 10
0
        public async Task SetEmailConfirmedAsync(CloudyUser user, bool confirmed, CancellationToken cancellationToken)
        {
            user.EmailConfirmed = confirmed;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 11
0
        public async Task SetEmailAsync(CloudyUser user, string email, CancellationToken cancellationToken)
        {
            user.Email = email;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 12
0
        public async Task SetNormalizedUserNameAsync(CloudyUser user, string normalizedName, CancellationToken cancellationToken)
        {
            user.NormalizedUsername = normalizedName;

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 13
0
        public ContentResponseMessage SaveContent([FromBody] SaveContentRequestBody data)
        {
            if (!ModelState.IsValid)
            {
                return(ContentResponseMessage.CreateFrom(ModelState));
            }

            var contentType = ContentTypeProvider.Get(data.ContentTypeId);

            var b = (IContent)JsonConvert.DeserializeObject(data.Content, contentType.Type, PolymorphicFormConverter);

            if (b.Id != null)
            {
                var a = (IContent)typeof(IContainerSpecificContentGetter).GetMethod(nameof(ContainerSpecificContentGetter.Get)).MakeGenericMethod(contentType.Type).Invoke(ContainerSpecificContentGetter, new[] { data.Id, null, contentType.Container });

                foreach (var coreInterface in ContentTypeCoreInterfaceProvider.GetFor(contentType.Id))
                {
                    foreach (var propertyDefinition in coreInterface.PropertyDefinitions)
                    {
                        var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault();

                        if (display != null && display.GetAutoGenerateField() == false)
                        {
                            continue;
                        }

                        propertyDefinition.Setter(a, propertyDefinition.Getter(b));
                    }
                }

                foreach (var propertyDefinition in PropertyDefinitionProvider.GetFor(contentType.Id))
                {
                    var display = propertyDefinition.Attributes.OfType <DisplayAttribute>().FirstOrDefault();

                    if (display != null && display.GetAutoGenerateField() == false)
                    {
                        continue;
                    }

                    propertyDefinition.Setter(a, propertyDefinition.Getter(b));
                }

                ContainerSpecificContentUpdater.Update(a, contentType.Container);

                return(new ContentResponseMessage(true, "Updated"));
            }
            else
            {
                ContainerSpecificContentCreator.Create(b, contentType.Container);

                return(new ContentResponseMessage(true, "Created"));
            }
        }
Esempio n. 14
0
        public async Task AddClaimsAsync(User user, IEnumerable <Claim> claims, CancellationToken cancellationToken)
        {
            if (user.Claims == null)
            {
                user.Claims = new List <Claim>();
            }

            user.Claims.AddRange(claims);

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 15
0
        public async Task RemoveClaimsAsync(User user, IEnumerable <Claim> claims, CancellationToken cancellationToken)
        {
            if (user.Claims == null)
            {
                user.Claims = new List <Claim>();
            }

            var types = claims.Select(c => c.Type);

            user.Claims.RemoveAll(c => types.Contains(c.Type));

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }
Esempio n. 16
0
        public async Task ReplaceClaimAsync(User user, Claim claim, Claim newClaim, CancellationToken cancellationToken)
        {
            if (user.Claims == null)
            {
                user.Claims = new List <Claim>();
            }

            var existing = user.Claims.SingleOrDefault(c => c.Type == claim.Type);

            if (existing != null)
            {
                user.Claims.Remove(existing);
            }

            user.Claims.Add(newClaim);

            if (user.Id != null)
            {
                await ContainerSpecificContentUpdater.UpdateAsync(user, Container);
            }
        }