Ejemplo n.º 1
0
        public async Task <IActionResult> GetByAccountId([FromRoute] Guid?id, [FromQuery] bool deleted = false)
        {
            IActionResult result = null;

            try
            {
                if (result == null && !id.HasValue || id.Value.Equals(Guid.Empty))
                {
                    result = BadRequest("Missing account id value");
                }
                if (result == null && !UserCanAccessAccount(id.Value))
                {
                    result = StatusCode(StatusCodes.Status401Unauthorized);
                }
                if (result == null)
                {
                    using ILifetimeScope scope = _container.BeginLifetimeScope();
                    SettingsFactory       settingsFactory = scope.Resolve <SettingsFactory>();
                    CoreSettings          settings        = settingsFactory.CreateAccount(_settings.Value);
                    IDomainFactory        domainFactory   = scope.Resolve <IDomainFactory>();
                    IEnumerable <IDomain> domains;
                    if (deleted)
                    {
                        domains = await domainFactory.GetDeletedByAccountId(settings, id.Value);
                    }
                    else
                    {
                        domains = await domainFactory.GetByAccountId(settings, id.Value);
                    }
                    IMapper mapper = MapperConfigurationFactory.CreateMapper();
                    result = Ok(
                        domains.Select <IDomain, Domain>(d => mapper.Map <Domain>(d))
                        );
                }
            }
            catch (Exception ex)
            {
                using (ILifetimeScope scope = _container.BeginLifetimeScope())
                {
                    await LogException(ex, scope.Resolve <IExceptionService>(), scope.Resolve <SettingsFactory>(), _settings.Value);
                }
                result = StatusCode(StatusCodes.Status500InternalServerError);
            }
            return(result);
        }