Ok, so there are a few excepotions here, I cannot use List<Dvd> Dvds = _dvds.ReadAll();
in DvdController.cs and check to see if it contains the dvd info if dvd is already in the list. Even if I did do that, it does not work as I intended it to do. Even if I check to see if the info is in the list and try to stop it, it still adds it to a list. The Dvd.cs does increment the Id by one by the way. I would like to know what would be the solution to this?
DvdController.cs
...
private void CreateDvd() //Create
{
var myView = new DvdView();
var dvdInfos = myView.GetNewDvdInfo();
_dvds.Create(dvdInfos);
DisplayDvds();
}
...
DvdRepository.cs
public class DvdRepository
{
private static List<Dvd> dvds = new List<Dvd>()
{
new Dvd("Batman", 2010, "Bruce", 4 ),
new Dvd("Superman", 2009, "John", 4),
new Dvd("Wonderwoman", 2012, "Omar", 4)
};
public Dvd Create(Dvd dvd)
{
if (dvds.Contains(dvd))
{
Console.WriteLine("duplicate"); //not working
}
else
dvds.Add(dvd);
return dvds.FirstOrDefault(d => d.Id == dvd.Id);
}
public List<Dvd> ReadAll()
{
return dvds;
}
...
Dvd.cs
public class Dvd
{
public Dvd(string title, int releaseyear, string director, float rating)
{
Id = Interlocked.Increment(ref globalId);
Title = title;
ReleaseYear = releaseyear;
Director = director;
Rating = rating;
}
public static int globalId;
public int Id { get; private set; }
public string Title { get; set; }
public int ReleaseYear { get; set; }
public string Director { get; set; }
public float Rating { get; set; }