Beispiel #1
0
        public async Task <IActionResult> Token([FromBody] LoginDto dto)
        {
            var webSecurity = HttpContext.Request.Headers["WebSecurity"].ToString();

            string tenantId = _tenantFactory.GetTenantId(webSecurity);

            var secret = await _tenantFactory.GetSecretByTenantIdAsync(tenantId);

            var result = await _oAuthClient.EnsureApiTokenAsync(dto.Username,
                                                                dto.Password, secret);

            return(Ok(result));
        }
Beispiel #2
0
        /// <summary>
        /// Tracking self entity base
        /// </summary>
        private void HandleTracking()
        {
            foreach (var entry in ChangeTracker.Entries <EntityTenant>())
            {
                if (entry.Entity.IsNoneTracking)
                {
                    continue;
                }
                EntityTracking entity;
                switch (entry.State)
                {
                case EntityState.Detached:
                case EntityState.Modified:
                    entity = entry.Entity as EntityTracking;
                    if (entity != null)
                    {
                        entity.Version++;
                        entity.ModifiedDate = _tenantFactory.GetCurrentClientTime();
                        entity.ModifiedBy   = _tenantFactory.GetUserName();
                    }


                    break;

                case EntityState.Added:
                    entry.Entity.TenantId = _tenantFactory.GetTenantId();
                    entity = entry.Entity as EntityTracking;
                    if (entity != null)
                    {
                        entity.Version     = 0;
                        entity.CreatedDate = _tenantFactory.GetCurrentClientTime();
                        entity.CreatedBy   = _tenantFactory.GetUserName();
                    }
                    break;

                case EntityState.Unchanged:
                    break;

                case EntityState.Deleted:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
Beispiel #3
0
        private void HandleTracking()
        {
            foreach (var entry in ChangeTracker.Entries <EntityVersionTenant>())
            {
                if (entry.Entity.IsNoneTracking)
                {
                    continue;
                }
                EntityTracking entity;
                switch (entry.State)
                {
                case EntityState.Detached:
                case EntityState.Modified:
                    entry.Entity.Version++;
                    entity = (entry.Entity as EntityTracking);
                    if (entity != null)
                    {
                        entity.ModifiedDate = new DateTimeOffset(DateTime.UtcNow, TimeSpan.FromMinutes(TenantFactory.GetClientOffset()));
                        entity.ModifiedBy   = TenantFactory.GetUserName();
                    }
                    break;

                case EntityState.Added:
                    entry.Entity.Version  = 0;
                    entry.Entity.TenantId = TenantFactory.GetTenantId();
                    entity = (entry.Entity as EntityTracking);
                    if (entity != null)
                    {
                        entity.CreatedDate  = new DateTimeOffset(DateTime.UtcNow, TimeSpan.FromMinutes(TenantFactory.GetClientOffset()));
                        entity.CreatedBy    = TenantFactory.GetUserName();
                        entity.ModifiedDate = new DateTimeOffset(DateTime.UtcNow, TimeSpan.FromMinutes(TenantFactory.GetClientOffset()));
                        entity.ModifiedBy   = TenantFactory.GetUserName();
                    }
                    break;
                }
            }
        }
Beispiel #4
0
 private void SetPredicate()
 {
     _predicate = PredicateBuilder.New <TEntity>();
     _predicate.Start(o => !o.IsDeleted);
     _predicate.And(o => o.TenantId.Equals(_tenantFactory.GetTenantId()));
 }