Пример #1
0
 public ActionResult Index(FeedbackViewModel submitModel)
 {
     using (var dbContext = FeedbackDbContext.Create())
     {
         if (ModelState.IsValid)
         {
             var model = new Data.Feedback
             {
                 Content         = submitModel.Content,
                 CreateTimestamp = DateTimeOffset.UtcNow,
                 EmailAddress    = submitModel.EmailAddress
             };
             dbContext.Feedbacks.Add(model);
             dbContext.SaveChanges();
             return(RedirectToAction(nameof(Index)));
         }
         var viewModel = new FeedbackListViewModel
         {
             Content      = submitModel.Content,
             EmailAddress = submitModel.EmailAddress
         };
         LoadFeedbackList(viewModel, dbContext);
         return(View(viewModel));
     }
 }
Пример #2
0
 public static async Task TriggerCalculateSentimentAsync([TimerTrigger(Every1Minute, RunOnStartup = false)] TimerInfo info)
 {
     using (var dbContext = FeedbackDbContext.Create())
     {
         await CalculateSentimentAsync(dbContext);
     }
 }
Пример #3
0
        public ActionResult Index()
        {
            var viewModel = new FeedbackListViewModel();

            using (var dbContext = FeedbackDbContext.Create())
            {
                try
                {
                    dbContext.Database.Initialize(false);
                    LoadFeedbackList(viewModel, dbContext);
                }
                catch (Exception e)
                {
                    Debug.WriteLine($"Could not initialize database, probably because it doesn't exist yet. It'll get created by the VSTS Delivery Pipeline!\r\n{e}");
                    // NOTE: Obviously in real systems you wouldn't emit your connection string for the world to see! :)
                    ViewData["Message"] = $"Attempted using connection string: {dbContext.Database.Connection.ConnectionString}\r\n{e.ToString()}";
                }
            }
            return(View(viewModel));
        }