public IEnumerable <ActivityTemplateCategoryDTO> GetAvailableActivityGroups() { var availableTerminalIds = _terminal.GetAll().Select(x => x.Id).ToList(); var activityTemplates = _activityTemplate .GetQuery() .Where(at => at.ActivityTemplateState == ActivityTemplateState.Active && availableTerminalIds.Contains(at.TerminalId)).AsEnumerable().ToArray() .ToList(); var result = ActivityCategories.ActivityCategoryList .Where(x => activityTemplates.Any(y => y.Categories.Any(z => z.ActivityCategoryId == x.Id) && y.ActivityTemplateState == ActivityTemplateState.Active)) .Select(x => new ActivityTemplateCategoryDTO() { Name = x.Name, Activities = activityTemplates .Where(y => y.Categories.Any(z => z.ActivityCategoryId == x.Id) && y.ActivityTemplateState == ActivityTemplateState.Active) .GroupBy(y => y.Name) .Select(y => y.OrderByDescending(z => int.Parse(z.Version)).First()) .Select(Mapper.Map <ActivityTemplateDTO>) .ToList() }) .ToList(); return(result); }
private async Task <IHttpActionResult> CreateSolution(string solutionName) { var userId = User.Identity.GetUserId(); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { ActivityTemplateDO activityTemplate; var activityTemplateInfo = _activityTemplate.GetActivityTemplateInfo(solutionName); if (!string.IsNullOrEmpty(activityTemplateInfo.Version)) { activityTemplate = _activityTemplate .GetQuery() .FirstOrDefault(x => x.Name == activityTemplateInfo.Name && x.Version == activityTemplateInfo.Version); } else { activityTemplate = _activityTemplate.GetQuery() .Where(x => x.Name == solutionName) .AsEnumerable() .OrderByDescending(x => int.Parse(x.Version)) .FirstOrDefault(); } if (activityTemplate == null) { throw new MissingObjectException($"Activity template (solution) name {solutionName} doesn't exist"); } ObjectFactory.GetInstance <ITracker>().Track(_security.GetCurrentAccount(uow), "Loaded Solution", new Segment.Model.Properties().Add("Solution Name", solutionName)); var result = await _activity.CreateAndConfigure( uow, userId, activityTemplate.Id, name : activityTemplate.Label, createPlan : true); return(Ok(PlanMappingHelper.MapPlanToDto((PlanDO)result))); } }
public async Task <AuthenticateResponse> GetOAuthToken(TerminalDO terminal, ExternalAuthenticationDTO externalAuthDTO) { var hasAuthentication = _activityTemplate.GetQuery().Any(x => x.Terminal.Id == terminal.Id); if (!hasAuthentication) { throw new WrongAuthenticationTypeException(); } var restClient = ObjectFactory.GetInstance <IRestfulServiceClient>(); var response = await restClient.PostAsync( new Uri(terminal.Endpoint + "/authentication/token"), externalAuthDTO, null, _terminalService.GetRequestHeaders(terminal, null)); var authTokenDTO = JsonConvert.DeserializeObject <AuthorizationTokenDTO>(response); if (!string.IsNullOrEmpty(authTokenDTO.Error)) { return(new AuthenticateResponse { Error = authTokenDTO.Error }); } using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var authTokenByExternalState = uow.AuthorizationTokenRepository .FindTokenByExternalState(authTokenDTO.ExternalStateToken, terminal.Id); if (authTokenByExternalState == null) { throw new MissingObjectException($"Authorization token with external state '{authTokenDTO.ExternalStateToken}' doesn't exist"); } var authTokenByExternalAccountId = uow.AuthorizationTokenRepository .FindTokenByExternalAccount( authTokenDTO.ExternalAccountId, terminal.Id, authTokenByExternalState.UserID); if (authTokenByExternalAccountId != null) { authTokenByExternalAccountId.Token = authTokenDTO.Token; authTokenByExternalState.ExternalAccountId = authTokenDTO.ExternalAccountId; authTokenByExternalState.ExternalAccountName = string.IsNullOrEmpty(authTokenDTO.ExternalAccountName) ? authTokenDTO.ExternalAccountId : authTokenDTO.ExternalAccountName; authTokenByExternalState.ExternalDomainId = authTokenDTO.ExternalDomainId; authTokenByExternalState.ExternalDomainName = string.IsNullOrEmpty(authTokenDTO.ExternalDomainName) ? authTokenDTO.ExternalDomainId : authTokenDTO.ExternalDomainName; authTokenByExternalAccountId.ExternalStateToken = null; authTokenByExternalState.AdditionalAttributes = authTokenDTO.AdditionalAttributes; authTokenByExternalState.ExpiresAt = authTokenDTO.ExpiresAt; if (authTokenByExternalState != null) { uow.AuthorizationTokenRepository.Remove(authTokenByExternalState); } EventManager.AuthTokenCreated(authTokenByExternalAccountId); } else { authTokenByExternalState.Token = authTokenDTO.Token; authTokenByExternalState.ExternalAccountId = authTokenDTO.ExternalAccountId; authTokenByExternalState.ExternalAccountName = string.IsNullOrEmpty(authTokenDTO.ExternalAccountName) ? authTokenDTO.ExternalAccountId : authTokenDTO.ExternalAccountName; authTokenByExternalState.ExternalDomainId = authTokenDTO.ExternalDomainId; authTokenByExternalState.ExternalDomainName = string.IsNullOrEmpty(authTokenDTO.ExternalDomainName) ? authTokenDTO.ExternalDomainId : authTokenDTO.ExternalDomainName; authTokenByExternalState.ExternalStateToken = null; authTokenByExternalState.AdditionalAttributes = authTokenDTO.AdditionalAttributes; authTokenByExternalState.ExpiresAt = authTokenDTO.ExpiresAt; EventManager.AuthTokenCreated(authTokenByExternalState); } uow.SaveChanges(); return(new AuthenticateResponse { AuthorizationToken = Mapper.Map <AuthorizationTokenDTO>(authTokenByExternalAccountId ?? authTokenByExternalState), Error = null }); } }