// for testing public int Add(DiscLocalDto disc) { int newId = AddDiscToList(disc); string jsonDiscs = SerializeDiscs(); SaveToFile(jsonDiscs, pathToJson); return(newId); }
private int AddDiscToList(DiscLocalDto discDto) { if (!discs.Any(d => d.DiscName == discDto.DiscName)) { int highestId = discs.Max(d => d.Id); discDto.Id = highestId + 1; discs.Add(discDto); } else { throw new ArgumentOutOfRangeException(discDto.DiscName, "Disc name already exists in Database"); } return(discDto.Id); }
public void Add_NewDisc_AddsToDiscTable() { string dbLocation = @"c:\temp\Files on Dvd.accdb"; DiscRepository repository = new DiscRepository(dbLocation); DiscLocalDto discDto = new DiscLocalDto() { DiscName = "TestingDisc2", Wallet = 5, Notes = "A Test from .NET" }; int expectedId = 226; int id = repository.Add(discDto); Console.WriteLine("Debug this line"); Assert.AreEqual(expectedId, id); }
private void PopulateDiscsFromDatabase(DataTable discsTable) { foreach (DataRow row in discsTable.Rows) { string idStr = row["ID"].ToString(); bool result = int.TryParse(idStr, out int id); string walletTypeStr = row["Wallet"].ToString(); result = int.TryParse(walletTypeStr, out int walletType); DiscLocalDto disc = new DiscLocalDto() { Id = id, DiscName = row["DiscName"].ToString(), Wallet = walletType, Notes = row["Notes"].ToString() }; discs.Add(disc); } }
public int Add(DiscLocalDto discDto) { AccessRetriever retriever = new AccessRetriever(databasePath); DataSet dataSet; int? id = 0; try { dataSet = retriever.GetDiscs(); } catch (Exception e) { Log.Error(e, "Could not retrieve discs from database"); throw new ArgumentException("Could not retrieve discs from database", e); } DataTable discsTable = dataSet.Tables[0]; PopulateDiscsFromDatabase(discsTable); if (discs.Any(d => d.DiscName == discDto.DiscName)) { Log.Error("Disc {0} already exists in database", discDto.DiscName); throw new ArgumentOutOfRangeException(discDto.DiscName, "Disc name already exists in database!"); } else { DataRow newRow = discsTable.NewRow(); newRow["DiscName"] = discDto.DiscName; newRow["Wallet"] = discDto.Wallet; newRow["Notes"] = discDto.Notes; // newRow[2] = 1; // this is supposed to be Performer Type. Can use the column number instead discsTable.Rows.Add(newRow); var changes = dataSet.GetChanges(); id = retriever.UpdateDiscs(dataSet); if (id is null) { throw new InvalidOperationException("New DiscId is null. Check Access DB to see if it was entered."); } else { Log.Information("Added Disc {0} to database with ID {1}", discDto.DiscName, id); } } return((int)id); }
public int Add(DvdFolderToImport disc) { DiscLocalDto discDto = new DiscLocalDto(disc); return(Add(discDto)); }