public PartialViewResult Faults()
        {
            WCFProductClient pClient = new WCFProductClient();
            WCFCart_OrderClient oClient = new WCFCart_OrderClient();

            List<Order> orders = oClient.GetOrders(@User.Identity.Name).ToList();
            List<OrderProductModel> orderProductsList = new List<OrderProductModel>();

            foreach (Order order in orders)
            {
                List<Order_Product> orderProducts = oClient.GetOrderProducts(order.ID).ToList();

                foreach (Order_Product op in orderProducts)
                {
                    Product aP = pClient.GetProductByID(op.ProductID);
                    OrderProductModel opM = new OrderProductModel();

                    opM.ProductID = aP.ID;
                    opM.ProductName = aP.Name;
                    opM.Features = aP.Features;
                    opM.QtyPurchased = op.Quantity;
                    opM.DatePurchased = order.DateOrdered;
                    opM.ExpiryDate = order.DateOrdered.AddYears(2);
                    opM.Status = "Not Available";

                    if (opM.ExpiryDate > DateTime.Today)
                    {
                        orderProductsList.Add(opM);
                    }
                }
            }
            return PartialView("_ShowFaults",orderProductsList);
        }
        public ActionResult BuyProduct(Guid productID)
        {
            Order order = new Order();

            order.ID = Guid.NewGuid();
            order.Username = @User.Identity.Name;
            order.DateOrdered = DateTime.Now;

            bool purchaseSuccess = true;

            //products to add to the order
            List<Cart_Product> cartProductsToBuy = new List<Cart_Product>();

            Cart_Product cp = new WCFCart_OrderClient().GetCartProduct(order.Username, productID);

            Product p = new WCFProduct().GetProductByID(cp.ProductID);

            if (p.Stock_Amount - cp.Quantity >= 0)
            {
                cartProductsToBuy.Add(cp);

                //delete cart product
                new WCFCart_Order().DeleteProductFromCart(cp);

                //decrease stock
                p.Stock_Amount = p.Stock_Amount - cp.Quantity;

                new WCFProduct().UpdateProduct(p);
            }
            else
            {
                purchaseSuccess = false;
            }

            if (purchaseSuccess)
            {
               Session["CartProductNameError"] = "";
                //add the order
                new WCFCart_OrderClient().AddOrder(order, cartProductsToBuy.ToArray());
            }
            else
            {
               Session["CartProductNameError"] = "Your amount for the Product" + p.Name + "appears to be more than we have in stock. Sorry for the inconveniece.";
            }

             return RedirectToAction("Cart");
        }
        public JsonResult UpdateCart(string productID, int quantity)
        {
            WCFCart_OrderClient coClient = new WCFCart_OrderClient();
            try
            {
                if (quantity > 0)
                {
                    //get cart product
                    Cart_Product cpToUpdate = coClient.GetCartProduct(@User.Identity.Name, new Guid(productID));

                    //change the quantity
                    cpToUpdate.Quantity = quantity;

                    //update
                    coClient.UpdateCart(cpToUpdate);

                    //refresh the list
                    List<Cart_Product> cp = coClient.GetCart(@User.Identity.Name).ToList();
                    //return PartialView("_Cart", cp);

                    return Json("success");
                }
                else
                {
                    return Json("error");
                }
            }
            catch (Exception e)
            {
                return Json("error");
            }
        }
        public PartialViewResult ShowOrderDetails(Guid id)
        {
            WCFProductClient pClient = new WCFProductClient();
            WCFCart_OrderClient oClient = new WCFCart_OrderClient();

            @ViewBag.orderID = id;

            Order cOrder = oClient.GetOrder(id);

            List<OrderProductModel> orderProductsList = new List<OrderProductModel>();

            List<Order_Product> orderProducts = oClient.GetOrderProducts(id).ToList();

            foreach (Order_Product op in orderProducts)
            {
                Product aP = pClient.GetProductByID(op.ProductID);
                OrderProductModel opM = new OrderProductModel();

                opM.ProductID = aP.ID;
                opM.ProductName = aP.Name;
                opM.Features = aP.Features;
                opM.QtyPurchased = op.Quantity;
                opM.DatePurchased = cOrder.DateOrdered;
                opM.ExpiryDate = cOrder.DateOrdered.AddYears(2);

                Fault f = new WCFFaultClient().GetProductFaultByOrderID(id, aP.ID);
                if (f != null)
                {
                    opM.Status = new WCFFaultClient().GetStatusByID(f.Status).Status1;
                }
                else
                {

                    opM.Status = "No Faults Reported";
                }

                Rating r = new WCFProductClient().GetRating(aP.ID, @User.Identity.Name);

                if (r != null)
                {
                    opM.Rating = r.Rating1;
                }
                else
                {
                    opM.Rating = 0;
                }

                orderProductsList.Add(opM);
            }

            return PartialView("_ShowOrderDetails", orderProductsList);
        }
        //---------------------------------------Printing---------------------------------------------------
        public FileResult PrintProductFaults()
        {
            Guid orderID =(Guid)Session["orderIDForPrint"];

            Guid prID = (Guid)Session["productIDForPrint"];

            Order order = new WCFCart_OrderClient().GetOrder(orderID);
            Order_Product op = new WCFCart_OrderClient().GetOrderProduct(orderID,prID);

            Fault fault = new WCFFaultClient().GetProductFaultByOrderID(orderID, prID);
            Product p = new WCFProductClient().GetProductByID(prID);
            List<Log> logs = new WCFFaultClient().GetLogByFaultID(fault.ID).ToList(); ;

            decimal totalAmount = p.Price * op.Quantity;

               // Create a Document object
            var document = new Document(PageSize.A4, 50, 50, 25, 25);

            // Create a new PdfWriter object, specifying the output stream
            var output = new FileStream("C:\\Users\\Kappuna\\Documents\\GitHub\\DSAAssignment1Sit1\\MVCAssignment - Copy\\MVCAssignment\\Content\\TempReports\\" + fault.Barcode + "Report.pdf", FileMode.Create);
            var writer = PdfWriter.GetInstance(document, output);

            // Open the Document for writing
            document.Open();

            var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
            var subTitleFont = FontFactory.GetFont("Arial", 14, Font.BOLD);
            var boldTableFont = FontFactory.GetFont("Arial", 12, Font.BOLD);
            var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC);
            var bodyFont = FontFactory.GetFont("Arial", 12, Font.NORMAL);

            document.Add(new Paragraph("Electros LTD", titleFont));

            document.Add(new Paragraph("Item:", subTitleFont));
            var orderInfoTable = new PdfPTable(5);
            orderInfoTable.HorizontalAlignment = 0;
            orderInfoTable.SpacingBefore = 10;
            orderInfoTable.SpacingAfter = 10;
            orderInfoTable.DefaultCell.Border = 0;
            orderInfoTable.SetWidths(new int[] { 3, 4,4,4,4});

            orderInfoTable.AddCell("Item No.");
            orderInfoTable.AddCell("Item:");
            orderInfoTable.AddCell("Amount Purchased");
            orderInfoTable.AddCell("Date Purchased");
            orderInfoTable.AddCell("Warranty Expiry Date");

            string id = p.ID.ToString();
            id = id.Substring(0, 8);
            orderInfoTable.AddCell(string.Format("{0}", id));
            orderInfoTable.AddCell(string.Format("{0}", p.Name));
            orderInfoTable.AddCell(string.Format("{0}", totalAmount));
            orderInfoTable.AddCell(string.Format("{0}", order.DateOrdered));
            orderInfoTable.AddCell(string.Format("{0}", order.DateOrdered.AddYears(2)));

            document.Add(orderInfoTable);

            document.Add(new Paragraph("Fault:",subTitleFont));

            var faultInfoTable = new PdfPTable(3);
            faultInfoTable.HorizontalAlignment = 0;
            faultInfoTable.SpacingBefore = 10;
            faultInfoTable.SpacingAfter = 10;
            faultInfoTable.DefaultCell.Border = 4;
            faultInfoTable.SetWidths(new int[] { 4, 4, 4 });

            //Fault Table

            faultInfoTable.AddCell("Fault Details");
            faultInfoTable.AddCell("Status");
            faultInfoTable.AddCell("Date Changed");

            foreach (Log l in logs)
            {
                faultInfoTable.AddCell(string.Format("{0}",l.Details));
                faultInfoTable.AddCell(string.Format("{0}", new WCFFault().GetStatusByID(l.Status).Status1));
                faultInfoTable.AddCell(string.Format("{0}", l.Date));
            }

            document.Add(faultInfoTable);

            // Close the Document - this saves the document contents to the output stream
            document.Close();

            string atch = Server.MapPath("\\Content\\TempReports\\" + fault.Barcode + "Report.pdf");
            User user = new WCFUserClient().GetUser(@User.Identity.Name);
            new WCFBAFuncClient().SendEmailWithAttachment(user.Email, "Product Receipt", "Reciept for the faults of Product " + p.Name + "\nThanks For Using Electros Ltd", atch);

            return File("/Content/TempReports/"+fault.Barcode+"Report.pdf", "application/pdf");
        }
        public PartialViewResult Orders()
        {
            List<Order> o = new WCFCart_OrderClient().GetOrders(@User.Identity.Name).ToList();

            return PartialView("_Orders", o);
        }
 public PartialViewResult Cart()
 {
     List<Cart_Product> cp = new WCFCart_OrderClient().GetCart(@User.Identity.Name).ToList();
     if (cp.Count > 0)
     {
         return PartialView("_Cart", cp);
     }
     else
     {
         @ViewBag.CartErrorMsg = "Your Cart Is Currently Empty";
         return PartialView("_CartError");
     }
 }
 //need to add remove from cart
 public PartialViewResult Cart()
 {
     List<Cart_Product> cp = new WCFCart_OrderClient().GetCart(@User.Identity.Name).ToList();
     return PartialView("_Cart", cp);
 }
        public ActionResult UpdateCart(string productID, int quantity)
        {
            WCFCart_OrderClient coClient = new WCFCart_OrderClient();

            //get cart product
            Cart_Product cpToUpdate = coClient.GetCartProduct(@User.Identity.Name, new Guid(productID));

            //change the quantity
            cpToUpdate.Quantity = quantity;

            //update
            coClient.UpdateCart(cpToUpdate);

            //refresh the list
            List<Cart_Product> cp = coClient.GetCart(@User.Identity.Name).ToList();
            //return PartialView("_Cart", cp);

            return Json(cp);
        }
        //need to fix view and status
        public PartialViewResult ShowOrderDetails(Guid id)
        {
            WCFProductClient pClient = new WCFProductClient();
            WCFCart_OrderClient oClient = new WCFCart_OrderClient();

            Order cOrder = oClient.GetOrder(id);

            List<OrderProductModel> orderProductsList = new List<OrderProductModel>();

            List<Order_Product> orderProducts = oClient.GetOrderProducts(id).ToList();

            foreach (Order_Product op in orderProducts)
            {
                Product aP = pClient.GetProductByID(op.ProductID);
                OrderProductModel opM = new OrderProductModel();

                opM.ProductID = aP.ID;
                opM.ProductName = aP.Name;
                opM.Features = aP.Features;
                opM.QtyPurchased = op.Quantity;
                opM.DatePurchased = cOrder.DateOrdered;
                opM.ExpiryDate = cOrder.DateOrdered.AddYears(2);
                opM.Status = "Not Available";

                orderProductsList.Add(opM);
            }

            return PartialView("_ShowOrderDetails", orderProductsList);
        }