예제 #1
0
 public IHttpActionResult Create([FromBody] Dvd model)
 {
     if (ModelState.IsValid)
     {
         var result = _repo.Create(model);
         return(Ok(result));
     }
     return(BadRequest("Why would you do this? Now I am very sad."));
 }
        public IHttpActionResult Add(JObject input)
        {
            Dvd dvd = DvdMapper.ToDVD(input);

            _repo.Create(dvd);

            JObject result = DvdMapper.ToJSON(dvd);

            return(Created($"dvd/{dvd.DvdId}", result));
        }
예제 #3
0
        public void Create(Dvd dvd)
        {
            dvds = _dvdRepository.GetAll();

            if (dvds.Any())
            {
                dvd.DvdId = dvds.Max(d => d.DvdId) + 1;
            }

            else
            {
                dvd.DvdId = 1;
            }

            _dvdRepository.Create(dvd);
        }
예제 #4
0
        public void FullCRRRRRRUDTest()
        {
            Dvd testDvd = new Dvd
            {
                title        = "Test DVD",
                director     = "Testing",
                rating       = "R",
                realeaseYear = "2019",
                notes        = "If you can see this, the test didn't edit itself properly."
            };

            testDvd = _repo.Create(testDvd);
            Assert.AreEqual(testDvd.notes, _repo.Read(testDvd.dvdId).notes);
            testDvd.notes = "If you can see this, the test didn't clean itself up properly.";
            _repo.Update(testDvd);
            Assert.AreEqual(testDvd.notes, _repo.Read(testDvd.dvdId).notes);
            Assert.IsNotEmpty(_repo.ReadAll(), "Could not read all");
            Assert.IsNotEmpty(_repo.ReadByDirector("Testing"), "Could not read by director");
            Assert.IsNotEmpty(_repo.ReadByRating("R"), "Could not read by rating");
            Assert.IsNotEmpty(_repo.ReadByTitle("Test DVD"), "Could not read by title");
            Assert.IsNotEmpty(_repo.ReadByYear("2019"), "Could not read by year");
            _repo.Delete(testDvd.dvdId);
            Assert.IsNull(_repo.Read(testDvd.dvdId).rating);
        }
예제 #5
0
 public IHttpActionResult Create(Dvd dvd)
 {
     _dvdRepository.Create(dvd);
     return(Created($"dvd/{dvd.DvdId}", dvd));
 }
예제 #6
0
 public IHttpActionResult Add(Dvd newDvd)
 {
     _dvdRepository.Create(newDvd);
     return(Created($"dvd/{newDvd.DvdId}", newDvd));
 }