Beispiel #1
0
        public void Start()
        {
            Console.WriteLine("\t\t WELCOME!");

            do
            {
                Console.WriteLine("\n\t\t MAIN MENU");

                Console.WriteLine("\tPlease choose an option. (Press the key that is enclosed by '()')\n");


                Console.WriteLine("(1) PRODUCTS MENU");
                Console.WriteLine("(2) CATEGORIES MENU");
                //Console.WriteLine("(0) TESTING");
                Console.WriteLine("(ESC) Exit");

                Console.WriteLine();


                var keypress = Console.ReadKey();
                Console.WriteLine("\n");

                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    ProductsMenu pMenu = new ProductsMenu();
                    pMenu.Start();
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    IMenu cMenu = new CategoriesMenu();
                    cMenu.Start();
                }

                //if (keypress.Key == ConsoleKey.D0 || keypress.Key == ConsoleKey.NumPad0)
                //{
                //    TestingClass testMenu = new TestingClass();
                //    testMenu.Start();
                //}



                else if (keypress.Key == ConsoleKey.Escape)
                {
                    logging.Log("WARN", "Are you sure that you would like to quit the application?");
                    Console.WriteLine("Press the \"Y\" key if you'd truly like to exit, otherwise press any other key to continue.");

                    ConsoleKeyInfo end = Console.ReadKey();
                    Console.WriteLine();

                    if (end.Key == ConsoleKey.Y)
                    {
                        break;
                    }
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }
Beispiel #2
0
 public IReadOnlyRepository CreateReadOnlyRepository(TContext context)
 {
     try
     {
         return(new EntityFrameworkReadOnlyRepository <TContext>(context));
     }
     catch (Exception e)
     {
         Logger.Log(new LogEntry(LoggingEventType.Error, "An error occurred in CreateReadonlyRepo", e));
         throw;
     }
 }
Beispiel #3
0
        private void Delete(Category category)
        {
            if (ConfirmSelections(category))
            {
                NorthwindContext db = new NorthwindContext();

                Console.WriteLine("Delete all related products?\n If yes, enter \"Yes\" otherwise, enter anything else for No. ");

                string del = Console.ReadLine();
                if (del.ToUpper() == "YES")
                {
                    //var prodDelete = category.Products;
                    db.RemoveCategoryProducts(category);

                    //foreach (var item in prodDelete)
                    //{
                    //    db.RemoveProduct(item);
                    //}
                }

                db.RemoveCategory(category);
                //db.Entry(product).State = EntityState.Deleted;
            }
            else
            {
                NLogger logging = new NLogger();

                logging.Log("INFO", "Operation Cancelled.");
            }
        }
        public void Save()
        {
            NLogger logger = new NLogger();

            try
            {
                this.SaveChanges();
            }
            catch (Exception ex)
            {
                logger.Log("ERROR", "" + ex);
                throw;
            }

            logger.Log("INFO", "Changes were saved to the database.");
        }
Beispiel #5
0
        public ActionResult Index(
            string applicationPath           = null,
            string siteName                  = null,
            IISSiteType siteType             = IISSiteType.Default,
            IISViewActionType viewActionType = IISViewActionType.InformationComponent)
        {
            string db      = null;
            string redisDb = null;

            if (!string.IsNullOrEmpty(applicationPath))
            {
                switch (siteType)
                {
                case IISSiteType.Application:
                    db      = ConnectionStringsService.GetMssqlDb(applicationPath, false);
                    redisDb = ConnectionStringsService.GetRedisDb(applicationPath, false);
                    break;

                case IISSiteType.Site:
                    db      = ConnectionStringsService.GetMssqlDb(applicationPath, true);
                    redisDb = ConnectionStringsService.GetRedisDb(applicationPath, true);
                    break;

                default:
                    var exception = new Exception("Такой тип приложения не поддерживается");
                    NLogger.Log(exception);
                    throw exception;
                }
            }

            var viewModel = new IISIndexViewModel
            {
                SiteName            = siteName,
                ApplicationPath     = applicationPath,
                SiteType            = siteType,
                ActionViewType      = viewActionType,
                Database            = db,
                RedisDatabase       = redisDb,
                IsFeatureTableExist = !string.IsNullOrEmpty(db) &&
                                      FeatureService.GetFeatureTableExist(db).GetAwaiter().GetResult()
            };

            if (!string.IsNullOrEmpty(applicationPath))
            {
                SiteInformation information;
                // TODO Extract interface for DI
                using (var infoService = new SiteInformationService())
                {
                    information = infoService.GetInformationBySiteType(applicationPath, siteType);
                }

                viewModel.ApplicationPoolName     = information.ApplicationPoolName;
                viewModel.IsPoolStoppingOrStopped =
                    ApplicationPoolService.IsPoolStoppingOrStopped(information.ApplicationPoolName);
                viewModel.IsPoolStartingOrStarted =
                    ApplicationPoolService.IsPoolStartingOrStarted(information.ApplicationPoolName);
            }

            return(View(viewModel));
        }
        public void AddProduct(Product product)
        {
            NLogger logger = new NLogger();

            try
            {
                this.Products.Add(product);
                this.SaveChanges();
                logger.Log("INFO", "Product has been added.");
            }
            catch (Exception ex)
            {
                logger.Log("ERROR", "An error occurred when attempting to add a new product.\n" + ex);
                throw;
            }
        }
        public void AddCategory(Category category)
        {
            NLogger logger = new NLogger();

            try
            {
                this.Categories.Add(category);
                this.SaveChanges();
                logger.Log("INFO", "Category has been added.");
            }
            catch (Exception ex)
            {
                logger.Log("ERROR", "An error occurred when attempting to add a new category.\n" + ex);
                throw;
            }
        }
        public void Start()
        {
            Console.WriteLine("\tADD CATEGORY\n");

            string categoryName;
            string description;

            NLogger logging = new NLogger();

            Console.WriteLine("Please enter the new Category name. (Required)");
            categoryName = StringValidation(Console.ReadLine());

            Console.WriteLine("What is the description of the new category?");
            description = StringValidation(Console.ReadLine());


            Category category = new Category
            {
                CategoryName = categoryName,
                Description  = description
            };

            if (ConfirmSelections(category) == true)
            {
                NorthwindContext db = new NorthwindContext();
                db.AddCategory(category);
            }
            else
            {
                logging.Log("INFO", "Operation Cancelled.");
            }
        }
        public List <Product> SearchProducts(int searchNum)
        {
            NLogger logging      = new NLogger();
            var     searchResult = this.Products.Where(p => p.ProductID == searchNum).ToList();

            if (searchResult.Count() == 0)
            {
                logging.Log("WARN", "There were no products found.");
            }
            else
            {
                logging.Log("INFO", searchResult.Count() + " Products Found.");
            }


            return(searchResult);
        }
        public List <Category> SearchCategory(int searchNum)
        {
            NLogger logging      = new NLogger();
            var     searchResult = this.Categories.Where(c => c.CategoryId == searchNum).ToList();

            if (searchResult.Count() == 0)
            {
                logging.Log("WARN", "There were no categories found.");
            }
            else
            {
                logging.Log("INFO", searchResult.Count() + " Categories Found.");
            }


            return(searchResult);
        }
Beispiel #11
0
        public decimal?UnitPrice_Input()
        {
            decimal?unitPrice;

            do
            {
                Console.WriteLine("What is the unit price for this product?" + nullableMessage);
                string tempn = Console.ReadLine();

                if (ValidateDecimal(tempn))
                {
                    if (tempn == "")
                    {
                        unitPrice = null;
                    }
                    else
                    {
                        unitPrice = decimal.Parse(tempn);
                    }
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A proper decimal was not entered for the new product's unit price. Please try again.");
                }
            } while (true);

            return(unitPrice);
        }
        public void RemoveCategory(Category category)
        {
            NLogger logger = new NLogger();

            try
            {
                var toDelete = this.Categories.FirstOrDefault(d => d.CategoryId == category.CategoryId);
                this.Categories.Remove(toDelete);
                //db.Entry(product).State = EntityState.Deleted;
                this.SaveChanges();
                logger.Log("INFO", "Category has been deleted.");
            }
            catch (Exception ex)
            {
                logger.Log("ERROR", "An error occurred when attempting to delete a category.\n" + ex);
                throw;
            }
        }
Beispiel #13
0
        public static void Main(string[] args)
        {
            NLogger logger = new NLogger();

            logger.Log("INFO", "PROGRAM START!");
            Console.WriteLine();

            TopMenu menu = new TopMenu();

            menu.Start();


            Console.WriteLine("Goodbye");
            logger.Log("INFO", "PROGRAM END!");

            Console.WriteLine("Press any key.");
            Console.ReadKey();
        }
Beispiel #14
0
 public int IntValidation(string input)
 {
     do
     {
         if (input == "")
         {
             logging.Log("WARN", "Input was null and will be replaced with 0.");
             return(0);
         }
         else if (int.TryParse(input, out int result))
         {
             return(result);
         }
         else
         {
             logging.Log("ERROR", "A valid input was not entered! Please enter a valid Integer number.");
             Console.Write("Input?:\t"); input = Console.ReadLine();
         }
     } while (true);
 }
        public void RemoveProduct(Product product)
        {
            NLogger logger = new NLogger();

            try
            {
                var toDelete = this.Products.FirstOrDefault(d => d.ProductID == product.ProductID);
                this.Products.Remove(toDelete);
                //var toDelete = this.Products.Attach(product);
                //this.Products.Remove(product);
                //this.Entry(product).State = EntityState.Deleted;
                this.SaveChanges();
                logger.Log("INFO", "Product has been deleted.");
            }
            catch (Exception ex)
            {
                logger.Log("ERROR", "An error occurred when attempting to delete a product.\n" + ex);
                throw;
            }
        }
        /// <summary>
        /// Search categories by name or description.
        /// </summary>
        /// <param name="searchName"></param>
        /// <param name="type">true = by CategoryName false = Description</param>
        /// <returns></returns>
        public List <Category> SearchCategory(string searchName, bool type)
        {
            NLogger         logging = new NLogger();
            List <Category> searchResult;


            if (type == true)
            {
                searchResult = this.Categories.Where(c => c.CategoryName.Contains(searchName)).ToList();

                if (searchResult.Count() == 0)
                {
                    logging.Log("WARN", "There were no categories found.");
                }
                else
                {
                    logging.Log("INFO", searchResult.Count() + " Categories Found.");
                }
            }

            else
            {
                searchResult = this.Categories.Where(c => c.Description.Contains(searchName)).ToList();

                if (searchResult.Count() == 0)
                {
                    logging.Log("WARN", "There were no categories found.");
                }
                else
                {
                    logging.Log("INFO", searchResult.Count() + " Categories Found.");
                }
            }



            return(searchResult);
        }
        public async Task <JsonResult> SetUserEnableStatus(string id, bool status)
        {
            try
            {
                await UserService.ChangeIsEnabled(status, id);
            }
            catch (Exception e)
            {
                NLogger.Log(e);
                return(Json(new { success = false, responseText = $"{e.Message}" }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { success = true, responseText = $"Success" }, JsonRequestBehavior.AllowGet));
        }
        public async Task <JsonResult> DeleteUser(string id)
        {
            try
            {
                await UserService.DeleteUser(id);
            }
            catch (Exception e)
            {
                NLogger.Log(e);
                return(Json(new { success = false, responseText = $"{e.Message}" }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { success = true, responseText = $"Success" }, JsonRequestBehavior.AllowGet));
        }
Beispiel #19
0
        private void Delete(Product product)
        {
            if (ConfirmSelections(product))
            {
                NorthwindContext db = new NorthwindContext();
                db.RemoveProduct(product);
                //var toDelete = db.Products.Attach(product);
                //db.Products.Remove(product);
                //db.Entry(product).State = EntityState.Deleted;
            }
            else
            {
                NLogger logging = new NLogger();

                logging.Log("INFO", "Operation Cancelled.");
            }
        }
Beispiel #20
0
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tPRODUCTS\n");

                Console.WriteLine("(1) Add new Product");
                Console.WriteLine("(2) Edit an existing Product");
                Console.WriteLine("(3) Delete an existing Product");
                Console.WriteLine("(4) Display Products");

                Console.WriteLine("(ESC) Return to Main menu");

                var keypress = Console.ReadKey();
                Console.WriteLine("");

                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    IMenu aMenu = new AddProductsMenu();
                    aMenu.Start();
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    IMenu eMenu = new EditProductsMenu();
                    eMenu.Start();
                }
                else if (keypress.Key == ConsoleKey.D3 || keypress.Key == ConsoleKey.NumPad3)
                {
                    IMenu deMenu = new DeleteProductsMenu();
                    deMenu.Start();
                }
                else if (keypress.Key == ConsoleKey.D4 || keypress.Key == ConsoleKey.NumPad4)
                {
                    IMenu dimenu = new DisplayProductMenu();
                    dimenu.Start();
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }
        //Confirms selections for Products
        protected bool ConfirmSelections(Product product)
        {
            NLogger logging = new NLogger();

            //loop through properties
            //foreach (PropertyInfo prop in product.GetType().GetProperties())
            //{
            //    Console.WriteLine("{0} = {1}", prop.Name, prop.GetValue(prop)); //sketchy, check
            //}

            Console.WriteLine("\nProduct Name: {0}", product.ProductName);
            Console.WriteLine("Quantity Per Unit: {0}", product.QuantityPerUnit);
            Console.WriteLine("Unit Price: {0}", product.UnitPrice);
            Console.WriteLine("Units In Stock: {0}", product.UnitsInStock);
            Console.WriteLine("Units On Order: {0}", product.UnitsOnOrder);
            Console.WriteLine("Reorder Level: {0}", product.ReorderLevel);
            Console.WriteLine("Discontinued: {0}", product.Discontinued);
            Console.WriteLine("Category ID: {0}\n", product.CategoryId);


            do
            {
                Console.WriteLine("Is this correct?");
                Console.WriteLine("If yes, Press Y. If No, Press N.");
                ConsoleKeyInfo keypress = Console.ReadKey();
                Console.WriteLine();



                if (keypress.Key == ConsoleKey.Y)
                {
                    return(true);
                }
                else if (keypress.Key == ConsoleKey.N)
                {
                    return(false);
                }
                else
                {
                    logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                }
            } while (true);
        }
Beispiel #22
0
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tDELETE CATEGORY\n");

                Console.WriteLine("Delete which Category?\n");
                Console.WriteLine("(1) Find by ID");
                Console.WriteLine("(2) Find by Name");

                Console.WriteLine("Press ESC to go back");

                var keypress = Console.ReadKey();
                Console.WriteLine("");

                NorthwindContext db    = new NorthwindContext();
                DisplayOptions   disOp = new DisplayOptions();

                List <Category> results = null;

                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    Console.WriteLine("Please enter the ID of the category that you are searching for.");
                    int search = IntValidation(Console.ReadLine());


                    results = db.SearchCategory(search).ToList();
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    Console.WriteLine("Please enter the Name of the category that you are searching for.");
                    string search = Console.ReadLine();

                    results = db.SearchCategory(search, true).ToList();
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    NLogger logging = new NLogger();

                    logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                }


                if (results == null)
                {
                }
                else if (results.Count() == 0)
                {
                }
                else if (results.Count() == 1)
                {
                    //disOp.DisplayCategory(results[0]);

                    this.Delete(results[0]);
                }
                else
                {
                    int row = 0;

                    foreach (var category in results)
                    {
                        Console.WriteLine("Row: ", ++row);
                        disOp.DisplayCategory(category);
                    }



                    Console.WriteLine("Which Product?");
                    Console.Write("Enter the Row number: \t");

                    string choice = Console.ReadLine();
                    int    vInput = IntValidation(choice);


                    this.Delete(results[vInput - 1]);
                }
            }while(true);
        }
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tDISPLAY PRODUCTS\n");

                Console.WriteLine("(1) Display all products");
                Console.WriteLine("(2) Find product details");

                Console.WriteLine("(ESC) Return to Products menu");

                var keypress = Console.ReadKey();
                Console.WriteLine("");

                DisplayOptions   disOp = new DisplayOptions();
                NorthwindContext db    = new NorthwindContext();

                //Display all
                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    Console.WriteLine("(1) Display all products");
                    Console.WriteLine("(2) Display all active products");
                    Console.WriteLine("(3) Display all discontinued products");

                    var type = Console.ReadKey();
                    Console.WriteLine("");
                    if (type.Key == ConsoleKey.D1 || type.Key == ConsoleKey.NumPad1)
                    {
                        Console.WriteLine("(1) Display products in short form");
                        Console.WriteLine("(2) Display products in long form");

                        var form = Console.ReadKey();
                        Console.WriteLine("");

                        if (form.Key == ConsoleKey.D1 || form.Key == ConsoleKey.NumPad1)
                        {
                            disOp.DisplayAllProducts_Short();
                        }
                        else if (form.Key == ConsoleKey.D2 || form.Key == ConsoleKey.NumPad2)
                        {
                            disOp.DisplayAllProducts_Long();
                        }
                        else
                        {
                            logging.Log("WARN", "Please press a valid option. Try again.");
                        }
                    }
                    else if (type.Key == ConsoleKey.D2 || type.Key == ConsoleKey.NumPad2)
                    {
                        Console.WriteLine("(1) Display products in short form");
                        Console.WriteLine("(2) Display products in long form");

                        var form = Console.ReadKey();
                        Console.WriteLine("");

                        if (form.Key == ConsoleKey.D1 || form.Key == ConsoleKey.NumPad1)
                        {
                            disOp.DisplayAllActiveProducts_Short();
                        }
                        else if (form.Key == ConsoleKey.D2 || form.Key == ConsoleKey.NumPad2)
                        {
                            disOp.DisplayAllActiveProducts_Long();
                        }
                        else
                        {
                            logging.Log("WARN", "Please press a valid option. Try again.");
                        }
                    }
                    else if (type.Key == ConsoleKey.D3 || type.Key == ConsoleKey.NumPad3)
                    {
                        Console.WriteLine("(1) Display products in short form");
                        Console.WriteLine("(2) Display products in long form");

                        var form = Console.ReadKey();
                        Console.WriteLine("");

                        if (form.Key == ConsoleKey.D1 || form.Key == ConsoleKey.NumPad1)
                        {
                            disOp.DisplayAllDiscontinuedProducts_Short();
                        }
                        else if (form.Key == ConsoleKey.D2 || form.Key == ConsoleKey.NumPad2)
                        {
                            disOp.DisplayAllDiscontinuedProducts_Long();
                        }
                        else
                        {
                            logging.Log("WARN", "Please press a valid option. Try again.");
                        }
                    }
                    else
                    {
                        logging.Log("WARN", "Please press a valid option. Try again.");
                    }
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    Console.WriteLine("Please enter the product that you are searching for. (Name)");
                    string search = Console.ReadLine();



                    var results = db.SearchProducts(search);

                    if (results.Count() == 0)
                    {
                    }
                    else
                    {
                        Console.WriteLine("(1) Display results in short form");
                        Console.WriteLine("(2) Display results in long form");

                        var form = Console.ReadKey();
                        Console.WriteLine("");

                        if (form.Key == ConsoleKey.D1 || form.Key == ConsoleKey.NumPad1)
                        {
                            disOp.DisplayProducts_Short(results);
                        }
                        else if (form.Key == ConsoleKey.D2 || form.Key == ConsoleKey.NumPad2)
                        {
                            disOp.DisplayProducts_Long(results);
                        }
                        else
                        {
                            logging.Log("WARN", "Please press a valid option. Try again.");
                        }
                    }
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }
Beispiel #24
0
        public void Start()
        {
            Console.WriteLine("\n\tADD A PRODUCT\n");


            string  productName;
            string  quantityPerUnit;
            decimal?unitPrice;
            Int16?  unitsInStock;
            Int16?  unitsOnOrder;
            Int16?  reorderLevel;
            bool    discontinued;
            int?    categoryId;

            string  tempn;
            NLogger logging = new NLogger();

            //string nullableMessage = "\n\t* Note: This field allows null. Press nothing but ENTER to leave blank.";

            Console.WriteLine("Please enter the product's name. (Required)");
            productName = Console.ReadLine();

            Console.WriteLine("What is the quantity/unit for this product.");
            quantityPerUnit = Console.ReadLine();

            do
            {
                Console.WriteLine("What is the unit price for this product?" + nullableMessage);
                tempn = Console.ReadLine();
                if (ValidateDecimal(tempn))
                {
                    if (tempn == "")
                    {
                        unitPrice = null;
                    }
                    else
                    {
                        unitPrice = decimal.Parse(tempn);
                    }
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A proper decimal was not entered for the new product's unit price. Please try again.");
                }
            } while (true);

            do
            {
                Console.WriteLine("What is the number of units in stock?" + nullableMessage);
                tempn = Console.ReadLine();
                if (ValidateInt16(tempn))
                {
                    if (tempn == "")
                    {
                        unitsInStock = null;
                    }
                    else
                    {
                        unitsInStock = Int16.Parse(tempn);
                    }
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A proper int (int16, smallint) was not entered for the new product's in stock number. Please try again.");
                }
            } while (true);

            do
            {
                Console.WriteLine("What is the number of units on order?" + nullableMessage);
                tempn = Console.ReadLine();
                if (ValidateInt16(tempn))
                {
                    if (tempn == "")
                    {
                        unitsOnOrder = null;
                    }
                    else
                    {
                        unitsOnOrder = Int16.Parse(tempn);
                    }
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A proper int (int16, smallint) was not entered for the new product's units on order. Please try again.");
                }
            } while (true);


            do
            {
                Console.WriteLine("What is the reorder level?" + nullableMessage);
                tempn = Console.ReadLine();
                if (ValidateInt16(tempn))
                {
                    if (tempn == "")
                    {
                        reorderLevel = null;
                    }
                    else
                    {
                        reorderLevel = Int16.Parse(tempn);
                    }
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A proper int (int16, smallint) was not entered for the new product's reorder level. Please try again.");
                }
            } while (true);

            do
            {
                Console.WriteLine("Is this product discontinued?");
                Console.WriteLine("If yes, Press Y. If No, Press N.");
                ConsoleKeyInfo keypress = Console.ReadKey();
                Console.WriteLine();

                if (keypress.Key == ConsoleKey.Y)
                {
                    discontinued = true;
                    break;
                }
                else if (keypress.Key == ConsoleKey.N)
                {
                    discontinued = false;
                    break;
                }
                else
                {
                    logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                }
            } while (true);

            do
            {
                Console.WriteLine("What category does this product belong to?" + nullableMessage);

                tempn = Console.ReadLine();

                if (tempn == "" || tempn == null)
                {
                    categoryId = null;
                    break;
                }
                else
                {
                    NorthwindContext db    = new NorthwindContext();
                    DisplayOptions   disOp = new DisplayOptions();

                    var category = db.Categories.FirstOrDefault(c => c.CategoryName.Contains(tempn));

                    disOp.DisplayCategory(category);


                    Console.WriteLine("Is this the correct category? (If yes, press Y. If no, press N.)");
                    var keypress = Console.ReadKey();


                    if (keypress.Key == ConsoleKey.Y)
                    {
                        categoryId = category.CategoryId;
                        break;
                    }
                    else if (keypress.Key == ConsoleKey.N)
                    {
                        logging.Log("WARN", "Setting Category to Null");

                        categoryId = null;
                        break;
                    }
                    else
                    {
                        logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                    }
                }
            } while (true);


            //add category

            Product product = new Product
            {
                ProductName     = productName,
                QuantityPerUnit = quantityPerUnit,
                UnitPrice       = unitPrice,
                UnitsInStock    = unitsInStock,
                UnitsOnOrder    = unitsOnOrder,
                ReorderLevel    = reorderLevel,
                Discontinued    = discontinued,
                CategoryId      = categoryId
            };

            if (ConfirmSelections(product) == true)
            {
                NorthwindContext db = new NorthwindContext();

                db.AddProduct(product);
            }
            else
            {
                logging.Log("INFO", "Operation Cancelled.");
            }
        }
