예제 #1
0
        //Create a line item per-order and add to db....
        static void addLineItemToDB(caproj0Context context, long order, int prodN, int qty)
        {
            //check if they exist
            var theOrder = context.CustOrder.FirstOrDefault(ord => ord.OrderId == order);

            var theProduct = context.Product.FirstOrDefault(prod => prod.ProductId == prodN);

            //check if order and products exist
            if (theOrder == null)
            {
                Console.WriteLine("Invalid order, canceling");
                return;
            }
            else if (theProduct == null)
            {
                Console.WriteLine("Invalid item, canceling");
                return;
            }

            var lineItem = new data_access.Entities.LineItem //create object
            {
                OrderId   = order,
                ProductId = prodN,
                Quantity  = qty
            };

            context.LineItem.Add(lineItem);

            context.SaveChanges();
        }
예제 #2
0
        static void UpdateLocInvOnDB(caproj0Context context, ILocation store)
        {
            //get the location
            var loc = context.StoreLocation.FirstOrDefault(l => l.Phone == store.Phone);

            //get the store's inventory representation from the server
            var invQuery = from inv in context.Inventory
                           where (inv.LocationId == store.LocID)
                           select inv;

            //do we need to ?  Why not just write directly? Synchronicity.

            //put it into a list for simplicity's sake
            var invList = invQuery.ToList();

            int count = 0;

            //iterate through the query results.
            foreach (var p in invList)
            {
                count++;
                //Console.WriteLine($"Remote Name: {p.Product.Pname} Qty{p.Quantity} Store: {p.LocationId}:" );
                //Console.WriteLine($"Local Name: {store.Inventory[count].ProductDesc}" );

                p.Quantity = store.Inventory[count].QuantityOnHand;

                //Console.WriteLine("Check Update:");
                //Console.WriteLine($"Remote Name: {p.Product.Pname} Qty{p.Quantity} Store: {p.LocationId}:");
            }

            context.SaveChanges();

            Console.WriteLine("Update complete, press Enter to Continue");
            Console.ReadLine();

/*
 *          //for each item in the inventory on the server and on the client
 *          for(int i = 0; i < invList.Count; i++)
 *          {
 *
 *              //from the store's inventory entries on the server
 *              //get the row we want                                      based on local product id equals server product-id
 *              var invRow = invQuery.FirstOrDefault(p => p.Product.ProductId == store.Inventory[i].ProdID);
 *
 *              //temp
 * //                string a = invRow.ProductID.ToString();
 *
 * //              Console.WriteLine($"Updated Remote Inventory -- inRow Product ID : {invRow.ProductId} <-> {invRow.Product.Pname} : ||  local equivalant: { store.Inventory[i].ProdID } <-> {store.Inventory[i].ProductDesc}");
 *
 *              //update that entry on the server
 *              invRow.Quantity = store.Inventory[i].QuantityOnHand;
 *
 *              context.SaveChanges();
 *
 *          }
 */
        }
예제 #3
0
        // Create new order
        //      get customer
        //      get location
        //      get items
        //      write order
        //      write line items to order.

        //works

        static void addOrderToDB(caproj0Context context, string custPhone, string locPhone, DateTime now)
        {
            //datetime format
            //2019-10-14 00:00:00.000
            //string now = SQLTimeStamp();

            //get the customer id
            var customer = context.Customer.FirstOrDefault(cust => cust.Phone == custPhone);

            //get the store id.
            var location = context.StoreLocation.FirstOrDefault(loc => loc.Phone == locPhone);

            //check if input is valid.
            if (customer == null)
            {
                Console.WriteLine("Unable to create order, The customer's record does not exist.");
                return;
            }
            else if (location == null)
            {
                Console.WriteLine("Unable to create order: The location's record does not exist.");
                return;
            }

            //passes all checks, so proceed

            var order = new data_access.Entities.CustOrder //create object
            {
                CustomerId = customer.CustomerId,
                LocationId = location.LocationId,
                OrderDate  = now //don't need to build this, already done.
            };

            //add to the table
            context.CustOrder.Add(order);

            //save changes.
            context.SaveChanges();
        }
예제 #4
0
        //Writes::
        //MUST HAVE
        //
        // Create new customer
        //      get data
        //      create object
        //      write object to server

        // Get Specific Customer

        //new customer on db, no pre-reqs or dependancies to set up either.
        //works
        static void AddCustToDB(caproj0Context context, string fName, string lName, string phone, string pw) //get data
        {
            //check if customer already exists based on phone number.
            //
            if (context.Customer.Any(cust => cust.Phone == phone))
            {
                Console.WriteLine("Customer already exists, please log in.");
                return;
            }

            var newCust = new data_access.Entities.Customer //create object
            {
                Fname      = fName,
                Lname      = lName,
                Phone      = phone,
                CustomerPw = pw
            };

            //add it to the Customer table
            context.Customer.Add(newCust); //write to table

            //commit changes
            context.SaveChanges(); //write to server.
        }