Пример #1
0
        public ActionResult Create([Bind(Include = "Id,Name,Level,Code,Descriptin,ParentId")] Machine machine)
        {
            if (ModelState.IsValid)
            {
                db.Machines.Add(machine);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ParentId = new SelectList(db.Machines, "Id", "Name", machine.ParentId);
            return(View(machine));
        }
Пример #2
0
        public void PostDernierChoix(Choix_utilisateurs dernierChoix)
        {
            var result = _machineContext.Choix_utilisateurs.Where(u => u.Num_Badge == dernierChoix.Num_Badge);

            if (result != null)
            {
                _machineContext.Remove(result.FirstOrDefault());
                _machineContext.SaveChanges();
            }

            _machineContext.Add(dernierChoix);
            _machineContext.SaveChanges();
        }
Пример #3
0
        public ActionResult EditMachine(MachineViewModel machineViewModel)
        {
            using (var machineContext = new MachineContext())
            {
                var machine = machineContext.Machines.SingleOrDefault(m => m.MachineId == machineViewModel.MachineId);

                if (machine != null)
                {
                    machine.MachineNum   = machineViewModel.MachineNum.Value;
                    machine.MachineMake  = machineViewModel.MachineMake;
                    machine.MachineModel = machineViewModel.MachineModel;
                    machine.TypeId       = machineViewModel.TypeId;
                    machine.Hours        = machineViewModel.Hours.Value;
                    machine.Notes        = machineViewModel.Notes;
                    machine.Status       = machineViewModel.Status;
                    machine.Photo        = machineViewModel.Photo;
                    machineContext.SaveChanges();


                    return(RedirectToAction("Index"));
                }

                return(new HttpNotFoundResult());
            }
        }
Пример #4
0
 static void SeedOperatingSystemTable()
 {
     using (var context = new MachineContext()) {
         var os = new OperatingSys {
             Name = "Windows XP", StillSupported = false
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows 7", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows 8", StillSupported = false
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows 8.1", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows 10", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2000", StillSupported = false
         };
         context.OperatingSys.Add(os);
         //os = new OperatingSys { Name = "Windows Server 2003 R2", StillSupported = false };
         //context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2008", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2008 R2", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2012", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2012 R2", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Windows Server 2016", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Ubuntu Server 16.14.2 LTS", StillSupported = true
         };
         context.OperatingSys.Add(os);
         os = new OperatingSys {
             Name = "Ubuntu Server 17.04", StillSupported = true
         };
         context.OperatingSys.Add(os);
         context.SaveChanges();
     }
 }
 private void CloseTicket(int ticketId)
 {
     Console.WriteLine("Closing ticket...");
     using (MachineContext context = new MachineContext()) {
         SupportTicket sTicket = context.SupportTicket.Where(x => x.SupportTicketId == ticketId).FirstOrDefault();
         sTicket.DateResolved = DateTime.Now;
         context.Update(sTicket);
         context.SaveChanges();
         Console.WriteLine("Ticket is closed");
     }
 }
Пример #6
0
 static void DeleteAllUnsupportedOperatingSystems()
 {
     using (var context = new MachineContext()) {
         var os = (from o in context.OperatingSys where o.StillSupported == false select o);
         Console.WriteLine("\r\nDeleting all Unsupported Operating Systems...");
         context.OperatingSys.RemoveRange(os);
         int i = context.SaveChanges();
         Console.WriteLine($"We have deleted {i} records");
         Console.WriteLine("Hit any key to continue...");
         Console.ReadKey();
     }
 }
Пример #7
0
 private void UpdateMachine()
 {
     try
     {
         var toUpdate = db.Machines.Where(m => m.Id == SelectedMachine.Id).Single();
         if (toUpdate == null)
         {
             InfoText = "Entry not found!";
             return;
         }
         toUpdate.Name        = SelectedMachine.Name;
         toUpdate.Description = SelectedMachine.Description;
         db.SaveChanges();
         ResetFields();
     }
     catch (Exception)
     {
         InfoText = "Entry not found!";
         return;
     }
 }