Beispiel #25
0
        public void Start()
        {
            do
            {
                Console.WriteLine("\tEDIT CATEGORY\n");

                Console.WriteLine("(1) Display all Categories");
                Console.WriteLine("(2) Display a specific Category and its related Products");
                Console.WriteLine("(3) Search for a specific category to edit (By the Category Name)");
                Console.WriteLine("(4) Search for a specific category to edit (By the Category ID)");
                Console.WriteLine("(5) Search for a specific category to edit (By the Category Description)");

                Console.WriteLine("Press ESC to go back");

                ConsoleKeyInfo keypress = Console.ReadKey();
                Console.WriteLine();

                NLogger        logging = new NLogger();
                DisplayOptions disOp   = new DisplayOptions();

                //Display all categories
                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    disOp.DisplayAllCategories();
                }

                //Display specific category and products
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("Which category are you looking for (Name)?");

                    var results = db.SearchCategory(Console.ReadLine(), true);



                    if (results.Count() == 0)
                    {
                        logging.Log("WARN", "No results found. Try Again.");
                    }
                    else
                    {
                        disOp.DisplayCategoryAndProducts(results.FirstOrDefault());
                    }
                }

                //Edit by Name
                else if (keypress.Key == ConsoleKey.D3 || keypress.Key == ConsoleKey.NumPad3)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("What is the name of the category that you are looking for?");
                    string toFind = Console.ReadLine();


                    var results = db.SearchCategory(toFind, true);

                    if (results.Count() == 0)
                    {
                        //logging.Log("WARN", "No results found. Try Again.");
                    }
                    else if (results.Count() == 1)
                    {
                        disOp.DisplayCategories(results);

                        Console.WriteLine("Is this the correct Product?");
                        Console.WriteLine("If yes, Press Y. If No, Press N.");

                        do
                        {
                            ConsoleKeyInfo keypress2 = Console.ReadKey();
                            Console.WriteLine();

                            if (keypress2.Key == ConsoleKey.Y)
                            {
                                EditCategory(results[0]);
                                break;
                            }
                            else if (keypress2.Key == ConsoleKey.N)
                            {
                                break;
                            }
                            else
                            {
                                logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                            }
                        } while (true);
                    }
                    else
                    {
                        int row = 0;

                        foreach (var category in results)
                        {
                            Console.WriteLine("Row: {0}", row++);
                            disOp.DisplayCategory(category);
                            Console.WriteLine("");
                        }


                        Console.WriteLine("Which Category would you like to edit?");
                        Console.Write("Enter the Row number: \t");

                        string choice = Console.ReadLine();
                        int    vInput = IntValidation(choice);


                        EditCategory(results[vInput - 1]);
                    }
                }

                //Edit by ID
                else if (keypress.Key == ConsoleKey.D4 || keypress.Key == ConsoleKey.NumPad4)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("What is the ID of the category that you are looking for?");
                    int toFind = IntValidation(Console.ReadLine());


                    var results = db.SearchCategory(toFind);

                    if (results.Count() == 0)
                    {
                    }
                    else if (results.Count() == 1)
                    {
                        disOp.DisplayCategories(results);

                        Console.WriteLine("Is this the correct Product?");
                        Console.WriteLine("If yes, Press Y. If No, Press N.");

                        do
                        {
                            ConsoleKeyInfo keypress2 = Console.ReadKey();
                            Console.WriteLine();

                            if (keypress2.Key == ConsoleKey.Y)
                            {
                                EditCategory(results[0]);
                                break;
                            }
                            else if (keypress2.Key == ConsoleKey.N)
                            {
                                break;
                            }
                            else
                            {
                                logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                            }
                        } while (true);
                    }
                    //Should never get used because ID is unique. If it does, something is terribly wrong with the database.
                    else
                    {
                        int row = 0;

                        foreach (var category in results)
                        {
                            Console.WriteLine("Row: {0}", row++);
                            disOp.DisplayCategory(category);
                            Console.WriteLine("");
                        }


                        Console.WriteLine("Which Category would you like to edit?");
                        Console.Write("Enter the Row number: \t");

                        string choice = Console.ReadLine();
                        int    vInput = IntValidation(choice);


                        EditCategory(results[vInput - 1]);
                    }
                }

                //Edit by description
                else if (keypress.Key == ConsoleKey.D5 || keypress.Key == ConsoleKey.NumPad5)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("What is the Description of the category that you are looking for?");
                    string toFind = Console.ReadLine();



                    var results = db.SearchCategory(toFind, false);

                    if (results.Count() == 0)
                    {
                        //logging.Log("WARN", "No results found. Try Again.");
                    }
                    else if (results.Count() == 1)
                    {
                        disOp.DisplayCategories(results);

                        Console.WriteLine("Is this the correct Product?");
                        Console.WriteLine("If yes, Press Y. If No, Press N.");

                        do
                        {
                            ConsoleKeyInfo keypress2 = Console.ReadKey();
                            Console.WriteLine();

                            if (keypress2.Key == ConsoleKey.Y)
                            {
                                EditCategory(results[0]);
                                break;
                            }
                            else if (keypress2.Key == ConsoleKey.N)
                            {
                                break;
                            }
                            else
                            {
                                logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                            }
                        } while (true);
                    }
                    //Should never get used because ID is unique. If it does, something is terribly wrong with the database.
                    else
                    {
                        int row = 0;

                        foreach (var category in results)
                        {
                            Console.WriteLine("Row: {0}", row++);
                            disOp.DisplayCategory(category);
                            Console.WriteLine("");
                        }


                        Console.WriteLine("Which Category would you like to edit?");
                        Console.Write("Enter the Row number: \t");

                        string choice = Console.ReadLine();
                        int    vInput = IntValidation(choice);


                        EditCategory(results[vInput - 1]);
                    }
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }
Beispiel #26
0
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tDELETE PRODUCT\n");

                Console.WriteLine("Delete which product?\n");
                Console.WriteLine("(1) Find by ID");
                Console.WriteLine("(2) Find by Name");

                Console.WriteLine("(ESC) Return to Products menu");

                var keypress = Console.ReadKey();
                Console.WriteLine("");

                NorthwindContext db    = new NorthwindContext();
                DisplayOptions   disOp = new DisplayOptions();

                List <Product> results = null;

                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    Console.WriteLine("Please enter the ID of the product that you are searching for.");
                    int search = IntValidation(Console.ReadLine());


                    results = db.SearchProducts(search);
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    Console.WriteLine("Please enter the Name of the product that you are searching for.");
                    string search = Console.ReadLine();

                    results = db.SearchProducts(search);
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    NLogger logging = new NLogger();

                    logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                }


                if (results == null)
                {
                }
                else if (results.Count() == 0)
                {
                }
                else if (results.Count() == 1)
                {
                    //disOp.DisplayProducts_Long(results);

                    this.Delete(results[0]);
                }
                else
                {
                    disOp.DisplayProducts_Short(results);


                    Console.WriteLine("Which Product?");
                    Console.Write("Enter the Row number: \t");

                    string choice = Console.ReadLine();
                    int    vInput = IntValidation(choice);


                    this.Delete(results[vInput - 1]);
                }
            } while (true);
        }
