Beispiel #1
0
        private void productClientButton_Click(object sender, RoutedEventArgs e)
        {
            ProductViewer product = (ProductViewer)productSelectView.SelectedItem;

            for (int i = 0; i < shoplogic.shop.Clients.Count(); i++)
            {
                if (client.Name == shoplogic.shop.Clients[i].Name)
                {
                    if (doWhat == "Add")
                    {
                        for (int j = 0; j < shoplogic.shop.Stock.Count(); j++)
                        {
                            if (product.Name == shoplogic.shop.Stock[j].Name)
                            {
                                shoplogic.AddToBasket(shoplogic.shop.Clients[i], shoplogic.shop.Stock[j]);
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0; j < shoplogic.shop.Clients[i].Basket.Count(); j++)
                        {
                            if (product.Name == shoplogic.shop.Clients[i].Basket[j].Name)
                            {
                                shoplogic.RemoveFromBasket(shoplogic.shop.Clients[i], shoplogic.shop.Clients[i].Basket[j]);
                            }
                        }
                    }
                }
            }
            updateLists();
        }
        public frmCreateOrder(Form calling_form)
        {
            _storeViewer    = new StoreViewer();
            _staffViewer    = new StaffViewer();
            _productViewer  = new ProductViewer();
            _customerViewer = new CustomerViewer();

            _newOrderCreator = new NewOrderCreator();

            //we pass in the form that opened this form.   Then we know how to get back to it.
            _calling_form = calling_form;
            InitializeComponent();
        }
Beispiel #3
0
 private void deleteButton_Click(object sender, RoutedEventArgs e)
 {
     if (eventView.Visibility == Visibility.Visible)
     {
         showWarningLabel("You need to be in Client or Product view!");
     }
     else if (clientView.Visibility == Visibility.Visible)
     {
         ClientViewer clientToDelete = (ClientViewer)clientView.SelectedItem;
         shoplogic.LeaveShopp(new Client(0, clientToDelete.Name));
     }
     else
     {
         ProductViewer productToDelete = (ProductViewer)productView.SelectedItem;
         shoplogic.RemoveFromStock(new Product(productToDelete.Price, productToDelete.Name));
     }
     updateLists();
 }
Beispiel #4
0
 public ActionResult AddProductViewer(Viewer request)
 {
     try
     {
         using (ESamhashoEntities entities = new ESamhashoEntities())
         {
             DateTime      dateTime = DateTime.Now.AddDays(-1);
             ProductViewer viewer   = entities.ProductViewers.FirstOrDefault(
                 a => a.ProductId == request.DataId && a.IpAddress.Equals(request.IpAddress) && a.DateCreated >= dateTime && a.DateCreated <= DateTime.Now);
             if (viewer != null)
             {
                 return(new ActionResult
                 {
                     Success = true,
                     Message = ""
                 });
             }
             ProductViewer productViewer = new ProductViewer
             {
                 DateCreated = DateTime.Now,
                 ProductId   = request.DataId,
                 Country     = request.Country,
                 IpAddress   = request.IpAddress,
                 Town        = request.Town
             };
             entities.ProductViewers.Add(productViewer);
             entities.SaveChanges();
             return(new ActionResult
             {
                 Success = true,
                 Message = ""
             });
         }
     }
     catch (Exception exception)
     {
         Dictionary <string, string> dictionary = request.ToDictionary();
         ServiceHelper.LogException(exception, dictionary, ErrorSource.Product);
         return(new ActionResult {
             Message = "Error, product failed to confirm viewed."
         });
     }
 }
Beispiel #5
0
        // view for creating new orders
        public ActionResult NewOrder()
        {
            // need to eventually query our business layers to retrieve information to pre-populates parts of the form
            // create bll viewer objects used for populating data
            int            StoreID        = 1; // Santa Cruz Store
            StaffViewer    staffViewer    = new StaffViewer();
            ProductViewer  productViewer  = new ProductViewer();
            CustomerViewer customerViewer = new CustomerViewer();
            StoreViewer    storeViewer    = new StoreViewer();

            NewOrderModel model = new NewOrderModel()
            {
                Staff     = staffViewer.GetAllEmployesByStore(StoreID),
                Products  = productViewer.GetRandom10(),
                Customers = customerViewer.GetRandom10(),
                Store     = storeViewer.GetStore(StoreID)
            };

            return(View(model));
        }
Beispiel #6
0
        // GET: Admin/Product/Details/5
        public async Task <ActionResult> Details(Guid?id)
        {
            ViewBag.ProductCategories = new SelectList(db.ProductCategories.ToList(), "Id", "Name");
            if (id == null)
            {
                return(View(new Product()));
            }
            Product product = await db.Products.Include("ProductTags").FirstOrDefaultAsync(x => x.Id == id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            product.ViewCount++;
            db.Entry(product).State = EntityState.Modified;
            db.SaveChanges();
            ViewBag.Tags            = db.ProductTags.ToList();
            ViewBag.ProductCanLikes = db.Products.OrderByDescending(x => x.ViewCount).Take(10).ToList();

            if (Session["PRODUCT_VIEWER"] == null)
            {
                Session["PRODUCT_VIEWER"] = new List <ProductViewer>();
            }
            List <ProductViewer> productViewers = Session["PRODUCT_VIEWER"] as List <ProductViewer>;

            if (productViewers.FirstOrDefault(x => x.Product.Id == product.Id) == null)
            {
                var productView = new ProductViewer {
                    Product     = product,
                    CreatedDate = DateTime.Now
                };
                productViewers.Add(productView);
            }
            else
            {
                ProductViewer item = productViewers.FirstOrDefault(m => m.Product.Id == product.Id);
                item.CreatedDate = DateTime.Now;
            }
            ViewBag.ProductViewers = productViewers;
            return(View(product));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            ProductViewer          productViewer       = new ProductViewer();
            PaymentMethodViewer    paymentMethodViewer = new PaymentMethodViewer();
            IPaymentGatewayService paymentGateway      = new ThirdPartyPaymentGatewayService();

            productViewer.ListAllProducts();

            Console.WriteLine("Please enter product id: ");
            int productId = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("Please enter quantity: ");
            int     qty     = Convert.ToInt32(Console.ReadLine());
            Product product = productViewer.Get(productId);


            paymentMethodViewer.ListSavedPaymentMethods();
            Console.WriteLine("Please choose payment method: ");
            int paymentMethodId = Convert.ToInt32(Console.ReadLine());

            PaymentInfo paymentInfo = paymentMethodViewer.Get(paymentMethodId);

            paymentInfo.Amount = product.Price * qty;

            Order order = new Order
            {
                Product    = product,
                Quantity   = qty,
                TotalPrice = product.Price * qty
            };

            OrderManager.PlaceOrder(order, paymentInfo);

            Console.WriteLine("======================================================================");
            Console.WriteLine($"{order.Status}");
            Console.WriteLine("======================================================================");

            Console.ReadKey();
        }
Beispiel #8
0
        /// <summary>
        /// Runs the order form in the UI
        /// </summary>
        private static void CreateOrderForm()
        {
            int store_id, staff_id, product_id, customer_id, quantity;

            if (_storeViewer == null)
            {
                _storeViewer = new StoreViewer();
            }
            if (_staffViewer == null)
            {
                _staffViewer = new StaffViewer();
            }
            if (_productViewer == null)
            {
                _productViewer = new ProductViewer();
            }
            if (_customerViewer == null)
            {
                _customerViewer = new CustomerViewer();
            }
            if (_newOrderCreator == null)
            {
                _newOrderCreator = new NewOrderCreator();
            }

            IList <StaffViewModel>    staff;
            IList <StoreViewModel>    stores    = _storeViewer.GetAllStores();
            IList <CustomerViewModel> customers = _customerViewer.GetRandom10();
            IList <ProductViewModel>  products  = _productViewer.GetRandom10();

            WriteHeader();
            WriteOrderFormHeader();

            Console.WriteLine("Select store:");
            Console.WriteLine("---------------");
            for (var i = 0; i < stores.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, stores[i].Name);
            }

            CommandPrompt("Select store");
            string str_store_id = Console.ReadLine();

            //validate the incoming store_id
            if (!Int32.TryParse(str_store_id, out store_id) || store_id > stores.Count || store_id < 1)
            {
                Console.WriteLine("Invalid store entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //store_id is valid - grab employees
            staff = _staffViewer.GetAllEmployesByStore(store_id);

            //write the employee info onscreen
            WriteHeader();
            WriteOrderFormHeader();

            Console.WriteLine("Select salesperson:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < staff.Count; i++)
            {
                Console.WriteLine("{0}. {1} {2}", i + 1, staff[i].FirstName, staff[i].LastName);
            }
            CommandPrompt("Select salesperson");
            string str_staff_id = Console.ReadLine();

            //validate the incoming staff_id
            if (!Int32.TryParse(str_staff_id, out staff_id) || staff_id > staff.Count || staff_id < 1)
            {
                Console.WriteLine("Invalid salesperson entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //staff_id is valid - print out customers
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select customer:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < customers.Count; i++)
            {
                Console.WriteLine("{0}. {1} {2}", i + 1, customers[i].FirstName, customers[i].LastName);
            }
            CommandPrompt("Select customer");
            string str_customer_id = Console.ReadLine();

            //validate the incoming customer_id
            if (!Int32.TryParse(str_customer_id, out customer_id) || customer_id > customers.Count || customer_id < 1)
            {
                Console.WriteLine("Invalid customer entry.  Press any key...");
                Console.ReadKey();
                return;
            }


            //customer_id is valid - print out products
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select product:");
            Console.WriteLine("--------------------");
            for (var i = 0; i < products.Count; i++)
            {
                Console.WriteLine("{0}. {1}", i + 1, products[i].Name);
            }
            CommandPrompt("Select product");
            string str_product_id = Console.ReadLine();

            //validate the incoming product_id
            if (!Int32.TryParse(str_product_id, out product_id) || product_id > products.Count || product_id < 1)
            {
                Console.WriteLine("Invalid product entry.  Press any key...");
                Console.ReadKey();
                return;
            }

            //product_id is valid - print out quantity
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Select quantity:");
            string str_quantity = Console.ReadLine();

            //validate the incoming product_id
            if (!Int32.TryParse(str_quantity, out quantity) || quantity < 1)
            {
                Console.WriteLine("Invalid quantity.  Press any key...");
                Console.ReadKey();
                return;
            }

            //all inputs valid - show an order summary screen
            WriteHeader();
            WriteOrderFormHeader();
            Console.WriteLine("Order Details:");
            Console.WriteLine("----------------");
            Console.WriteLine("Entered by {0} {1} at {2}", staff[staff_id - 1].FirstName, staff[staff_id - 1].LastName, stores[store_id - 1].Name);
            Console.WriteLine("Order for {0} {1}", customers[customer_id - 1].FirstName, customers[customer_id - 1].LastName);
            Console.WriteLine(products[product_id - 1].Name);
            Console.WriteLine("Qty: {0}", quantity);
            CommandPrompt("Is this correct? (Y/N)");
            string str_response = Console.ReadLine();

            if (str_response.ToLower() == "y")
            {
                NewOrderDTO newOrder = new NewOrderDTO()
                {
                    store_id    = store_id,
                    staff_id    = staff_id,
                    customer_id = customer_id,
                    order_date  = DateTime.Now,
                };

                NewOrderItemDTO newItem = new NewOrderItemDTO()
                {
                    product_id = product_id,
                    quantity   = quantity
                };

                newOrder.items.Add(newItem);

                _newOrderCreator = new NewOrderCreator();
                try
                {
                    int order_number = _newOrderCreator.CreateOrder(newOrder);
                    WriteHeader();
                    WriteOrderFormHeader();
                    Console.WriteLine("Order #{0} created successfully.", order_number);
                    Console.WriteLine("Press any key...");
                    Console.ReadKey();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                return;
            }
        }