Пример #1
0
 public ActionResult SaveProduct(FormCollection fc, HttpPostedFileBase prodImage)
 {
     if (ModelState.IsValid)
     {
         string imagePath = uploadFile(prodImage);
         po.AddProduct(fc["productname"].ToString(), int.Parse(fc["productType"].ToString()), int.Parse(fc["supplier"].ToString()), int.Parse(fc["posGroup"].ToString()), fc["barcode"].ToString(), fc["description"].ToString(), imagePath);
     }
     return(RedirectToAction("Index"));
 }
Пример #2
0
        /*
         * Role Based Access Control:
         *
         * Implement a role based auth system. System should be able to assign a role to user and remove a user from the role.
         *
         * Entities are USER, ACTION TYPE, RESOURCE, ROLE
         *
         * ACTION TYPE defines the access level(Ex: READ, WRITE, DELETE)
         *
         * Access to resources for users are controlled strictly by the role.One user can have multiple roles. Given a user, action type and resource system should be able to tell whether user has access or not.
         */
        static void Main(string[] args)
        {
            ProductOperation productOperation = new ProductOperation();

            ResourceHandler resourceHandler = new ResourceHandler();

            Console.WriteLine("Please Login\nProvide Username and Password");
            string currentUserName = Console.ReadLine();
            string password        = Console.ReadLine();

            Login login = new Login(currentUserName, password);

            if (Login.CurrentUser == null)
            {
                Console.WriteLine("Incorrect Password!! Please restart Appication with correct login");
                Console.ReadKey();
                return;
            }


            string choice = "";

            Console.WriteLine("Data Operations\n1. Add Product\t2. Modify Product\t3. Delete product\t4.Print Products");
            while (choice != "exit")
            {
                Console.WriteLine("Make a Choice");
                int c = Convert.ToInt32(Console.ReadLine());
                switch (c)
                {
                    #region Product Cases
                case 1:
                    Console.WriteLine("Provide Id");
                    int id = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Provide Product Name");
                    string pName = Console.ReadLine();
                    Console.WriteLine("Provide Supplier");
                    string supplier = Console.ReadLine();
                    Console.WriteLine("Provide Quantity");
                    decimal quantity = Convert.ToDecimal(Console.ReadLine());
                    Console.WriteLine("Provide Unit Cost");
                    decimal uCost = Convert.ToDecimal(Console.ReadLine());

                    Product product = new Product(id, pName, supplier, quantity, uCost);
                    productOperation.AddProduct(product);
                    break;

                case 2:
                    Console.WriteLine("Provide Id");
                    id = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Provide Product Name");
                    pName = Console.ReadLine();
                    Console.WriteLine("Provide Supplier");
                    supplier = Console.ReadLine();
                    Console.WriteLine("Provide Quantity");
                    quantity = Convert.ToDecimal(Console.ReadLine());
                    Console.WriteLine("Provide Unit Cost");
                    uCost = Convert.ToDecimal(Console.ReadLine());

                    product = new Product(id, pName, supplier, quantity, uCost);
                    productOperation.UpdateProduct(product);
                    break;

                case 3:
                    Console.WriteLine("Provide Id");
                    id = Convert.ToInt32(Console.ReadLine());
                    productOperation.DeleteProduct(id);
                    break;

                case 4:
                    productOperation.PrintProducts();
                    break;

                    #endregion
                default:
                    choice = "exit";
                    break;
                }
            }
        }
        public static void ProductOperationMenu()
        {
            Console.WriteLine("Please Select Product Operation");
            Console.WriteLine("a. Add a Product");
            Console.WriteLine("b. List all Products");
            Console.WriteLine("c. Search a Product");
            Console.WriteLine("d. Delete a Product");
            Console.WriteLine("e. Main Menu");
            char ch1 = Convert.ToChar(Console.ReadLine());

            switch (ch1)
            {
            case 'a':
                Console.WriteLine("Enter Product Name");
                var ProductName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(ProductName) || int.TryParse(ProductName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    ProductName = Console.ReadLine();
                }
                Console.WriteLine("Enter Short Code");
                var shortCode = Console.ReadLine();

                Console.WriteLine("Enter Description");
                var desc = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(desc) || int.TryParse(desc, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    desc = Console.ReadLine();
                }
                Console.WriteLine("Enter Price");
                int  price = -1;
                bool flag  = Int32.TryParse(Console.ReadLine(), out price);
                while (!flag || price <= 0)
                {
                    Console.WriteLine("Please Enter Only Number and It can not be Empty/can not be negetive");
                    flag = Int32.TryParse(Console.ReadLine(), out price);
                }
                Console.WriteLine("Enter Manufacture Name");
                var manufactureName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(manufactureName) || int.TryParse(manufactureName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    manufactureName = Console.ReadLine();
                }
                Console.WriteLine("Enter Category Name");
                var category = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(category) || int.TryParse(category, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    category = Console.ReadLine();
                }
                ProductOperation.AddProduct(ProductName, shortCode, desc, price, manufactureName, category);
                break;

            case 'b':
                ProductOperation.GetAllProduct();
                break;

            case 'c':
                Console.WriteLine("Enter Product Name");
                var SearchProductName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(SearchProductName) || int.TryParse(SearchProductName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    ProductName = Console.ReadLine();
                }
                ProductOperation.SearchProduct(SearchProductName);
                break;

            case 'd':
                Console.WriteLine("Enter Product Name");
                var DeleteProductName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(DeleteProductName) || int.TryParse(DeleteProductName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    DeleteProductName = Console.ReadLine();
                }
                ProductOperation.DeleteProduct(DeleteProductName);
                break;

            case 'e':
                StartMenu.Menu();
                break;

            default:
                Console.WriteLine("Invalid Selection!!");
                ProductOperationMenu();
                break;
            }
        }