//Adding user's configuration public async Task <IActionResult> AddConfig(string hwtype) { string user = _userManager.GetUserId(User); if (!String.IsNullOrEmpty(user)) { PC pcdata = new PC(); string hwid; pcdata.DateOfCreation = DateTime.Now; pcdata.ApplicationUserID = user; hwid = HttpContext.Session.GetString(SessionKeyCPU); if (!String.IsNullOrEmpty(hwid)) { pcdata.CPU = await _context.CPUs.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyGPU); if (!String.IsNullOrEmpty(hwid)) { pcdata.GPU = await _context.GPUs.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyMOBO); if (!String.IsNullOrEmpty(hwid)) { pcdata.MOBO = await _context.MOBOes.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyRAM); if (!String.IsNullOrEmpty(hwid)) { pcdata.RAM = await _context.RAMs.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyPSU); if (!String.IsNullOrEmpty(hwid)) { pcdata.PSU = await _context.PSUs.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyCase); if (!String.IsNullOrEmpty(hwid)) { pcdata.Case = await _context.Cases.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } hwid = HttpContext.Session.GetString(SessionKeyCooler); if (!String.IsNullOrEmpty(hwid)) { pcdata.Cooler = await _context.Coolers.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); hwid = null; } string SessionKeyStorage; pcdata.PC_Storage = new Collection <PC_Storage>(); for (int i = 1; i <= max_storage_amount; i++) { SessionKeyStorage = SessionKeyStorageBase + i; hwid = HttpContext.Session.GetString(SessionKeyStorage); if (!String.IsNullOrEmpty(hwid)) { Storage stg = await _context.Storages.SingleOrDefaultAsync(s => s.Id == Int32.Parse(hwid)); PC_Storage pc_stg = new PC_Storage { PC = pcdata, Storage = stg }; if (stg.PC_Storage == null) { stg.PC_Storage = new Collection <PC_Storage>(); } stg.PC_Storage.Add(pc_stg); pcdata.PC_Storage.Add(pc_stg); } hwid = null; } if (pcdata.CPU != null || pcdata.GPU != null || pcdata.MOBO != null || pcdata.RAM != null || pcdata.PSU != null || pcdata.Case != null || pcdata.Cooler != null || pcdata.PC_Storage.Any() ) { _context.PCs.Add(pcdata); try { await _context.SaveChangesAsync(); }catch (DbUpdateException ex) { _logger.LogInformation("Unable to save configuration." + ex); } ViewData["ServerMessage"] = "<span id=\"temp-config-success-msg\">[Configuration has been added successfully.]</span>"; } else { ViewData["ServerMessage"] = "<span id=\"temp-config-error-msg\">[You cant' add an empty configuration.]</span>"; } } else { ViewData["ServerMessage"] = "<span id=\"temp-config-error-msg\">[You need to be logged in to save your configuration.]</span>"; } return(await LoadDataFromHwType(hwtype)); }
private PC_StorageColecao ConsultarStorage() { List <string[]> listStorage = new List <string[]>(); string ler = string.Empty; using (StreamReader sr = new StreamReader(path)) { while ((ler = sr.ReadLine()) != null) { if (ler.Contains("Storage")) { string[] storage = new string[5]; while ((ler = sr.ReadLine()) != null) { if (ler.Contains("Name")) { storage[0] = ler; } if (ler.Contains("Serial")) { storage[1] = ler; } if (ler.Contains("Capacity")) { storage[2] = ler; } if (ler.Contains("Type") && !ler.Contains("RAID") && !ler.Contains("Bus")) { storage[3] = ler.Replace("Fixed", "Interno"); } if (ler.Contains("Volume")) { storage[4] = ler.Replace(" percent available", "% disponível"); string[] novo = TratarArray(storage); listStorage.Add(novo); } if (ler.Contains("USB")) { goto Hd; } } } } Hd: PC_StorageColecao colecaoStorage = new PC_StorageColecao(); foreach (string[] storage in listStorage) { PC_Storage Storage = new PC_Storage { Capacidade = storage[2], Nome = storage[0], Serial = storage[1], Tipo = storage[3], Volume = storage[4] }; colecaoStorage.Add(Storage); } return(colecaoStorage); } }