public IActionResult VoiceMessage(Guid id)
        {
            try
            {
                DivineMessage message = null;
                //TODO: create  a repository and refactor this code
                // if (!cache.TryGetValue(id, out message))
                // {
                using (var context = new DivineContext())
                {
                    message = context.Messages.FirstOrDefault(m => m.Id == id);
                    //    cache.Set(id, message, new MemoryCacheEntryOptions().
                    //                       SetAbsoluteExpiration(TimeSpan.FromHours(1))
                    //                      .SetPriority(CacheItemPriority.High));
                }
                //  }

                Logger.LogInformation("MessageController_VoiceMessage",
                    $"Starting to retrieve VoiceMessage with ID={ id.ToString()}",
                    username: CurrentUser,
                    clientIp: DisplayUrl,
                    serverIp: Environment.MachineName);

                if (message == null)
                    throw new Exception("<Response><Say>Unable to retrieve message!</Say></Response>");

                return Content(message.ToTwiML(), "text/xml");

            }
            catch (Exception ex)
            {
                Logger.LogError("MessageController_VoiceMessage",
                                $"An Error occurred while getting VoiceMessage :: { ex.Message}",
                                exception: ex,
                                username: CurrentUser,
                                clientIp: DisplayUrl,
                                serverIp: Environment.MachineName);
                //TODO: possible notify admin by email
                return Content(ex.Message, "text/xml");
            }
        }
Exemple #2
0
 public SeedData(DivineContext context, ILookupRepository lookupRepo)
 {
     dbContext = context;
     this.lookupRepo = lookupRepo;
 }