private ActivityTemplateDO Clone(ActivityTemplateDO source) { var newTemplate = new ActivityTemplateDO(); CopyPropertiesHelper.CopyProperties(source, newTemplate, false); newTemplate.Terminal = _terminal.GetByKey(source.TerminalId); if (source.Categories != null) { newTemplate.Categories = new List <ActivityCategorySetDO>(); foreach (var acs in source.Categories) { var newActivityCategory = new ActivityCategoryDO(); var activityCategory = _activityCategory.GetById(acs.ActivityCategoryId); CopyPropertiesHelper.CopyProperties(activityCategory, newActivityCategory, false); newTemplate.Categories.Add(new ActivityCategorySetDO() { ActivityTemplateId = newTemplate.Id, ActivityTemplate = newTemplate, ActivityCategoryId = newActivityCategory.Id, ActivityCategory = newActivityCategory }); } } return(newTemplate); }
public IHttpActionResult Get(Guid id) { var terminalDTO = Mapper.Map <TerminalDTO>(_terminal.GetByKey(id)); terminalDTO.Roles = _security.GetAllowedUserRolesForSecuredObject(id, nameof(TerminalDO)); return(Ok(terminalDTO)); }
private string FormatTerminalName(AuthorizationTokenDO authorizationToken) { var terminal = _terminal.GetByKey(authorizationToken.TerminalID); if (terminal != null) { return(terminal.Label); } return(authorizationToken.TerminalID.ToString()); }
public TerminalDO GetByKey(Guid terminalId) { return(_terminal.GetByKey(terminalId)); }
public async Task <AuthenticateResponse> AuthenticateInternal( Fr8AccountDO account, TerminalDO terminal, string domain, string username, string password, bool isDemoAccount = false) { if (terminal.AuthenticationType == AuthenticationType.None) { throw new WrongAuthenticationTypeException(); } var restClient = ObjectFactory.GetInstance <IRestfulServiceClient>(); var credentialsDTO = new CredentialsDTO { Domain = domain, Username = username, Password = password, IsDemoAccount = isDemoAccount, Fr8UserId = account?.Id }; var terminalResponse = await restClient.PostAsync( new Uri(terminal.Endpoint + "/authentication/token"), credentialsDTO, null, _terminalService.GetRequestHeaders(terminal, account?.Id)); var terminalResponseAuthTokenDTO = JsonConvert.DeserializeObject <AuthorizationTokenDTO>(terminalResponse); if (!string.IsNullOrEmpty(terminalResponseAuthTokenDTO.Error)) { return(new AuthenticateResponse { Error = terminalResponseAuthTokenDTO.Error }); } var curTerminal = _terminalService.GetByKey(terminal.Id); using (var uow = ObjectFactory.GetInstance <IUnitOfWork>()) { var curAccount = uow.UserRepository.GetByKey(account.Id); AuthorizationTokenDO authToken = null; if (!string.IsNullOrEmpty(terminalResponseAuthTokenDTO.ExternalAccountId)) { authToken = uow.AuthorizationTokenRepository .GetPublicDataQuery() .FirstOrDefault(x => x.TerminalID == curTerminal.Id && x.UserID == curAccount.Id && x.ExternalDomainId == terminalResponseAuthTokenDTO.ExternalDomainId && x.ExternalAccountId == terminalResponseAuthTokenDTO.ExternalAccountId && x.AdditionalAttributes == terminalResponseAuthTokenDTO.AdditionalAttributes ); } var created = false; if (authToken == null) { authToken = new AuthorizationTokenDO { Token = terminalResponseAuthTokenDTO.Token, ExternalAccountId = terminalResponseAuthTokenDTO.ExternalAccountId, ExternalAccountName = string.IsNullOrEmpty(terminalResponseAuthTokenDTO.ExternalAccountName) ? terminalResponseAuthTokenDTO.ExternalAccountId : terminalResponseAuthTokenDTO.ExternalAccountName, ExternalDomainId = terminalResponseAuthTokenDTO.ExternalDomainId, ExternalDomainName = string.IsNullOrEmpty(terminalResponseAuthTokenDTO.ExternalDomainName) ? terminalResponseAuthTokenDTO.ExternalDomainId : terminalResponseAuthTokenDTO.ExternalDomainName, TerminalID = curTerminal.Id, UserID = curAccount.Id, AdditionalAttributes = terminalResponseAuthTokenDTO.AdditionalAttributes, ExpiresAt = terminalResponseAuthTokenDTO.ExpiresAt }; uow.AuthorizationTokenRepository.Add(authToken); created = true; } else { authToken.Token = terminalResponseAuthTokenDTO.Token; authToken.ExternalAccountId = terminalResponseAuthTokenDTO.ExternalAccountId; authToken.ExternalAccountName = string.IsNullOrEmpty(terminalResponseAuthTokenDTO.ExternalAccountName) ? terminalResponseAuthTokenDTO.ExternalDomainId : terminalResponseAuthTokenDTO.ExternalAccountName; authToken.ExternalDomainId = terminalResponseAuthTokenDTO.ExternalDomainId; authToken.ExternalDomainName = string.IsNullOrEmpty(terminalResponseAuthTokenDTO.ExternalDomainName) ? terminalResponseAuthTokenDTO.ExternalDomainId : terminalResponseAuthTokenDTO.ExternalDomainName; } uow.SaveChanges(); if (created) { EventManager.AuthTokenCreated(authToken); } //if terminal requires Authentication Completed Notification, follow the existing terminal event notification protocol //to notify the terminal about authentication completed event if (terminalResponseAuthTokenDTO.AuthCompletedNotificationRequired) { //let's save id of DTO before informing related terminal terminalResponseAuthTokenDTO.Id = authToken.Id.ToString(); EventManager.TerminalAuthenticationCompleted(curAccount.Id, curTerminal, terminalResponseAuthTokenDTO); } return(new AuthenticateResponse { AuthorizationToken = Mapper.Map <AuthorizationTokenDTO>(authToken), Error = null }); } }