Пример #1
0
 public Computer GetById(int itemId)
 {
     using (var context = new AssetsContext())
     {
         return(context.Computers.Find(itemId));
     }
 }
Пример #2
0
 public Tv GetById(int itemId)
 {
     using (var context = new AssetsContext())
     {
         return(context.Tvs.Find(itemId));
     }
 }
Пример #3
0
        static void ListInventory()
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine($"            ASSETS  INVENTORY        \n");
            Console.WriteLine($">.............................................................<\n");
            Console.ResetColor();

            using (var dbContext = new AssetsContext())
            {
                Write("Brand, Model and year, Date of purchase, Expiration date, Expiration price");
                var formattedItems = dbContext.Computers
                                     .Select(computer => (
                                                 $"ID: {computer.Id}, {computer.Brand}, {computer.ModelName}, " +
                                                 $"{computer.PurchaseDate}, {computer.InicialCost}, " +
                                                 $"{computer.ExpiredDate}, {computer.ExpiredCost}"
                                                 )).ToList();

                Console.WriteLine();

                Console.WriteLine(string.Join("     Is a Computer\n", formattedItems) + "     Is a Computer\n");
            }
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine($">.............................................................<\n");
            Console.ResetColor();
        }
Пример #4
0
 public List <Computer> GetAll()
 {
     using (var context = new AssetsContext())
     {
         return(context.Computers.ToList());
     }
 }
Пример #5
0
 public Phone GetById(int itemId)
 {
     using (var context = new AssetsContext())
     {
         return(context.Phones.Find(itemId));
     }
 }
Пример #6
0
 public List <Tv> GetAll()
 {
     using (var context = new AssetsContext())
     {
         return(context.Tvs.ToList());
     }
 }
Пример #7
0
 public List <Phone> GetAll()
 {
     using (var context = new AssetsContext())
     {
         return(context.Phones.ToList());
     }
 }
Пример #8
0
 public void Create(Tv Tv)
 {
     using (var context = new AssetsContext())
     {
         context.Tvs.Add(Tv);
         context.SaveChanges();
     }
 }
Пример #9
0
 public void Delete(Phone Phone)
 {
     using (var context = new AssetsContext())
     {
         context.Phones.Remove(Phone);
         context.SaveChanges();
     }
 }
Пример #10
0
 public void Create(Phone Phone)
 {
     using (var context = new AssetsContext())
     {
         context.Phones.Add(Phone);
         context.SaveChanges();
     }
 }
Пример #11
0
 public void Delete(Computer computer)
 {
     using (var context = new AssetsContext())
     {
         context.Computers.Remove(computer);
         context.SaveChanges();
     }
 }
Пример #12
0
 public void Create(Computer computer)
 {
     using (var context = new AssetsContext())
     {
         context.Computers.Add(computer);
         context.SaveChanges();
     }
 }
Пример #13
0
 public void Delete(Tv Tv)
 {
     using (var context = new AssetsContext())
     {
         context.Tvs.Remove(Tv);
         context.SaveChanges();
     }
 }
Пример #14
0
 public void Update(Computer computer)
 {
     using (var context = new AssetsContext())
     {
         var existingComputer = context.Computers.Find(computer.Id);
         existingComputer.Brand        = computer.Brand;
         existingComputer.ModelName    = computer.ModelName;
         existingComputer.PurchaseDate = computer.PurchaseDate;
         existingComputer.InicialCost  = computer.InicialCost;
         existingComputer.ExpiredDate  = computer.ExpiredDate;
         existingComputer.ExpiredCost  = computer.ExpiredCost;
         context.SaveChanges();
     }
 }
Пример #15
0
 public void Update(Phone Phone)
 {
     using (var context = new AssetsContext())
     {
         var existingPhone = context.Phones.Find(Phone.Id);
         existingPhone.Brand        = Phone.Brand;
         existingPhone.ModelName    = Phone.ModelName;
         existingPhone.PurchaseDate = Phone.PurchaseDate;
         existingPhone.InicialCost  = Phone.InicialCost;
         existingPhone.ExpiredDate  = Phone.ExpiredDate;
         existingPhone.ExpiredCost  = Phone.ExpiredCost;
         context.SaveChanges();
     }
 }
Пример #16
0
 public void Update(Tv Tv)
 {
     using (var context = new AssetsContext())
     {
         var existingTv = context.Tvs.Find(Tv.Id);
         existingTv.Brand        = Tv.Brand;
         existingTv.ModelName    = Tv.ModelName;
         existingTv.PurchaseDate = Tv.PurchaseDate;
         existingTv.InicialCost  = Tv.InicialCost;
         existingTv.ExpiredDate  = Tv.ExpiredDate;
         existingTv.ExpiredCost  = Tv.ExpiredCost;
         context.SaveChanges();
     }
 }
