Esempio n. 1
0
        /// <summary>
        /// Takes a serial number in and first checks the stored list of
        /// known serial numbers from the database. If it is not found,
        /// it makes a call to apples web api using the DeviceID class.
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public IActionResult GetSN(GeneralViewModel search)
        {
            string     str      = search.NewSearch.SearchText.ToString();
            string     lastFour = search.NewSearch.SearchText.ToString().Substring(str.Length - 4);
            LastFourSN lfsn     = _context.LastFourSNs.FirstOrDefault(m => m.last4 == lastFour);

            GeneralViewModel gvm = new GeneralViewModel();

            if (lfsn == null)
            {
                DeviceID dId      = new DeviceID();
                string   itemName = dId.AppleSNLookup(str);
                gvm.DeviceName = itemName;
            }
            else
            {
                gvm.DeviceName = lfsn.name;
            }



            Computer computer = _context.Computers.Search(
                m => m.Model.ToLower(),
                m => m.Description.ToLower(),
                m => m.ModelIdentifier.ToLower())
                                .Containing(gvm.DeviceName.ToLower()).FirstOrDefault();

            IOSDevice iOSDevice = _context.IOSDevices.Search(
                m => m.DeviceName.ToLower(),
                m => m.DeviceModel.ToLower(),
                m => m.DeviceConfiguration.Configuration.ToLower(),
                m => m.DeviceModelNumber.Model.ToLower())
                                  .Containing(gvm.DeviceName.ToLower()).FirstOrDefault();


            if (computer != null)
            {
                gvm.Computer = computer;
                return(RedirectToAction("details", "Computers", new { id = computer.Id }));
            }
            if (iOSDevice != null)
            {
                gvm.IOSDevice = iOSDevice;
                return(RedirectToAction("details", "IOSDevices", new { id = iOSDevice.Id }));
            }
            else
            {
                return(View("Index", gvm));
            }
        }
Esempio n. 2
0
        public void ParseSNData()
        {
            JObject obj = JObject.Parse(System.IO.File.ReadAllText(@"Data/sndb.json"));

            System.Diagnostics.Debug.WriteLine(obj);
            foreach (var item in obj.SelectToken("items"))
            {
                LastFourSN lfsn = new LastFourSN();
                lfsn.last4 = item.SelectToken("last4").ToString();
                lfsn.name  = item.SelectToken("name").ToString();
                _context.LastFourSNs.Add(lfsn);
            }
            _context.SaveChanges();
        }