示例#1
0
        public void AddCustomer(User customer)
        {
            string connectionString = File.ReadAllText("C:/Revature/databaseconnectionstring.txt");


            var options = new DbContextOptionsBuilder <DamionBuyContext>()
                          .UseSqlServer(connectionString)
                          .Options;

            using (var context = new DamionBuyContext(options))
            {
                var newCustomer = new Member()
                {
                    FirstName = customer.FirstName,
                    LastName  = customer.LastName,
                    Role      = customer.Role,
                    Email     = customer.Email,
                    CustomerLocationAddress = customer.CustomerLocationAddress,
                    CustomerLocationCity    = customer.CustomerLocationCity,
                    CustomerLocationState   = customer.CustomerLocationState,
                    CustomerLocationCountry = customer.CustomerLocationCountry,
                    CustomerLocationZip     = customer.CustomerLocationZIP,
                    Password = customer.Password
                };

                context.Add(newCustomer);

                context.SaveChanges();
            };
        }
    { public void Addstore(Stores store)
      {
          string connectionString = File.ReadAllText("C:/Revature/databaseconnectionstring.txt");


          var options = new DbContextOptionsBuilder <DamionBuyContext>()
                        .UseSqlServer(connectionString)
                        .Options;

          using (var context = new DamionBuyContext(options))
          {
              var newstore = new Store()
              {
                  StoreName            = "DamionBuy",
                  StoreLocationAddress = store.StoreLocationAddress,
                  StoreLocationCity    = store.StoreLocationCity,
                  StoreLocationState   = store.StoreLocationState,
                  StoreLocationCountry = store.StoreLocationCountry,
                  StoreLocationZip     = store.StoreLocationZip,
                  StorePhoneNumber     = store.StorePhoneNumber,
              };
              context.Add(newstore);
              context.SaveChanges();
          }
      }
        public void placeorder(Orders order)
        {
            string connectionString = File.ReadAllText("C:/Revature/databaseconnectionstring.txt");


            var options = new DbContextOptionsBuilder <DamionBuyContext>()
                          .UseSqlServer(connectionString)
                          .Options;

            using (var context = new DamionBuyContext(options))
            {
                var newOrder = new Order()
                {
                    CustomerId = order.CustomerNumber,
                    StoreId    = order.StoreID,
                    DatePlaced = DateTime.Now,
                };
                context.Add(newOrder);
                context.SaveChanges();
                Order            dbOrderV2       = context.Orders.OrderBy(x => x.Id).Last();
                List <OrderItem> orderDetailList = new List <OrderItem>();

                List <OrderItem> newdetail = new List <OrderItem>();
                foreach (var product in order.Product)
                {
                    OrderItem neworderdetail = new OrderItem
                    {
                        Orderid   = dbOrderV2.Id,
                        Productid = product.ID,
                        Quantity  = product.Quantity
                    };
                    orderDetailList.Add(neworderdetail);
                }
                foreach (var i in orderDetailList)
                {
                    context.Add(i);
                    context.SaveChanges();
                }
            };
        }
        public void addProduct(Products newproduct)
        {
            string connectionString = File.ReadAllText("C:/Revature/databaseconnectionstring.txt");


            var options = new DbContextOptionsBuilder <DamionBuyContext>()
                          .UseSqlServer(connectionString)
                          .Options;

            using (var context = new DamionBuyContext(options))
            {
                var newproduc = new Product()
                {
                    ProductName        = newproduct.ProductName,
                    ProductPrice       = newproduct.ProductPrice,
                    ProductDescription = newproduct.ProductDescription
                };


                context.Add(newproduc);
                context.SaveChanges();
            }
        }