コード例 #1
0
        public IActionResult AfterEdit(Visitor edited)
        {
            Visitor visitor = (
                from v in _newContext.Visitors
                where v.RegistrationNumber == edited.RegistrationNumber
                select v
                ).SingleOrDefault();

            visitor.Name       = edited.Name;
            visitor.Last       = edited.Last;
            visitor.Occupation = edited.Occupation;
            visitor.Company    = edited.Company;
            _newContext.SaveChanges();
            return(View("CheckInForm", visitor));
        }
コード例 #2
0
        public RedirectToActionResult RemoveDuplicateStaff()
        {
            IEnumerable <StaffNames> Staff = _textFileOperations.RemoveDuplicateStaff();

            _context.StaffNames.AddRange(Staff);
            _context.SaveChanges();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #3
0
        public void UploadStaffFile()
        {
            //--------------Get the data from the Text file --------------
            string[] lines = { };

            //Gets or sets the absolute path to the directory that contains the web-servable application content files.
            string webRootPath = _environment.WebRootPath;

            FileInfo filePath = new FileInfo(Path.Combine(webRootPath, "Staff.txt"));

            lines = System.IO.File.ReadAllLines(filePath.ToString());

            //holds all the staff names
            Dictionary <string, StaffNames> StaffnamesDict = new Dictionary <string, StaffNames>();

            List <StaffNames> AllStaffNames = new List <StaffNames>();

            foreach (var name in lines)
            {
                StaffNames staffnames = new StaffNames();
                string[]   data       = name.Split(',');
                staffnames.Name       = data[0];
                staffnames.Department = data[1];

                //if the name isn't there, add it in
                if (!StaffnamesDict.ContainsKey(staffnames.Name))
                {
                    StaffnamesDict.Add(staffnames.Name, staffnames);
                    AllStaffNames.Add(staffnames);
                }
            }


            //--------------Get the data from the Database --------------

            //add in the ones from the db
            AllStaffNames.AddRange(RemoveDuplicateStaff());
            //sort the new data and pull out only uniques
            IOrderedEnumerable <StaffNames> orderedStaffNames = AllStaffNames.Distinct().OrderBy(
                i => i.Department).ThenBy(i => i.Name);

            _context.AddRange(orderedStaffNames);
            _context.SaveChanges();
        }