Пример #8
0
        public ActionResult DeleteMachine(MachineViewModel machineViewModel)
        {
            using (var machineContext = new MachineContext())
            {
                var machine = machineContext.Machines.SingleOrDefault(p => p.Id == machineViewModel.Id);

                if (machine != null)
                {
                    machineContext.Machines.Remove(machine);
                    machineContext.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }

            return(new HttpNotFoundResult());
        }
        static void DeleteOperatingSystem(int id)
        {
            OperatingSys os = GetOperatingSystemById(id);

            if (os != null)
            {
                Console.WriteLine($"\r\nAre you sure you want to delete {os.Name}? [y or n]");
                Console.ForegroundColor = ConsoleColor.White;
                ConsoleKeyInfo cki;
                string         result;
                bool           cont;
                do
                {
                    cki    = Console.ReadKey(true);
                    result = cki.KeyChar.ToString();
                    cont   = ValidateYorN(result);
                } while (!cont);
                if ("y" == result.ToLower())
                {
                    Console.WriteLine("\r\nDeleting record");
                    Console.ForegroundColor = ConsoleColor.White;
                    using (var context = new MachineContext())
                    {
                        context.Remove(os);
                        context.SaveChanges();
                    }
                    Console.WriteLine("Record Deleted");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadKey();
                }
                else
                {
                    Console.WriteLine("Delete Aborted\r\nHit any key to continue...");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadKey();
                }
            }
            else
            {
                Console.WriteLine("\r\nOperating System Not Found!");
                Console.ForegroundColor = ConsoleColor.White;
                Console.ReadKey();
                SelectOperatingSystem("Delete");
            }
        }
Пример #10
0
        public ActionResult AddMachine(MachineViewModel machineViewModel)
        {
            using (var machineContext = new MachineContext())
            {
                var machine = new Machine
                {
                    Num   = machineViewModel.Num,
                    Make  = machineViewModel.Make,
                    Model = machineViewModel.Model,
                    Hours = machineViewModel.Hours
                };

                machineContext.Machines.Add(machine);
                machineContext.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Пример #11
0
        public bool CreateComment(Comment comment)
        {
            ModelInput input = new ModelInput()
            {
                SentimentText = comment.Text
            };

            var result = ConsumeModel.Predict(input);

            bool sentimentresult = result.Prediction == "1" ? true : false;

            comment.Toxic      = sentimentresult;
            comment.PostedDate = DateTime.Now;

            _context.Comments.Add(comment);

            _context.SaveChanges();

            return(sentimentresult);
        }
Пример #12
0
        public ActionResult AddMachine(MachineViewModel machineViewModel)
        {
            using (var machineContext = new MachineContext())
            {
                var machine = new Mach
                {
                    MachineNum   = machineViewModel.MachineNum.Value,
                    MachineMake  = machineViewModel.MachineMake,
                    MachineModel = machineViewModel.MachineModel,
                    TypeId       = machineViewModel.TypeId,
                    Hours        = machineViewModel.Hours.Value,
                    Notes        = machineViewModel.Notes,
                    Status       = machineViewModel.Status,
                    Photo        = machineViewModel.Photo
                };

                machineContext.Machines.Add(machine);
                machineContext.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        private void AddSupportLogEntry(string entry, bool close, int ticketId)
        {
            bool            modelIsValid = false;
            ModelValidation mv           = new ModelValidation();

            Console.WriteLine("Saving new log entry");
            using (MachineContext context = new MachineContext())
            {
                SupportLog sLogEntry = new SupportLog()
                {
                    SupportTicketId     = ticketId,
                    SupportLogEntry     = entry,
                    SupportLogUpdatedBy = Environment.UserName,
                    SupportLogEntryDate = DateTime.Now //DateTime.Now.AddSeconds(-2000)
                };
                modelIsValid = mv.ValidateSupportLog(sLogEntry, "save");
                if (modelIsValid)
                {
                    context.SupportLog.Add(sLogEntry);
                    int res = context.SaveChanges();
                    Console.WriteLine($"{res} record saved");
                }
            }
            if (modelIsValid)
            {
                if (close)
                {
                    CloseTicket(ticketId);
                }
            }
            else
            {
                Console.WriteLine("There is a problem with your Entry");
                foreach (var error in mv.errorList)
                {
                    Console.WriteLine($"{error.FieldName} {error.Error}");
                }
            }
        }
        static void ModifyOperatingSystem(int id)
        {
            OperatingSys os = GetOperatingSystemById(id);

            Console.Clear();
            char           operation = '0';
            bool           cont      = false;
            ConsoleKeyInfo cki;

            WriteHeader("Update Operating System");
            if (os != null)
            {
                Console.WriteLine($"\r\nOS Name: {os.Name}  Still Supported: {os.StillSupported}");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("To modify the name press 1\r\nTo modify if the OS is Still Supported press 2");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Hit Esc to exit this menu");
                Console.ForegroundColor = ConsoleColor.White;

                do
                {
                    cki = Console.ReadKey(true);
                    if (cki.Key == ConsoleKey.Escape)
                    {
                        cont = true;
                    }
                    else
                    {
                        if (char.IsNumber(cki.KeyChar))
                        {
                            if (cki.KeyChar == '1')
                            {
                                Console.WriteLine("Updated Operating System Name: ");
                                Console.ForegroundColor = ConsoleColor.White;
                                operation = '1';
                                cont      = true;
                            }
                            else if (cki.KeyChar == '2')
                            {
                                Console.WriteLine("Update if the OS is Still Supported [y or n]: ");
                                Console.ForegroundColor = ConsoleColor.White;
                                operation = '2';
                                cont      = true;
                            }
                        }
                    }
                } while (!cont);
            }
            if (operation == '1')
            {
                string osName;
                cont = false;
                do
                {
                    osName = Console.ReadLine();
                    if (osName.Length >= 4)
                    {
                        cont = true;
                    }
                    else
                    {
                        Console.WriteLine("Please enter a vaild OS name of at least 4 characters.\r\nPress and key to continue...");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.ReadKey();
                    }
                } while (!cont);
                os.Name = osName;
            }
            else if (operation == '2')
            {
                string k;
                do
                {
                    cki  = Console.ReadKey(true);
                    k    = cki.KeyChar.ToString();
                    cont = ValidateYorN(k);
                } while (!cont);
                if (k == "y")
                {
                    os.StillSupported = true;
                }
                else
                {
                    os.StillSupported = false;
                }
            }
            using (var context = new MachineContext())
            {
                var o = context.OperatingSys.FirstOrDefault(i => i.OperatingSysId == os.OperatingSysId);
                if (o != null)
                {
                    // just making sure
                    o.Name           = os.Name;
                    o.StillSupported = os.StillSupported;
                    Console.WriteLine("\r\nUpdating the database...");
                    Console.ForegroundColor = ConsoleColor.White;
                    context.SaveChanges();
                    Console.WriteLine("Done!\r\nHit any key to continue...");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            Console.ReadKey();
        }
        static void AddOperatingSystem()
        {
            Console.Clear();
            ConsoleKeyInfo cki;
            string         result;
            bool           cont   = false;
            OperatingSys   os     = new OperatingSys();
            string         osName = "";

            do
            {
                WriteHeader("Add New Operating System");
                Console.WriteLine("Enter the Name of the Operating System and hit Enter");
                Console.ForegroundColor = ConsoleColor.White;
                osName = Console.ReadLine();
                if (osName.Length >= 4)
                {
                    cont = true;
                }
                else
                {
                    Console.WriteLine("Please enter a vaild OS name of at least 4 characters.\r\nPress and key to continue...");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadKey();
                }
            } while (!cont);
            cont    = false;
            os.Name = osName;
            Console.WriteLine("Is the Operating System still supported? [y or n]");
            Console.ForegroundColor = ConsoleColor.White;
            do
            {
                cki    = Console.ReadKey();
                result = cki.KeyChar.ToString();
                cont   = ValidateYorN(result);
            } while (!cont);

            if (result.ToLower() == "y")
            {
                os.StillSupported = true;
            }
            else
            {
                os.StillSupported = false;
            }
            cont = false;
            do
            {
                Console.Clear();
                Console.WriteLine($"You entered {os.Name} as the Operating System Name\r\nIs the OS still supported, you entered {os.StillSupported}.\r\nDo you wish to continue? [y or n]");
                Console.ForegroundColor = ConsoleColor.White;
                cki    = Console.ReadKey();
                result = cki.KeyChar.ToString();
                cont   = ValidateYorN(result);
            } while (!cont);
            if (result.ToLower() == "y")
            {
                bool exists = CheckForExistingOS(os.Name);
                if (exists)
                {
                    Console.WriteLine("\r\nOperating System already exists in the database\r\nPress any key to continue...");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.ReadKey();
                }
                else
                {
                    using (var context = new MachineContext())
                    {
                        Console.WriteLine("\r\nAttempting to save changes...");
                        Console.ForegroundColor = ConsoleColor.White;
                        context.OperatingSys.Add(os);
                        int i = context.SaveChanges();
                        if (i == 1)
                        {
                            Console.WriteLine("Contents Saved\r\nPress any key to continue...");
                            Console.ForegroundColor = ConsoleColor.White;
                            Console.ReadKey();
                        }
                    }
                }
            }
        }