Beispiel #27
0
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tDISPLAY CATEGORIES\n");

                Console.WriteLine("(1) Display all Categories");
                Console.WriteLine("(2) Display a Category with all related products");

                Console.WriteLine("Press ESC to go back");

                var keypress = Console.ReadKey();
                Console.WriteLine("");

                DisplayOptions disOp = new DisplayOptions();

                //Display all categories
                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    disOp.DisplayAllCategories();
                }
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    Console.WriteLine("What Category are you looking for? \n");

                    Console.WriteLine("(1) Search by ID");
                    Console.WriteLine("(2) Search by Name");
                    Console.WriteLine("(3) Search by Description");

                    var keypress2 = Console.ReadKey();
                    Console.WriteLine("");

                    Category        choice  = null;
                    List <Category> results = null;

                    if (keypress2.Key == ConsoleKey.D1 || keypress2.Key == ConsoleKey.NumPad1)
                    {
                        Console.WriteLine("What is the ID of the Category you want to display?");
                        int toFind = IntValidation(Console.ReadLine());

                        results = db.SearchCategory(toFind).ToList();
                    }
                    else if (keypress2.Key == ConsoleKey.D2 || keypress2.Key == ConsoleKey.NumPad2)
                    {
                        Console.WriteLine("What is the Name of the Category you want to display?");
                        string toFind = Console.ReadLine();

                        results = db.SearchCategory(toFind, true).ToList();
                    }
                    else if (keypress2.Key == ConsoleKey.D3 || keypress2.Key == ConsoleKey.NumPad3)
                    {
                        Console.WriteLine("What is the Description of the Category you want to display?");
                        string toFind = Console.ReadLine();

                        results = db.SearchCategory(toFind, false).ToList();
                    }
                    else
                    {
                        logging.Log("WARN", "Please press a valid option. Try again.");
                    }



                    if (results == null)
                    {
                    }

                    else if (results.Count == 0)
                    {
                    }
                    else if (results.Count == 1)
                    {
                        disOp.DisplayCategory(results[0]);
                        choice = results[0];
                    }
                    else
                    {
                        int row = 0;

                        foreach (var category in results)
                        {
                            Console.WriteLine("Row: {0}", row++);
                            disOp.DisplayCategory(category);
                            Console.WriteLine("");
                        }


                        Console.WriteLine("Which Category would you like to display?");
                        Console.Write("Enter the Row number: \t");

                        string rowChoice = Console.ReadLine();
                        int    vInput    = IntValidation(rowChoice);


                        choice = results[vInput - 1];
                    }



                    if (results.Count > 0)
                    {
                        Console.WriteLine("(1) Display all Products");
                        Console.WriteLine("(2) Display only active Products");
                        Console.WriteLine("(3) Display only discontinued Products");

                        var keypress3 = Console.ReadKey();
                        Console.WriteLine("");

                        if (choice == null)
                        {
                        }

                        else if (keypress3.Key == ConsoleKey.D1 || keypress3.Key == ConsoleKey.NumPad1)
                        {
                            disOp.DisplayCategoryAndProducts(choice);
                        }
                        else if (keypress3.Key == ConsoleKey.D2 || keypress3.Key == ConsoleKey.NumPad2)
                        {
                            disOp.DisplayCategoryAndActiveProducts(choice);
                        }
                        else if (keypress3.Key == ConsoleKey.D3 || keypress3.Key == ConsoleKey.NumPad3)
                        {
                            disOp.DisplayCategoryAndDiscontinuedProducts(choice);
                        }
                        else
                        {
                            logging.Log("WARN", "Please press a valid option. Try again.");
                        }
                    }
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }
        public void Start()
        {
            do
            {
                Console.WriteLine("\n\tEDIT PRODUCTS\n");

                Console.WriteLine("(1) Display all products");
                Console.WriteLine("(2) Search for a specific product to edit by the Product Name");
                Console.WriteLine("(3) Find product to edit by Product ID");

                Console.WriteLine("Press ESC to go back");

                ConsoleKeyInfo keypress = Console.ReadKey();
                Console.WriteLine();

                NLogger        logging = new NLogger();
                DisplayOptions disOp   = new DisplayOptions();

                //Display all products in a short format
                if (keypress.Key == ConsoleKey.D1 || keypress.Key == ConsoleKey.NumPad1)
                {
                    disOp.DisplayAllProducts_Short();
                }

                //Search for product to edit by name
                else if (keypress.Key == ConsoleKey.D2 || keypress.Key == ConsoleKey.NumPad2)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("Which product are you looking for?");

                    var results = db.SearchProducts(Console.ReadLine());



                    if (results.Count() == 0)
                    {
                        logging.Log("WARN", "No results found. Try Again.");
                    }
                    else if (results.Count() == 1)
                    {
                        disOp.DisplayProducts_Short(results);

                        Console.WriteLine("Is this the correct Product?");
                        Console.WriteLine("If yes, Press Y. If No, Press N.");

                        do
                        {
                            ConsoleKeyInfo keypress2 = Console.ReadKey();
                            Console.WriteLine();

                            if (keypress2.Key == ConsoleKey.Y)
                            {
                                int     pickID = results[0].ProductID;
                                Product pick   = results.FirstOrDefault(p => p.ProductID == pickID);
                                EditProduct(pick);
                                break;
                            }
                            else if (keypress2.Key == ConsoleKey.N)
                            {
                                break;
                            }
                            else
                            {
                                logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                            }
                        } while (true);
                    }
                    else
                    {
                        disOp.DisplayProducts_Short(results);


                        Console.WriteLine("Which Product would you like to edit?");
                        Console.Write("Enter the Row number: \t");

                        string choice = Console.ReadLine();
                        int    vInput = IntValidation(choice);

                        int     findID = results[vInput - 1].ProductID;
                        Product pick   = results.FirstOrDefault(p => p.ProductID == findID);

                        EditProduct(pick);
                    }
                }
                //Find product to edit by ID
                else if (keypress.Key == ConsoleKey.D3 || keypress.Key == ConsoleKey.NumPad3)
                {
                    NorthwindContext db = new NorthwindContext();
                    Console.WriteLine("What is the ID number of the product you are looking for?");
                    string check  = Console.ReadLine();
                    int    toFind = IntValidation(check);


                    var results = db.Products.Where(p => p.ProductID == toFind).ToList();

                    if (results.Count() == 0)
                    {
                        logging.Log("WARN", "No results found. Try Again.");
                    }
                    else if (results.Count() == 1)
                    {
                        disOp.DisplayProducts_Short(results);

                        Console.WriteLine("Is this the correct Product?");
                        Console.WriteLine("If yes, Press Y. If No, Press N.");

                        do
                        {
                            ConsoleKeyInfo keypress2 = Console.ReadKey();
                            Console.WriteLine();

                            if (keypress2.Key == ConsoleKey.Y)
                            {
                                EditProduct(results[0]);
                                break;
                            }
                            else if (keypress2.Key == ConsoleKey.N)
                            {
                                break;
                            }
                            else
                            {
                                logging.Log("ERROR", "A valid key was not pressed. Please press (Y)es or (N)o.");
                            }
                        } while (true);
                    }
                    else
                    {
                        disOp.DisplayProducts_Short(results);


                        Console.WriteLine("Which Product would you like to edit?");
                        Console.Write("Enter the Row number: \t");

                        string choice = Console.ReadLine();
                        int    vInput = IntValidation(choice);


                        EditProduct(results[vInput - 1]);
                    }
                }
                else if (keypress.Key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    logging.Log("WARN", "Please press a valid option. Try again.");
                }
            } while (true);
        }