public void AddToCart(int id)
        {
            // Retrieve the product from the database.
            ShoppingSalesId = GetSalesId();

            var shoppingCartItem = _db.SalesItems.SingleOrDefault(
                c => c.SalesId == ShoppingSalesId
                && c.ItemId == id);
            if (shoppingCartItem == null)
            {
                // Create a new cart item if no cart item exists.
                shoppingCartItem = new SalesItem
                {
                    //SalesItemTransId = Guid.NewGuid().ToString(),
                    ItemId = id,
                    SalesId = ShoppingSalesId,
                    ItemName = _db.Items.SingleOrDefault(
                     p => p.ItemId == id).ItemName,
                    Price = _db.Items.SingleOrDefault(
                     p => p.ItemId == id).Price,
                    Qty = 1,
                    LineAmount = _db.Items.SingleOrDefault(
                     p => p.ItemId == id).Price * 1,
                };

                _db.SalesItems.Add(shoppingCartItem);
            }
            else
            {
                // If the item does exist in the cart,
                // then add one to the quantity.
                shoppingCartItem.Qty++;
            }
            _db.SaveChanges();
        }
        public void InstantiateCallerRequested(XmlWriter localXmlWriter, string xmlFileName)
        {
            customer = null;
            item = null;
            salesHeader= null;
            salesItem = null;
            employee = null;

            XmlReader xmlReader = XmlReader.Create(xmlFileName);
            while (xmlReader.Read())
            {
                if (xmlReader.NodeType == XmlNodeType.Element
                    && xmlReader.Name == "Customer")
                {
                    customer = Activator.CreateInstance<Customer>();
                    break;
                }
                if (xmlReader.NodeType == XmlNodeType.Element
                    && xmlReader.Name == "Item")
                {
                    item = Activator.CreateInstance<Item>();
                    break;
                }
                if (xmlReader.NodeType == XmlNodeType.Element
                    && xmlReader.Name == "SalesHeader")
                {
                    salesHeader = Activator.CreateInstance<SalesHeader>();
                    break;
                }
                if (xmlReader.NodeType == XmlNodeType.Element
                    && xmlReader.Name == "SalesItem")
                {
                    salesItem = Activator.CreateInstance<SalesItem>();
                    break;
                }
                if (xmlReader.NodeType == XmlNodeType.Element
                    && xmlReader.Name == "Employee")
                {
                    employee = Activator.CreateInstance<Employee>();
                    break;
                }
                //throw Exception("No Caller Requested found in XML");

            }
            xmlReader.Close();
        }
Beispiel #3
0
        public void CreateSalesItemUsingRepository()
        {
            var SalesItemRepo = new DataRepository<SalesItem>();

            SalesItem createSalesItem = new SalesItem();
            createSalesItem.ItemName = "FP Green Turbo";
            createSalesItem.Price = 800;
            createSalesItem.Qty = 1;
            createSalesItem.ItemId = 1;
            createSalesItem.SalesId = 1;
            createSalesItem.LineAmount = 800;

            SalesItemRepo.Create(createSalesItem);
        }