Пример #17
0
        static void ShowAllItems()
        {
            AssetsContext context;

            using (context = new AssetsContext())
            {
                var list = context.Computers.ToList();
                foreach (Asset bp in list)
                {
                    Console.WriteLine(bp.Id.ToString().PadRight(5) + bp.Brand.PadRight(30) +
                                      bp.ModelName.PadRight(20) + bp.PurchaseDate.ToString().PadRight(5) +
                                      bp.InicialCost.ToString().PadRight(5) + bp.ExpiredDate.ToString().PadRight(5) +
                                      bp.ExpiredCost.ToString().PadRight(5)
                                      );
                }
            }
            Console.WriteLine();
        }
Пример #18
0
        public static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine($">.............................................................<\n");
            Console.WriteLine($"       Welcome to IDESIGNER.SE\n");
            Console.WriteLine($">.............................................................<\n");

            using (var dbContext = new AssetsContext())
            {
                //(string brand, string modelName, int purchaseDate, int inicialCost, int expiredDate, int expiredCost)
                // new Asset("MacBook", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000),
                dbContext.Add(new Computer("MacBook", "Pro 2018 15 inch ", new DateTime(2018, 1, 1), 13000, new DateTime(2021, 12, 01), 8000));
                dbContext.Add(new Phone("Iphuff", "Pro 2018 15 inch ", new DateTime(2018, 1, 1), 13000, new DateTime(2021, 12, 1), 8000));
                dbContext.Add(new Tv("SamAbsurd", "Pro 2018 15 inch ", new DateTime(2018, 1, 1), 13000, new DateTime(2021, 12, 1), 8000));
                dbContext.SaveChanges();
            }

            PageMainMenu();
        }
Пример #19
0
        static void Main(string[] args)
        {
            using (var dbContext = new AssetsContext())
            {
                //(string brand, string modelName, int purchaseDate, int inicialCost, int expiredDate, int expiredCost)
                // new Asset("MacBook", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000),
                dbContext.Add(new Computer("MacBook", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000));

                dbContext.SaveChanges();

                var result = dbContext.Computers.ToList()
                             .Select(d => d.Brand);
                Console.WriteLine(string.Join(", ", result));;



                //             Console.WriteLine("Hello World!");
                //           using (var dbContext = new CustomTreatmentContext())
                //         {
                //           dbContext.Add(new Diet("Superduper diet", "Hard", 2, 200));
                //         dbContext.SaveChanges();
                //       var result = dbContext.Diets.ToList()
                //         .Where(d => d.DietDaysProgram > 0)
                //       .Take(5)
                //     .OrderBy(d => d.DietDaysProgram)
                //                       .Select(d => d.DietName);
                //
                //                 var resultSum = dbContext.Diets
                //                   .Where(d => d.DietDaysProgram > 0)
                //                 .OrderBy(d => d.DietDaysProgram)
                //               .GroupBy(o => 1)
                //             .Select(d =>
                //               "Average days:" + (float)d.Sum(d => d.DietDaysProgram) / (float)Math.Max(1, d.Count()) +
                //             "(total diets: " + d.Count() + ")"
                //       );
                //                   Console.WriteLine(string.Join(", ", result));
                //                 Console.WriteLine(string.Join(", ", resultSum));
                //           }
            }
        }
