コード例 #1
0
        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
ファイル: DataContext.cs プロジェクト: saurav1251/Test
        public DataContext(DbContextOptions connectionOptions)
            : base(connectionOptions)
        {
            _instanceId = base.ContextId;
            _Database   = base.Database;

            ChangeTracker.LazyLoadingEnabled = false;
        }
コード例 #3
0
ファイル: EfTest.cs プロジェクト: samhowes/rules_dotnet
        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);
        }
コード例 #4
0
 public virtual ITestDiagnosticListener SubscribeToDiagnosticListener(DbContextId contextId)
 => ShouldSubscribeToDiagnosticListener
         ? (ITestDiagnosticListener) new TestDiagnosticListener(contextId)
         : new NullDiagnosticListener();
コード例 #5
0
 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;