Esempio n. 1
0
        public async Task Update(
            ISiteUser user,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (user == null)
            {
                throw new ArgumentException("user cannot be null");
            }
            if (user.SiteId == Guid.Empty)
            {
                throw new ArgumentException("user must have a siteid");
            }
            if (user.Id == Guid.Empty)
            {
                throw new ArgumentException("user must have a non-empty id");
            }

            //await EnsureProjectId().ConfigureAwait(false);
            var projectId = user.SiteId.ToString();

            var siteUser = SiteUser.FromISiteUser(user);
            await userCommands.UpdateAsync(
                projectId,
                siteUser.Id.ToString(),
                siteUser,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 2
0
        public async Task Update(
            ICurrency currency,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();
            if (currency == null)
            {
                throw new ArgumentException("currency must not be null");
            }
            if (currency.Id == Guid.Empty)
            {
                throw new ArgumentException("currency must have a non-empty id");
            }

            var c = Currency.FromICurrency(currency);

            await EnsureProjectId().ConfigureAwait(false);

            await currencyCommands.UpdateAsync(
                projectId,
                c.Id.ToString(),
                c,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task Update(
            IGeoCountry geoCountry,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (geoCountry == null)
            {
                throw new ArgumentException("geoCountry must not be null");
            }
            if (geoCountry.Id == Guid.Empty)
            {
                throw new ArgumentException("geoCountry must have a non-empty id");
            }

            await EnsureProjectId().ConfigureAwait(false);

            var country = GeoCountry.FromIGeoCountry(geoCountry); // convert from IGeoCountry

            await countryCommands.UpdateAsync(
                projectId,
                country.Id.ToString(),
                country,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 4
0
        public async Task UpdateByUserCodeAsync(string userCode, DeviceCode data)
        {
            var site = _contextAccessor.HttpContext.GetTenant <SiteContext>();

            if (site == null)
            {
                _logger.LogError("sitecontext was null");
                return;
            }
            var siteId = site.Id.ToString();

            var all = await GetAllInternalAsync(siteId);

            var existing = all
                           .FirstOrDefault(x => x.UserCode == userCode && x.SiteId == siteId);

            if (existing == null)
            {
                _logger.LogError("{userCode} not found in database", userCode);
                throw new InvalidOperationException("Could not update device code");
            }

            var entity = ToEntity(data, existing.DeviceCode, userCode, siteId);

            _logger.LogDebug("{userCode} found in database", userCode);

            existing.SubjectId = data.Subject?.FindFirst(JwtClaimTypes.Subject).Value;
            existing.Data      = entity.Data;

            await _commands.UpdateAsync(siteId, existing.UserCode, existing);
        }
Esempio n. 5
0
        public async Task UpdateRole(
            ISiteRole role,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (role == null)
            {
                throw new ArgumentException("role cannot be null");
            }
            if (role.SiteId == Guid.Empty)
            {
                throw new ArgumentException("SiteId must be provided");
            }
            if (role.Id == Guid.Empty)
            {
                throw new ArgumentException("Id must be provided");
            }

            //await EnsureProjectId().ConfigureAwait(false);
            var projectId = role.SiteId.ToString();

            var siteRole = SiteRole.FromISiteRole(role);

            await roleCommands.UpdateAsync(
                projectId,
                siteRole.Id.ToString(),
                siteRole,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 6
0
        public async Task UpdateUserLocation(
            IUserLocation userLocation,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userLocation == null)
            {
                throw new ArgumentException("userLocation must not be null");
            }
            if (userLocation.Id == Guid.Empty)
            {
                throw new ArgumentException("Id must not be empty guid");
            }
            if (userLocation.UserId == Guid.Empty)
            {
                throw new ArgumentException("UserId must not be empty guid");
            }
            if (userLocation.SiteId == Guid.Empty)
            {
                throw new ArgumentException("SiteId must not be empty guid");
            }

            await EnsureProjectId().ConfigureAwait(false);

            var ul = UserLocation.FromIUserLocation(userLocation);

            await locationCommands.UpdateAsync(
                projectId,
                ul.Id.ToString(),
                ul,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 7
0
        public async Task UpdateClaim(
            IUserClaim userClaim,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userClaim == null)
            {
                throw new ArgumentException("userClaim cannnot be null");
            }
            if (userClaim.Id == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have an id");
            }
            if (userClaim.SiteId == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have n SiteId");
            }
            if (userClaim.UserId == Guid.Empty)
            {
                throw new ArgumentException("userClaim must have a UserId");
            }

            //await EnsureProjectId().ConfigureAwait(false);
            var projectId = userClaim.SiteId.ToString();

            var claim = UserClaim.FromIUserClaim(userClaim);
            await claimCommands.UpdateAsync(
                projectId,
                claim.Id.ToString(),
                claim,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 8
0
        public async Task Update(
            IGeoZone geoZone,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();
            if (geoZone == null)
            {
                throw new ArgumentException("geoZone must not be null");
            }
            if (geoZone.Id == Guid.Empty)
            {
                throw new ArgumentException("geoZone must have a non-empty id");
            }
            if (geoZone.CountryId == Guid.Empty)
            {
                throw new ArgumentException("geoZone must have a non-empty CountryId");
            }

            await EnsureProjectId().ConfigureAwait(false);

            var state = GeoZone.FromIGeoZone(geoZone); // convert from IGeoZone

            await stateCommands.UpdateAsync(
                projectId,
                state.Id.ToString(),
                state,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 9
0
        public async Task Update(
            ISiteSettings site,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (site == null)
            {
                throw new ArgumentException("site must not be null");
            }
            if (site.Id == Guid.Empty)
            {
                throw new ArgumentException("site must have a non-empty Id");
            }

            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            await EnsureProjectId().ConfigureAwait(false);

            var siteSettings = SiteSettings.FromISiteSettings(site);

            await commands.UpdateAsync(projectId,
                                       siteSettings.Id.ToString(),
                                       siteSettings,
                                       cancellationToken).ConfigureAwait(false);
        }
        public async Task Update(
            string projectId,
            IPost post,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            var p = Post.FromIPost(post);

            p.LastModified = DateTime.UtcNow;

            //since we store posts in year month folders we need to check if pubdate changed and move the file if needed by delete and re-reate.
            var currentVersion = await _query.FetchAsync(projectId, p.Id);

            if (currentVersion.PubDate != p.PubDate)
            {
                await _commands.DeleteAsync(projectId, p.Id).ConfigureAwait(false);

                await _commands.CreateAsync(projectId, p.Id, p).ConfigureAwait(false);
            }
            else
            {
                await _commands.UpdateAsync(projectId, p.Id, p).ConfigureAwait(false);
            }

            _cache.ClearListCache(projectId);
        }
Esempio n. 11
0
        public async Task <bool> UpdateMovie(Movie movie)
        {
            await _movieCommands.UpdateAsync(projectId, movie.Id.ToString(), movie).ConfigureAwait(false);

            _cache.Remove(moviesCacheKey);

            return(true);
        }
Esempio n. 12
0
 public async Task UpdateSubscription(PushDeviceSubscription subscription)
 {
     await _commands.UpdateAsync(
         _NoDbProjectId,
         subscription.Key.ToString(),
         subscription
         ).ConfigureAwait(false);
 }
Esempio n. 13
0
        public async Task UpdateClient(string siteId, Client client, CancellationToken cancellationToken = default(CancellationToken))
        {
            await DeleteClientClaims(siteId, client.ClientId, cancellationToken).ConfigureAwait(false);
            await SaveClientClaims(siteId, client, cancellationToken).ConfigureAwait(false);

            // remove the System.Security.Claims because we can't deserialize them
            client.Claims.Clear();
            await _commands.UpdateAsync(siteId, client.ClientId, client, cancellationToken).ConfigureAwait(false);
        }
Esempio n. 14
0
 public async Task Update(
     string projectId,
     IProjectSettings project,
     CancellationToken cancellationToken = default(CancellationToken)
     )
 {
     var p = ProjectSettings.FromIProjectSettings(project);
     await commands.UpdateAsync(projectId, p.Id, p).ConfigureAwait(false);
 }
Esempio n. 15
0
        public async Task <IActionResult> UpdateQuestion(Question question)
        {
            var q = _pageQueriesQuestion.FetchAsync("Cues", question.Id.ToString()).Result;

            if (q != null)
            {
                q.Title        = question.Title;
                q.InternalName = q.Title.ToSlug();
                q.Answer       = question.Answer;
                q.CategoryId   = question.CategoryId ?? q.CategoryId;
                await _pageCommandsQuestion.UpdateAsync("Cues", q.Id.ToString(), q);
            }
            else
            {
                return(NotFound());
            }

            return(new NoContentResult());
        }
        public async Task Update(
            string projectId,
            IPage page,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            var p = Page.FromIPage(page);

            p.LastModified = DateTime.UtcNow;

            await _commands.UpdateAsync(projectId, p.Id, p).ConfigureAwait(false);
        }
Esempio n. 17
0
        public async Task Update(
            string projectId,
            IPage page,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            //if (string.IsNullOrEmpty(page.Id)) { page.Id = Guid.NewGuid().ToString(); }
            var p = Page.FromIPage(page);

            p.LastModified = DateTime.UtcNow;

            await commands.UpdateAsync(projectId, p.Id, p).ConfigureAwait(false);
        }
        public async Task Update(
            string projectId,
            IKvpItem kvp,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            var item = KvpItem.FromIKvpItem(kvp);

            await _kvpCommands.UpdateAsync(
                projectId,
                item.Id,
                item,
                cancellationToken).ConfigureAwait(false);
        }
        public async Task Update(
            string projectId,
            IPost post,
            CancellationToken cancellationToken = default(CancellationToken)
            )
        {
            var p = Post.FromIPost(post);

            p.LastModified = DateTime.UtcNow;

            await commands.UpdateAsync(projectId, p.Id, p).ConfigureAwait(false);

            cache.ClearListCache(projectId);
        }
Esempio n. 20
0
        public async Task Update(
            AuthorizationPolicyInfo policy,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (policy == null)
            {
                throw new ArgumentException("policy cannot be null");
            }

            await _policyCommands.UpdateAsync(
                policy.TenantId,
                policy.Id.ToString(),
                policy,
                cancellationToken).ConfigureAwait(false);

            _cache.ClearListCache(policy.TenantId);
        }
Esempio n. 21
0
        public async Task <ActionResult <string> > UpdateCategory([FromBody] Category category)
        {
            var c = _pageQueriesCategory.FetchAsync("Cues", category.Id.ToString()).Result;

            if (c != null)
            {
                c.Title            = category.Title;
                c.InternalName     = c.Title.ToSlug();
                c.ParentCategoryId = category.ParentCategoryId == 0 ? c.ParentCategoryId : category.ParentCategoryId;
                await _pageCommandsCategory.UpdateAsync("Cues", c.Id.ToString(), c);

                return(new NoContentResult());
            }
            else
            {
                return(NotFound());
            }
        }
Esempio n. 22
0
        public async Task <IActionResult> PutMovie([FromRoute] Guid id, [FromBody] Movie movie)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != movie.Id)
            {
                return(BadRequest());
            }

            await _movieCommands.UpdateAsync(projectId, id.ToString(), movie).ConfigureAwait(false);

            _cache.Remove(moviesCacheKey);

            return(NoContent());
        }
Esempio n. 23
0
        public async Task UpdateToken(
            IUserToken userToken,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();

            if (userToken == null)
            {
                throw new ArgumentException("userToken can't be null");
            }
            if (userToken.LoginProvider.Length == -1)
            {
                throw new ArgumentException("userToken must have a loginprovider");
            }
            if (userToken.Name.Length == -1)
            {
                throw new ArgumentException("userToken must have a Name");
            }
            if (userToken.UserId == Guid.Empty)
            {
                throw new ArgumentException("userToken must have a user id");
            }

            var projectId = userToken.SiteId.ToString();

            var token = UserToken.FromIUserToken(userToken);

            // this will be a tricky one for queries because the key consists of 4 columns
            // TODO: review this and whether we really need all the  parts of the key in EF
            // http://www.jerriepelser.com/blog/using-aspnet-oauth-providers-without-identity
            // ProviderKey is the unique key associated with the login on that service
            var key = token.UserId.ToString()
                      + "~" + token.SiteId.ToString()
                      + "~" + token.LoginProvider
                      + "~" + token.Name;

            await tokenCommands.UpdateAsync(
                projectId,
                key,
                token,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 24
0
        public async Task <IActionResult> Put(string id, [FromBody] object value)
        {
            try
            {
                var original = await cardQueries.FetchAsync("BlueShift", id);

                if (original == null)
                {
                    return(BadRequest(new { error = $"Card with id [{id}] does not exist. You must create a new card or update a card with an existing id." }));
                }

                var card = JsonConvert.DeserializeObject <Card>(value.ToString());
                await cardCommands.UpdateAsync("BlueShift", id, original.UpdateWith(card));

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(new { error = e.Message }));
            }
        }
Esempio n. 25
0
        public async Task Update(
            ILanguage language,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            ThrowIfDisposed();
            cancellationToken.ThrowIfCancellationRequested();
            if (language == null)
            {
                throw new ArgumentException("language must not be null");
            }
            if (language.Id == Guid.Empty)
            {
                throw new ArgumentException("language must have a non-empty id");
            }

            await EnsureProjectId().ConfigureAwait(false);

            var lang = Language.FromILanguage(language);
            await langCommands.UpdateAsync(
                projectId,
                lang.Id.ToString(),
                lang,
                cancellationToken).ConfigureAwait(false);
        }
Esempio n. 26
0
        public async Task StoreAsync(PersistedGrant token)
        {
            try
            {
                var existing = await GetAsync(token.Key).ConfigureAwait(false);

                if (existing == null)
                {
                    if (string.IsNullOrEmpty(token.Key))
                    {
                        token.Key = Guid.NewGuid().ToString();
                    }
                    await _commands.CreateAsync(_siteId, token.Key, token).ConfigureAwait(false);
                }
                else
                {
                    await _commands.UpdateAsync(_siteId, token.Key, token).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(0, ex, "StoreAsync");
            }
        }
Esempio n. 27
0
 public Task UpdateContentCollection(ContentCollection contentCollection)
 {
     return(_contentCollectionCommands.UpdateAsync(contentCollection.ContentType.AppId, contentCollection.Id, contentCollection));
 }
Esempio n. 28
0
 public async Task UpdateIdentityResource(string siteId, IdentityResource resource, CancellationToken cancellationToken = default(CancellationToken))
 {
     await _commands.UpdateAsync(siteId, resource.Name, resource, cancellationToken).ConfigureAwait(false);
 }
Esempio n. 29
0
 public Task UpdateApp(App app)
 {
     return(_appCommands.UpdateAsync(Constants.ApplicationsProjectId, app.Id, app));
 }
Esempio n. 30
0
 public void Update(string triptag, TripItem tripitem)
 {
     _commands.UpdateAsync($"{TripItemsRoot}{triptag}", tripitem.Tag, tripitem).Wait();
 }