コード例 #1
0
        //[TestMethod]
        public void PlacingTheOrder()
        {
            SqlConnectionBuilder CB = new SqlConnectionBuilder("(localdb)\\V11.0", "PizzaWaiter", "", "");
            Assert.IsTrue(CB.CheckConnection());

            IPizzaWaiterTestService proxy = new PizzaWaiterTestServiceClient("WSHttpBinding_IPizzaWaiterTestService");

            List<PartOrder> partOrders = new List<PartOrder>();

            PartOrder po1 = new PartOrder();
            po1.Amount = 2;
            po1.Dish = new Dish();
            po1.Dish.ID = 8;

            PartOrder po2 = new PartOrder();
            po2.Amount = 3;
            po2.Dish = new Dish();
            po2.Dish.ID = 9;

            partOrders.Add(po1);
            partOrders.Add(po2);

            //address, phonenumber
            string address = "gneooerig";
            string phoneNr = "23952754";

            bool success = proxy.ProcessOrder(partOrders.ToArray(), phoneNr, address);

            Assert.IsTrue(success);
        }
コード例 #2
0
        public void AddPartOrder()
        {
            var partOrderCtr = new PartOrderCtr(new PartOrderTestClass());
            var partOrder    = new PartOrder(1, new Product(), 2, 10, new Cart());
            var flag         = partOrderCtr.AddPartOrder(partOrder);

            Assert.AreEqual(1, flag);
        }
コード例 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            PartOrder partOrder = db.PartOrders.Find(id);

            db.PartOrders.Remove(partOrder);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public ActionResult AddProductToCart(ProductPartOrderViewModel partOrder)
        {
            // Get the login from session and check if a person is set, is not return a site with a javascript

            var login = (Login)Session["Login"];

            if (login.PersonId == 0)
            {
                return(Content("<script language='javascript' type='text/javascript'>alert('Du skal være logget ind får at tilføje til kurv :)');</script>"));
            }
            // Get the cart from Session
            var cart  = (Cart)Session["ShoppingCart"];
            var proxy = new BestilNemtServiceClient();
            // Get the product by a partOrder product id.
            var product = proxy.GetProduct(partOrder.Product.Id);
            // Make the PartOrder object
            var po = new PartOrder
            {
                Product   = product,
                Amount    = partOrder.Amount,
                PartPrice = product.Price * partOrder.Amount,
                Cart      = cart
            };
            // Get all PartOrders from cart
            var partOrders = cart.PartOrders;
            // There is a partOrder
            // isFound is used to check if a partOrder is allready added
            var isFound = false;

            // Loop for every partOrdeers
            foreach (var partOrderLoop in partOrders)
            {
                // If the product ids not match
                if (partOrderLoop.Product.Id != partOrder.Product.Id)
                {
                    continue;
                }
                // Update the amount
                partOrderLoop.Amount = partOrder.Amount + partOrderLoop.Amount;
                // The PartOrder is found
                isFound = true;
            }
            // If the partOrder is not allready added, add it
            if (!isFound)
            {
                // Add the partOrder to the list
                partOrders.Add(po);
            }
            // Save the list of PartOrders to the cart
            cart.PartOrders = partOrders;
            // Update the session of Cart
            Session["ShoppingCart"] = cart;
            // Get the shop from session
            var shop = (Shop)Session["Shop"];

            // Return the view to Product with the Shop id
            return(RedirectToAction("Product", new { id = shop.Id }));
        }
コード例 #5
0
        public void TestPartOrderPartPriceSer()
        {
            var product             = new Product();
            var cart                = new Cart();
            var partOrder           = new PartOrder(2, product, 2, 100m, cart);
            var serializationResult = SerializerTestHelpClass.TestSerialize(partOrder);

            Assert.AreEqual(partOrder.PartPrice, serializationResult.PartPrice);
        }
