Esempio n. 1
0
        public IHttpActionResult PutCategory(int id, Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.ProductCategoryID)
            {
                return(BadRequest());
            }

            db.Entry(category).State = EntityState.Modified;

            try {
                db.SaveChanges();
            } catch (DbUpdateConcurrencyException) {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "CustomerID,NameStyle,Title,FirstName,MiddleName,LastName,Suffix,CompanyName,SalesPerson,EmailAddress,Phone,PasswordHash,PasswordSalt,rowguid,ModifiedDate")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
Esempio n. 3
0
        public ActionResult Create([Bind(Include = "PersonId, Name, Message")] HelloWorld helloWorld)
        {
            if (ModelState.IsValid)
            {
                db.HelloWorlds.Add(helloWorld);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(helloWorld));
        }
Esempio n. 4
0
        private static void ModifyDetailsForSalesOrder()
        {
            using (var context = new AWEntities())
            {
                var detailList = context.SalesOrderDetails.Where(d => d.SalesOrderID == 71816).ToList();

                // modify an OrderDetail
                detailList[0].OrderQty = 10;
                //delete an OrderDetail
                context.DeleteObject(detailList[1]);
                //insert a new OrderDetail
                var product   = context.Products.SingleOrDefault(p => p.ProductID == 711);
                var newDetail = new SalesOrderDetail
                {
                    SalesOrderID      = 71816,
                    ProductID         = product.ProductID,
                    OrderQty          = 2,
                    UnitPrice         = product.ListPrice,
                    UnitPriceDiscount = 0,
                    ModifiedDate      = DateTime.Today
                };
                context.SalesOrderDetails.AddObject(newDetail);
                context.SaveChanges();
            }
        }
Esempio n. 5
0
 private static void addCustomer()
 {
     Customer c = new Customer { FirstName = "John", LastName = "Kelleher" };
     //context.Customers.AddObject(c);       // only for ObjectContext
     context.Customers.Attach(c);
     context.Customers.Add(c);
     context.SaveChanges();
 }
        public void ModifyQuantityDatabaseIntegration()
        {
            var context = new AWEntities();
            var detail  = context.SalesOrderDetails.First();

            detail.OrderQty += 1;
            context.SaveChanges();
            Assert.Inconclusive("the purpose of this test is to see profiler activity, assertions are not applicable");
        }
Esempio n. 7
0
 public Product_dto Save(Product_dto data)
 {
     using (var ctx = new AWEntities())
     {
         var efo = Transform(data);
         ctx.Products.Attach(efo);
         ctx.Entry(efo).State = DbContextHelper.GetEntityState(data);
         ctx.SaveChanges();
         return(Transform(ctx.Entry(efo).Entity));
     }
 }
Esempio n. 8
0
 private static void DeleteOrders()
 {
     using (var context = new AWEntities())
     {
         var orders = from o in context.SalesOrderHeaders where o.CustomerID == 721 select o;
         foreach (var order in orders)
         {
             context.SalesOrderHeaders.DeleteObject(order);
         }
         context.SaveChanges();
     }
 }
Esempio n. 9
0
        private static void InsertUpdateAndDeleteEntityWithMappedSprocs()
        {
            var customer = new Customer
            {
                First        = "Julie",
                LastName     = "Lerman",
                ModifiedDate = DateTime.Now
            };

            using (var context = new AWEntities())
            {
                context.Customers.Add(customer);
                context.SaveChanges();

                customer.Title       = "Princess";
                customer.CompanyName = "The Data Farm";
                context.SaveChanges();

                context.Customers.Remove(customer);
                context.SaveChanges();
            }
        }
Esempio n. 10
0
 private static void RetrieveAndUpdateCustomer()
 {
     using (var context = new AWEntities())
     {
         var query    = from c in context.Customers where c.CustomerID == 5 select c;
         var customer = query.FirstOrDefault();
         var newOrder = new SalesOrderHeader
         {
             OrderDate    = DateTime.Now,
             DueDate      = DateTime.Now.AddMonths(1),
             ModifiedDate = DateTime.Now,
             Comment      = "Don't forget to ship this!"
         };
         context.ContextOptions.LazyLoadingEnabled = false;
         customer.SalesOrderHeaders.Add(newOrder);
         context.SaveChanges();
     }
 }
Esempio n. 11
0
 private static void NewCustomer()
 {
     using (var context = new AWEntities())
     {
         var customer = new Customer
         {
             FirstName    = "Julie",
             LastName     = "Lerman",
             ModifiedDate = DateTime.Now
         };
         customer.SalesOrderHeaders.Add(new SalesOrderHeader
         {
             OrderDate    = DateTime.Now,
             DueDate      = DateTime.Now.AddMonths(1),
             ModifiedDate = DateTime.Now,
             Comment      = "Don't forget to ship this too!"
         });
         context.Customers.AddObject(customer);
         context.SaveChanges();
     }
 }
Esempio n. 12
0
        private static decimal ObjectServicesUpdateTest()
        {
            List <decimal> testresults = new List <decimal>();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            var context = new AWEntities();

            for (int j = 0; j < iInnerloop; j++)
            {
                var customers = from c in context.AWCustomers select c;
                foreach (AWCustomer cust in customers)
                {
                    AWCustomer c = cust;
                    c.ModifiedDate = c.ModifiedDate.AddDays(1);
                }
                for (int iAdd = 0; iAdd < 10; iAdd++)
                {
                    AWCustomer cust = AWCustomer.CreateAWCustomer(0, true, "new", "cust", "pw", "salt", Guid.NewGuid(), DateTime.Now);
                    context.AWCustomers.AddObject(cust);
                }

                sw.Reset();
                sw.Start();
                context.SaveChanges();
                sw.Stop();
                testresults.Add((decimal)sw.ElapsedMilliseconds);
                clearnewcusts(connectionString);
            }

            // figure out how long this took
            //toss first result, calc average of rest
            clearnewcusts(connectionString);

            testresults.Remove(0);
            return(testresults.Average());
        }
 public void Save()
 {
     context.SaveChanges();
 }