public HomeController(IDataSource dataSource, IDomainFactory domainFactory) { Contract.Requires(dataSource != null); Contract.Requires(domainFactory != null); domain = domainFactory.Create(dataSource); }
public async Task <IActionResult> Create([FromBody] Domain domain) { IActionResult result = null; try { if (result == null && domain == null) { result = BadRequest("Missing domain data"); } if (result == null && string.IsNullOrEmpty(domain.Name)) { result = BadRequest("Missing domain name value"); } if (result == null && (!domain.AccountId.HasValue || domain.AccountId.Value.Equals(Guid.Empty))) { result = BadRequest("Missing account id value"); } if (result == null && !UserCanAccessAccount(domain.AccountId.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>(); IDomain innerDomain = await domainFactory.Create(domain.AccountId.Value); IMapper mapper = MapperConfigurationFactory.CreateMapper(); mapper.Map <Domain, IDomain>(domain, innerDomain); IDomainSaver saver = scope.Resolve <IDomainSaver>(); await saver.Create(settings, innerDomain); result = Ok(mapper.Map <Domain>(innerDomain)); } } 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); }
/// <summary> /// Finds the resources. /// </summary> /// <returns> /// IEnumerable of the ResourceDto /// </returns> /// <exception cref="System.NotImplementedException"></exception> public virtual async Task <IEnumerable <ResourceDto> > FindAsync() { IResource resource = _resourceFactory.Create(); return(_resourceMapper.Convert(await resource.FindAllAsync())); }
public virtual async Task <IEnumerable <RoleDto> > FindRolesAsync() { IRole role = _roleFactory.Create(); return(_roleMapper.Convert(await role.FindAllWithChildrenAsync())); }
public virtual async Task <IEnumerable <UserDto> > FindUsersAsync() { IUser user = _userFactory.Create(); return(_userMapper.Convert(await user.FindAllAsync())); }