Exemplo n.º 1
0
        public ActionResult Index()
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                List <Category> categoryList = categoryOperation.GetAllCategory(appUser.AppUserId);

                List <CategoryListViewModel> categoryListViewModelList = new List <CategoryListViewModel>();

                foreach (Category cat in categoryList)
                {
                    categoryListViewModelList.Add(new CategoryListViewModel()
                    {
                        CategoryId = cat.CategoryId,
                        Name       = cat.Name,
                        IsActive   = cat.IsActive
                    });
                }
                return(View(categoryListViewModelList));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Exemplo n.º 2
0
        public static void CategoryOperationMenu()
        {
            Console.WriteLine("Please Select Category Operation");
            Console.WriteLine("1. Enter a Category");
            Console.WriteLine("2. List all Categories");
            Console.WriteLine("3. Search a Category");
            Console.WriteLine("4. Delete a Category");
            char op = Convert.ToChar(Console.ReadLine());

            switch (op)
            {
            case '1':
                Console.WriteLine("Enter Category Name");
                var categoryName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(categoryName) || int.TryParse(categoryName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    categoryName = 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();
                }
                CategoryOperation.AddCategory(categoryName, shortCode, desc);
                break;

            case '2':
                CategoryOperation.GetAllCategory();
                Console.ReadKey();
                break;

            case '3':
                Console.WriteLine("Enter Category Name");
                var searchCategoryName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(searchCategoryName) || int.TryParse(searchCategoryName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    searchCategoryName = Console.ReadLine();
                }
                CategoryOperation.SearchCategory(searchCategoryName);
                break;

            case '4':
                Console.WriteLine("Enter Category Id or Short Code");
                break;

            default:
                Console.WriteLine("Invalid Selection");
                CategoryOperationMenu();
                break;
            }
        }
Exemplo n.º 3
0
        public ActionResult Insert(int id = 0)
        {
            AppUser appUser = (AppUser)Session["LoggedUser"];

            if (appUser != null)
            {
                MyBookCRUDModel myBookCRUDModel = new MyBookCRUDModel();

                List <Category> categoryList = categoryOperation.GetAllCategory(appUser.AppUserId);
                myBookCRUDModel.CategoryList = new SelectList(categoryList, "CategoryId", "Name");

                return(View(myBookCRUDModel));
            }
            else
            {
                return(RedirectToAction("Login", "Home"));
            }
        }
Exemplo n.º 4
0
        public static void CategoryOperationMenu()
        {
            Console.WriteLine("***Welcome to ProductCatalog, Please Select Category Operation***");
            Console.WriteLine("a. Enter a Category");
            Console.WriteLine("b. List all Categories");
            Console.WriteLine("c. Search a Category");
            Console.WriteLine("d. Delete a Category");
            Console.WriteLine("e. Main Menu");
            char ch1 = Convert.ToChar(Console.ReadLine());

            switch (ch1)
            {
            case 'a':
                Console.WriteLine("Enter Category Name");
                var categoryName = Console.ReadLine();
                while (string.IsNullOrWhiteSpace(categoryName) || int.TryParse(categoryName, out _))
                {
                    Console.WriteLine("Please Enter Only Char and It can not be Empty");
                    categoryName = Console.ReadLine();
                    //break;
                }
                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();
                }
                CategoryOperation.AddCategory(categoryName, shortCode, desc);
                break;

            case 'b':
                CategoryOperation.GetAllCategory();
                Console.ReadKey();
                break;

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

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

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

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