public async Task <IActionResult> Import(string source, IFormFile file, bool IsEquipment = true) { var data = new List <Equipment>(); var migration = new DataMigrations(); try { switch (source) { case "MacService": if (file is null || file.Length == 0 || !string.Equals(file.ContentType, "application/json", StringComparison.OrdinalIgnoreCase)) { throw new Exception("No appropriate file selected!"); } // Used to import Macservice data await migration.ImportMacServiceJson(_service, file); break; case "Backup": //Restore from .json Export if (file is null || file.Length == 0 || !string.Equals(file.ContentType, "application/json", StringComparison.OrdinalIgnoreCase)) { throw new Exception("No appropriate file selected!"); } data = (await migration.InsertBackupJson <Equipment>(file, IsEquipment)).ToList(); break; case "Random": //Random for testing await migration.InsertRandomData(_service); return(Json(true)); case "LegacyJSON": await migration.LegacyImportJson(_service, file); return(Json(true)); default: return(Json(false)); } for (int i = 0; i < data.Count; i++) { await _service.Create(data[i]); } } catch (Exception) { throw; } return(Json(true)); }