public IActionResult Create(GuestbookItem gbItem)
        {
            gbItem.IPAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            gbItem.Created   = DateTime.Now;

            ReCaptchaV2 recaptcha = new ReCaptchaV2();
            long        new_id    = 0;

            if (ModelState.IsValid && recaptcha.Verify(_config.RecaptchaSecretKey, gbItem.Recaptcha, gbItem.IPAddress))
            {
                _db.GuestbookItem.Add(gbItem);
                _db.SaveChanges();
                DbContextId id = _db.ContextId;
                new_id = gbItem.Id;
            }
            else if (ModelState.IsValid)
            {
                ModelState.AddModelError(string.Empty, "Error! Invalid recaptcha.");
            }

            if (new_id > 0)
            {
                //return Redirect("/Guestbook/Item?Id=" + new_id.ToString());
                return(Redirect("/Guestbook/Index"));
            }
            else
            {
                ViewBag.RecaptchaSiteKey = _config.RecaptchaSiteKey;
                return(View());
            }
        }
示例#2
0
        public DataContext(DbContextOptions connectionOptions)
            : base(connectionOptions)
        {
            _instanceId = base.ContextId;
            _Database   = base.Database;

            ChangeTracker.LazyLoadingEnabled = false;
        }
示例#3
0
        public void DoTest()
        {
            // Check entity framework
            var g = new Guid();
            var z = new DbContextId(g, 1);

            Assert.Equal(g, z.InstanceId);

            // Check aspnet core
            var builder = Microsoft.AspNetCore.WebHost.CreateDefaultBuilder();

            Assert.NotNull(builder);
        }
 public virtual ITestDiagnosticListener SubscribeToDiagnosticListener(DbContextId contextId)
 => ShouldSubscribeToDiagnosticListener
         ? (ITestDiagnosticListener) new TestDiagnosticListener(contextId)
         : new NullDiagnosticListener();
 public TestDiagnosticListener(DbContextId contextId)
 {
     _contextId    = contextId;
     _subscription = DiagnosticListener.AllListeners.Subscribe(this);
 }
示例#6
0
 /// <summary>
 ///     Compares this ID to another ID to see if they represent the same leased context.
 /// </summary>
 /// <param name="other">The other ID.</param>
 /// <returns><see langword="true" /> if they represent the same leased context; <see langword="false" /> otherwise.</returns>
 public bool Equals(DbContextId other)
 => InstanceId == other.InstanceId &&
 Lease == other.Lease;