예제 #1
0
        public ActionResult Add(Driver driver)
        {
            //F1Context db = new F1Context();
            int id = rnd.Next(1, 10000);

            driver.ID = 2000 + id;
            db.Drivers.Add(driver);
            db.SaveChanges();
            return(Redirect("/Admin/AdminCatalog"));
        }
예제 #2
0
        /// <summary>
        ///     Runs the two actions inside a transaction scope but with two different contexts and calling
        ///     SaveChanges such that storeChange will succeed and the store will reflect this change, and
        ///     then clientChange will result in a concurrency exception.
        ///     After the exception is caught the resolver action is called, after which SaveChanges is called
        ///     again.  Finally, a new context is created and the validator is called so that the state of
        ///     the database at the end of the process can be validated.
        /// </summary>
        private void ConcurrencyTest(
            Action <F1Context> storeChange, Action <F1Context> clientChange,
            Action <F1Context, DbUpdateException> resolver, Action <F1Context> validator)
        {
            ExtendedSqlAzureExecutionStrategy.ExecuteNew(
                () =>
            {
                using (new TransactionScope())
                {
                    using (var context = new F1Context())
                    {
                        clientChange(context);

                        using (var innerContext = new F1Context())
                        {
                            storeChange(innerContext);
                            innerContext.SaveChanges();
                        }

                        try
                        {
                            context.SaveChanges();
                            Assert.True(false);
                        }
                        catch (DbUpdateException ex)
                        {
                            Assert.IsAssignableFrom <UpdateException>(ex.InnerException);

                            resolver(context, ex);

                            if (validator != null)
                            {
                                context.SaveChanges();

                                using (var validationContext = new F1Context())
                                {
                                    validator(validationContext);
                                }
                            }
                        }
                    }
                }
            });
        }
예제 #3
0
    public static void Seed(F1Context context)
    {
        AddEntities(context);

        context.SaveChanges();
    }