Ejemplo n.º 1
0
        public async Task <Location> ExecuteQueryAsync(Queries.LocationByInvitationId query,
                                                       CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(query?.Id))
            {
                return(null);
            }

            using (ApplicationContext context = this.databaseContextProvider.CreateContext())
            {
                ReadModels.Location model = await context.Locations
                                            .AsNoTracking()
                                            .FirstOrDefaultAsync(
                    entity => entity.Invitations.Any(invitation =>
                                                     invitation.Id.Equals(query.Id, StringComparison.InvariantCultureIgnoreCase) &&
                                                     !invitation.Accepted), cancellationToken)
                                            .ConfigureAwait(false);

                return(model == null ? null : this.mapper.Map <Location>(model));
            }
        }
Ejemplo n.º 2
0
        public async Task <Location> ExecuteQueryAsync(Queries.LocationByName query,
                                                       CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(query?.Name) ||
                string.IsNullOrWhiteSpace(this.currentUserProvider?.User?.Name))
            {
                return(null);
            }

            using (ApplicationContext context = this.databaseContextProvider.CreateContext())
            {
                ReadModels.Location model = await context.Locations
                                            .AsNoTracking()
                                            .FirstOrDefaultAsync(
                    entity => entity.Name.Equals(query.Name, StringComparison.InvariantCultureIgnoreCase) &&
                    entity.Owner.Equals(this.currentUserProvider.User.Name.ToSha256(),
                                        StringComparison.InvariantCultureIgnoreCase), cancellationToken)
                                            .ConfigureAwait(false);

                return(model == null ? null : this.mapper.Map <Location>(model));
            }
        }