public async Task <ServiceProviderResponse> ListTemplatesAsync( [FromHeader(Constant.OperationTrackingIdHeader)] string requestId, [FromHeader] string account, [FromQuery] string continuationToken = null, [FromQuery] int count = ContinuationToken.DefaultCount) { await ValidateAccount(account); Validator.IsTrue <ArgumentException>(count > 0 && count <= SmsConstant.PagingMaxTakeCount, nameof(count), $"Count should be between 0 and {SmsConstant.PagingMaxTakeCount}."); var token = new DbContinuationToken(continuationToken); Validator.IsTrue <ArgumentException>(token.IsValid, nameof(token), "ContinuationToken is invalid."); var templates = await this.store.ListTemplatesAsync(account, token, count); var response = ServiceProviderResponse.CreateJsonResponse(HttpStatusCode.OK, templates); if (templates.NextLink != null) { response.Headers = new Dictionary <string, IEnumerable <string> > { { ContinuationToken.ContinuationTokenKey, new List <string> { templates.NextLink.Token } } }; } return(response); }
public async Task <SenderList> ListSendersAsync(string engagementAccount, DbContinuationToken continuationToken, int count) { using (var ctx = new EmailServiceDbEntities(this.connectionString)) { var result = new SenderList(); var senders = ctx.SenderAddresses.Where(s => s.EngagementAccount == engagementAccount).OrderBy(s => s.Created); result.Total = senders.Count(); if (result.Total <= 0) { return(result); } var taken = count >= 0 ? await senders.Skip(continuationToken.Skip).Take(count).ToListAsync() : await senders.Skip(continuationToken.Skip).ToListAsync(); result.SenderAddresses = new List <Sender>(); foreach (var entity in taken) { result.SenderAddresses.Add(entity.ToModel()); } if (result.Total > continuationToken.Skip + count) { result.NextLink = new DbContinuationToken(continuationToken.DatabaseId, continuationToken.Skip + count); } return(result); } }
public async Task <TemplateList> ListTemplatesAsync(string account, DbContinuationToken continuationToken, int count, string trackingId) { try { var templates = await this.store.ListTemplatesAsync(account, continuationToken, count); return(templates); } catch (Exception ex) { EmailProviderEventSource.Current.ErrorException(trackingId, this, nameof(this.ListTemplatesAsync), OperationStates.Failed, $"Failed to get email template for account: {account}", ex); throw new ApplicationException(string.Format($"Failed to get email template list for account: {account}")); } }
public async Task <TemplateList> ListTemplatesAsync(string engagementAccount, DbContinuationToken continuationToken, int count) { using (var ctx = new SmsServiceDbEntities(this.connectionString)) { var result = new TemplateList(); var templates = ctx.Templates.Where(t => t.EngagementAccount == engagementAccount).OrderBy(t => t.Created); result.Total = templates.Count(); if (result.Total <= 0) { return(result); } var taken = count >= 0 ? await templates.Skip(continuationToken.Skip).Take(count).ToListAsync() : await templates.Skip(continuationToken.Skip).ToListAsync(); result.Templates = new List <Template>(); foreach (var entity in taken) { result.Templates.Add(entity.ToModel()); } if (result.Total > continuationToken.Skip + count) { result.NextLink = new DbContinuationToken(continuationToken.DatabaseId, continuationToken.Skip + count); } return(result); } }