Пример #20
0
        static void Main(string[] args)
        {
            using (var dbContext = new AssetsContext())
            {
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($">.............................................................<\n");
                Console.WriteLine($"       Welcomen to IDESIGNER.SE\n");
                Console.WriteLine($">.............................................................<\n");

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"            ASSETS  INVENTORY        \n");
                Console.WriteLine($">.............................................................<\n");
                Console.ResetColor();


                //(string brand, string modelName, int purchaseDate, int inicialCost, int expiredDate, int expiredCost)
                // new Asset("MacBook", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000),
                dbContext.Add(new Computer("MacBook", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000));
                dbContext.Add(new Phone("Iphuff", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000));
                dbContext.Add(new Tv("SamAbsurd", "Pro 2018 15 inch ", 20180101, 13000, 20211201, 8000));
                dbContext.SaveChanges();

                var brand = dbContext.Computers.ToList()
                            .Select(brand => brand.Brand);

                var modelName = dbContext.Computers.ToList()
                                .Select(modelName => modelName.ModelName);
                Console.WriteLine();

                var purchaseDate = dbContext.Computers.ToList()
                                   .Select(purchaseDate => purchaseDate.PurchaseDate);

                var inicialCost = dbContext.Computers.ToList()
                                  .Select(inicialCost => inicialCost.InicialCost);

                var expiredDate = dbContext.Computers.ToList()
                                  .Select(expiredDate => expiredDate.ExpiredDate);

                var expiredCost = dbContext.Computers.ToList()
                                  .Select(expiredCost => expiredCost.ExpiredCost);

                Console.WriteLine(string.Join("                     Is a Computer Brand.\n", brand));
                Console.WriteLine(string.Join("           Is Computer Model Name\n", modelName));
                Console.WriteLine(string.Join("                    Is a Computer purchase Date\n", purchaseDate));

                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine($">.............................................................<\n");
                Console.ResetColor();

                PageMainMenu();

                void PageMainMenu()
                {
                    Menu();
                }

                void CreateItem()
                {
                    Header("Create");
                    Menu();
                }

                void PageUpdateItems()
                {
                    Header("Create");

                    Console.WriteLine("Witch Item to update? ");

                    int ItemId = int.Parse(Console.ReadLine());

                    AssetsContext context;

                    using (context = new AssetsContext())
                    {
                        var list = context.Computers.ToList();
                    }

                    Computer computer = DbContext.GetItemById(ItemId);

                    Console.WriteLine("Your Actual Item is: " + computer.Id);

                    Menu();
                }

                void DeleteItem()
                {
                    Header("Create");
                    Menu();
                }

                void ShowAllItems()
                {
                    AssetsContext context;

                    using (context = new AssetsContext())
                    {
                        var list = context.Computers.ToList();
                    }
                    foreach (Asset bp in list)
                    {
                        Console.WriteLine(bp.Id.ToString().PadRight(5) + bp.Brand.PadRight(30) +
                                          bp.ModelName.PadRight(20) + bp.PurchaseDate.ToString().PadRight(5) +
                                          bp.InicialCost.ToString().PadRight(5) + bp.ExpiredDate.ToString().PadRight(5) +
                                          bp.ExpiredCost.ToString().PadRight(5)
                                          );
                    }
                    Console.WriteLine();
                }

                void QuitProgram()
                {
                    string insert = Console.ReadLine();

                    {
                        Console.WriteLine("\nBye, Thanks for your visit!\n");
                        return;
                    }
                }

                void Menu()
                {
                    Console.WriteLine("Press key A,B,C or D Instructions: \n".PadLeft(5));
                    Console.WriteLine("a) Back Menu".PadLeft(5));
                    Console.WriteLine("b) Create an Item".PadLeft(5));
                    Console.WriteLine("c) Update and Item".PadLeft(5));
                    Console.WriteLine("d) Delete and Item".PadLeft(5));
                    Console.WriteLine("Key Return twices to QUIT this program".PadLeft(5));


                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    Console.WriteLine($">.............................................................<\n");
                    Console.ResetColor();

                    ConsoleKey command = Console.ReadKey(true).Key;

                    if (command == ConsoleKey.A)
                    {
                        PageMainMenu();
                    }

                    if (command == ConsoleKey.B)
                    {
                        CreateItem();
                    }

                    if (command == ConsoleKey.C)
                    {
                        PageUpdateItems();
                    }

                    if (command == ConsoleKey.D)
                    {
                        DeleteItem();
                    }

                    if (command == ConsoleKey.Enter)
                    {
                        QuitProgram();
                    }
                }

                void Header(string text)
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine();
                    Console.WriteLine(text.ToUpper());
                    Console.WriteLine();
                }

                //             Console.WriteLine("Hello World!");
                //           using (var dbContext = new CustomTreatmentContext())
                //         {
                //           dbContext.Add(new Diet("Superduper diet", "Hard", 2, 200));
                //         dbContext.SaveChanges();
                //       var result = dbContext.Diets.ToList()
                //         .Where(d => d.DietDaysProgram > 0)
                //       .Take(5)
                //     .OrderBy(d => d.DietDaysProgram)
                //                       .Select(d => d.DietName);
                //
                //                 var resultSum = dbContext.Diets
                //                   .Where(d => d.DietDaysProgram > 0)
                //                 .OrderBy(d => d.DietDaysProgram)
                //               .GroupBy(o => 1)
                //             .Select(d =>
                //               "Average days:" + (float)d.Sum(d => d.DietDaysProgram) / (float)Math.Max(1, d.Count()) +
                //             "(total diets: " + d.Count() + ")"
                //       );
                //                   Console.WriteLine(string.Join(", ", result));
                //                 Console.WriteLine(string.Join(", ", resultSum));
                //           }
            }
        }