コード例 #6
0
 public ActionResult Edit([Bind(Include = "ID,OrderedOn,IsPartReceived,ReceivedOn,RepaidID,PartID")] PartOrder partOrder)
 {
     if (ModelState.IsValid)
     {
         db.Entry(partOrder).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PartID = new SelectList(db.Parts, "ID", "PartNo", partOrder.PartID);
     return(View(partOrder));
 }
コード例 #7
0
        public void TestCartTotalPriceSer()
        {
            var partOrder  = new PartOrder();
            var partOrders = new List <PartOrder> {
                partOrder
            };
            var cart = new Cart(5, partOrders, 200.00m, new Person().Id, new Chain().Id);
            var serializationResult = SerializerTestHelpClass.TestSerialize(cart);

            Assert.AreEqual(cart.TotalPrice, serializationResult.TotalPrice);
        }
コード例 #8
0
        public void TestConcurrencyLessThenMaxAmount()
        {
            var i1 = 0;
            var i2 = 0;

            var prod = new Product("TestProd1", new decimal(10), "TestDescription", "Oste", "TestPath");
            var s    = new Shop("TestShop1", "TestAddress", "12345678", "OpeningTime", new DbChain().GetChain(1), new List <Warehouse>());

            //add product to database
            int prodId = new DbProduct().AddProduct(prod);

            prod.Id = prodId;
            //add shop to database
            var shopId = new DbShop().AddShop(s);

            s.Id = shopId;

            //add warehouse to databse and add it to shop
            var warehouse = new Warehouse(10, 0, prod, s, null);
            var warId     = new DbWarehouse().AddWarehouse(warehouse);

            warehouse.Id = warId;
            s.Warehouses.Add(warehouse);

            //make cart1 with part order
            var cart1 = new Cart();
            var po1   = new PartOrder(prod, 5, 20);

            cart1.PartOrders.Add(po1);
            cart1.PersonId = _cust.Id;
            cart1.ShopId   = s.Id;

            //make cart2 with part order
            var cart2 = new Cart();
            var po2   = new PartOrder(prod, 2, 20);

            cart2.PartOrders.Add(po2);
            cart2.PersonId = _cust1.Id;
            cart2.ShopId   = s.Id;

            //start 2 parallel queries
            var cartDb = new DbCart();

            Parallel.Invoke(() => { i1 = cartDb.AddCartWithPartOrders(cart1); }, () => { i2 = cartDb.AddCartWithPartOrders(cart2); });
            //var antal = new DbWarehouse().GetWarehouse(warId).Stock;
            var flag = 0;

            if (i1 == 0 || i2 == 0)
            {
                flag = 1;
            }
            Assert.AreEqual(1, flag);
        }
コード例 #9
0
        public int AddPartOrder(PartOrder partOrder)
        {
            partOrder.Id = IdCounter;
            if (ValidatePartOrderInput(partOrder))
            {
                Flag = 1;
            }

            PartOrders.Add(partOrder);
            IdCounter++;
            return(Flag);
        }
コード例 #10
0
        /// <summary>
        /// Add a PartOrder to a Cart
        /// Use of PartOrders Cart object
        /// </summary>
        /// <param name="partOrder"></param>
        /// <returns>
        /// The View
        /// </returns>
        public ActionResult AddtoCart(PartOrder partOrder)
        {
            var proxy = new BestilNemtServiceClient();

            // Check for partOrder != null and partOrder.Cart != null
            if (partOrder?.Cart != null)
            {
                // Call the Service provider
                proxy.AddPartOrder(partOrder);
            }
            // Return the View
            return(View());
        }
コード例 #11
0
        public ActionResult Create([Bind(Include = "ID,OrderedOn,IsPartReceived,ReceivedOn,RepaidID,PartID")] PartOrder partOrder)
        {
            if (ModelState.IsValid)
            {
                db.PartOrders.Add(partOrder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PartID   = new SelectList(db.Parts, "ID", "Description", partOrder.PartID);
            ViewBag.RepairID = new SelectList(db.Repairs, "ID", "RepairDescription", partOrder.RepairID);
            return(View(partOrder));
        }
コード例 #12
0
        // GET: PartOrders/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartOrder partOrder = db.PartOrders.Find(id);

            if (partOrder == null)
            {
                return(HttpNotFound());
            }
            return(View(partOrder));
        }
コード例 #13
0
        // GET: PartOrders/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PartOrder partOrder = db.PartOrders.Find(id);

            if (partOrder == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PartID = new SelectList(db.Parts, "ID", "PartNo", partOrder.PartID);
            return(View(partOrder));
        }
コード例 #14
0
 /// <summary>
 /// Create a PartOrder with a SqlDataReader
 /// </summary>
 /// <param name="reader"></param>
 /// <returns>
 /// PartOrder if builded correct, else null
 /// </returns>
 public static PartOrder CreatePartOrder(SqlDataReader reader)
 {
     // Use try to check if all fields is valid
     try
     {
         var partOrder = new PartOrder()
         {
             Id        = reader.GetInt32(reader.GetOrdinal("partOrderId")),
             Product   = CreateProduct(reader),
             Amount    = reader.GetInt32(reader.GetOrdinal("partOrderAmount")),
             PartPrice = reader.GetDecimal(reader.GetOrdinal("partOrderPartPrice"))
         };
         return(partOrder);
     }
     catch (Exception)
     {
         // The build failed, return a null
         return(null);
     }
 }
コード例 #15
0
        /// <summary>
        /// Add a PartOrder
        /// </summary>
        /// <param name="partOrder"></param>
        /// <returns>
        /// Id of PartOrder if added, else 0
        /// </returns>
        public int AddPartOrder(PartOrder partOrder)
        {
            var id = 0;

            using (
                var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationDbContext"].ConnectionString))
            {
                conn.Open();
                var cmd         = conn.CreateCommand();
                var transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted);
                cmd.Transaction = transaction;
                try
                {
                    cmd.CommandText = "Insert into PartOrder(partOrderProductId,partOrderAmount,partOrderPartPrice,partOrderCartId) values(@productId, @amount, @partPrice, @cartId)";
                    cmd.Parameters.AddWithValue("productId", partOrder.Product.Id);
                    cmd.Parameters.AddWithValue("amount", partOrder.Amount);
                    cmd.Parameters.AddWithValue("partPrice", partOrder.PartPrice);
                    cmd.Parameters.AddWithValue("cartId", partOrder.Cart.Id);
                    // Get the Id
                    id = (int)cmd.ExecuteScalar();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    // The transaction failed
                    try
                    {
                        // Try rolling back
                        transaction.Rollback();
                        Console.WriteLine("Transaction was rolled back");
                    }
                    catch (SqlException)
                    {
                        // Rolling back failed
                        Console.WriteLine("Transaction rollback failed");
                    }
                }
            }
            return(id);
        }
コード例 #16
0
 private bool ValidatePartOrderInput(PartOrder partOrder)
 {
     return(partOrder.Amount > 0 && partOrder.Product != null && partOrder.Cart != null);
 }
コード例 #17
0
 /// <summary>
 /// Add a PartOrder
 /// </summary>
 /// <param name="partOrder"></param>
 /// <returns>
 /// Return a PartOrder id if added, else 0
 /// </returns>
 public int AddPartOrder(PartOrder partOrder)
 {
     return(ValidatePartOrderInput(partOrder) ? DbPartOrder.AddPartOrder(partOrder) : 0);
 }
コード例 #18
0
        ///// <summary>
        ///// Update a Login
        ///// </summary>
        ///// <param name="login"></param>
        ///// <returns>
        ///// Return 1 if Login was updated, else 0
        ///// </returns>
        //public int UpdateLogin(Login login)
        //{
        //    return LoginCtr.UpdateLogin(login);
        //}

        /// <summary>
        /// Add a PartOrder
        /// </summary>
        /// <param name="partOrder"></param>
        /// <returns>
        /// Id of PartOrder if added, else 0
        /// </returns>
        public int AddPartOrder(PartOrder partOrder)
        {
            return(PartOrderCtr.AddPartOrder(partOrder));
        }