public APIResult<List<int>> Send(SendModel model) { var messageIds = new List<int>(); try { if (model == null) throw new Exception("Please pass model"); using (var bo = new ApplicationBusinessObject()) { if (!bo.Check(model.ApplicationId, model.ApplicationSecretKey)) throw new Exception("Invalid application credentials"); } if (String.IsNullOrEmpty(model.Content)) throw new Exception("Content can't be empty"); Provider provider; using (var bo = new ProviderBusinessObject()) { provider = bo.GetByKey(model.ProviderKey); if (provider == null) throw new Exception("Provider not found"); } if (model.ExternalUserIds == null) model.ExternalUserIds = new List<string>(); if (!String.IsNullOrEmpty(model.ExternalUserId)) model.ExternalUserIds.Add(model.ExternalUserId); var userInfos = GetUserInfos(model.ApplicationId, model.ExternalUserIds, provider.Id); if (!String.IsNullOrEmpty(model.To)) userInfos.Add(new Tuple<int?, string>(null, model.To)); if (userInfos.Count == 0) throw new Exception("Please set: ExternalUserId, ExternalUserIds, or To"); var groupId = Guid.NewGuid(); foreach (var info in userInfos) { var message = new Message { UserId = info.Item1, To = info.Item2, ProviderId = provider.Id, ApplicationId = model.ApplicationId, Subject = model.Subject, Content = model.Content, ProcessDate = model.ProcessDate, GroupId = groupId, Priority = model.Priority ?? MessagePriority.Normal }; using (var bo = new MessageBusinessObject()) { var id = bo.Create(message); messageIds.Add(id); } } } catch (Exception ex) { return new APIResult<List<int>>(ex.Message, ex.ToString()); } return new APIResult<List<int>>(messageIds); }
public async Task<ProviderProcessResult> Process(Message message) { await Task.Delay(TimeSpan.FromSeconds(10)); return new ProviderProcessResult { IsSuccess = true }; }