Exemple #1
0
        public IHttpActionResult Update(UpdateDvdRequest request)
        {
            var repo = DvdRepositoryFactory.Create();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Dvd dvd = repo.GetDvd(request.DvdId);

            if (dvd == null)
            {
                return(NotFound());
            }

            dvd.Title       = request.Title;
            dvd.Director    = request.Director;
            dvd.ReleaseYear = request.ReleaseYear;
            dvd.Rating      = request.Rating;
            dvd.Notes       = request.Notes;

            repo.EditDvd(dvd);
            return(Ok(dvd));
        }
        public IHttpActionResult DeleteDvd(int DvdId)
        {
            Dvd dvd = DvdRepositoryFactory.Create().GetDvdByID(DvdId);

            if (dvd == null)
            {
                return(NotFound());
            }

            DvdRepositoryFactory.Create().DeleteDvd(DvdId);
            return(Ok());
        }
        public IHttpActionResult GetAllDvds()
        {
            List <Dvd> dvds = DvdRepositoryFactory.Create().GetAllDvds();

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
        public IHttpActionResult GetDvdByTitle(string title)
        {
            List <Dvd> dvds = DvdRepositoryFactory.Create().GetDvdByTitle(title);

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
        public IHttpActionResult GetDvdByReleaseYear(int releaseYear)
        {
            List <Dvd> dvds = DvdRepositoryFactory.Create().GetDvdByReleaseYear(releaseYear);

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
Exemple #6
0
 public void EditDvd(int id, Dvd dvd)
 {
     //validate edit
     if (ModelState.IsValid)
     {
         IDvdRepository DvdRepo = DvdRepositoryFactory.Create();
         DvdRepo.Edit(dvd);
     }
     else
     {
         Content(HttpStatusCode.BadRequest, "Model state invalid");
     }
 }
Exemple #7
0
        public IHttpActionResult Delete(int id)
        {
            var repo  = DvdRepositoryFactory.Create();
            Dvd movie = repo.GetDvd(id);

            if (movie == null)
            {
                return(NotFound());
            }

            repo.DeleteDvd(id);
            return(Ok());
        }
        public IHttpActionResult GetDvdByDirector(string director)
        {
            List <Dvd> dvds = DvdRepositoryFactory.Create().GetDvdByDirector(director);

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
Exemple #9
0
        public IHttpActionResult Get(int id)
        {
            var repo = DvdRepositoryFactory.Create();
            Dvd dvd  = repo.GetDvd(id);

            if (dvd == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvd));
            }
        }
        public IHttpActionResult GetDvdById(int DvdId)
        {
            Dvd dvd = DvdRepositoryFactory.Create().GetDvdByID(DvdId);

            if (dvd == null)
            {
                return(NotFound());
            }
            else
            {
                //Creates HTTP Response status 200
                return(Ok(dvd));
            }
        }
Exemple #11
0
        public IHttpActionResult GetDvdsByDate(int year)
        {
            var        repo = DvdRepositoryFactory.Create();
            List <Dvd> dvds = repo.GetDvdsByDate(year);

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
Exemple #12
0
        public IHttpActionResult GetDvdsByRating(string rating)
        {
            var        repo = DvdRepositoryFactory.Create();
            List <Dvd> dvds = repo.GetDvdsByRating(rating);

            if (dvds == null)
            {
                return(NotFound());
            }
            else
            {
                return(Ok(dvds));
            }
        }
Exemple #13
0
        public void CreateDvd(AddDvdRequest request)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            Dvd dvd = new Dvd
            {
                Title        = request.Title,
                RealeaseYear = request.RealeaseYear,
                Director     = request.Director,
                Rating       = request.Rating,
                Notes        = request.Notes
            };

            repo.AddDvd(dvd);
        }
Exemple #14
0
        public IHttpActionResult AddDvd(Dvd dvd)
        {
            //validate add
            if (ModelState.IsValid)
            {
                IDvdRepository DvdRepo = DvdRepositoryFactory.Create();
                DvdRepo.Add(dvd);

                //return route
                return(Created($"/dvd{dvd.DvdId}", dvd));
            }
            else
            {
                return(Content(HttpStatusCode.BadRequest, "Model state invalid"));
            }
        }
Exemple #15
0
        public void UpdateDvd(int id, EditDvdRequest request)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            Dvd dvd = new Dvd
            {
                DvdId        = request.DvdId,
                Title        = request.Title,
                RealeaseYear = request.RealeaseYear,
                Director     = request.Director,
                Rating       = request.Rating,
                Notes        = request.Notes
            };

            repo.EditDvd(dvd, id);
        }
        public IHttpActionResult CreateDvd(Dvd info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Dvd newDvd = new Dvd()
            {
                Title       = info.Title,
                ReleaseYear = info.ReleaseYear,
                Director    = info.Director,
                Rating      = info.Rating,
                Notes       = info.Notes
            };

            DvdRepositoryFactory.Create().CreateDvd(info);
            return(Created($"dvd/{info.DvdId}", info));
        }
Exemple #17
0
        public IHttpActionResult Add(AddDvdRequest request)
        {
            var repo = DvdRepositoryFactory.Create();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Dvd dvd = new Dvd()
            {
                Title       = request.Title,
                Director    = request.Director,
                ReleaseYear = request.ReleaseYear,
                Rating      = request.Rating,
                Notes       = request.Notes
            };

            repo.AddDvd(dvd);
            return(Created($"dvd/get/{dvd.DvdId}", dvd));
        }
        public IHttpActionResult UpdateDvd(Dvd info)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Dvd dvd = DvdRepositoryFactory.Create().GetDvdByID(info.DvdId);

            if (dvd == null)
            {
                return(NotFound());
            }

            dvd.DvdId       = info.DvdId;
            dvd.Title       = info.Title;
            dvd.ReleaseYear = info.ReleaseYear;
            dvd.Director    = info.Director;
            dvd.Rating      = info.Rating;
            dvd.Notes       = info.Notes;

            DvdRepositoryFactory.Create().UpdateDvd(dvd);
            return(Ok(dvd));
        }
Exemple #19
0
        public List <Dvd> GetByRating(string rating)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetByRating(rating));
        }
Exemple #20
0
        public List <Dvd> GetByDirector(string directorName)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetByDirector(directorName));
        }
Exemple #21
0
        public List <Dvd> GetByRealeaseYear(int realeaseYear)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetByYear(realeaseYear));
        }
Exemple #22
0
        public List <Dvd> GetByTitle(string title)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetByTitle(title));
        }
Exemple #23
0
        public List <Dvd> GetAll()
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetAll());
        }
Exemple #24
0
        public Dvd GetById(int id)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            return(repo.GetById(id));
        }
Exemple #25
0
        public IHttpActionResult GetByTitle(string title)
        {
            IDvdRepository DvdRepo = DvdRepositoryFactory.Create();

            return(Ok(DvdRepo.GetByTitle(title)));
        }
Exemple #26
0
        public IHttpActionResult GetByReleaseYear(int releaseYear)
        {
            IDvdRepository DvdRepo = DvdRepositoryFactory.Create();

            return(Ok(DvdRepo.GetByReleaseYear(releaseYear)));
        }
Exemple #27
0
        public IHttpActionResult GetByDirectorName(string directorName)
        {
            IDvdRepository DvdRepo = DvdRepositoryFactory.Create();

            return(Ok(DvdRepo.GetByDirector(directorName)));
        }
Exemple #28
0
        public IHttpActionResult GetByRating(string rating)
        {
            IDvdRepository DvdRepo = DvdRepositoryFactory.Create();

            return(Ok(DvdRepo.GetByRating(rating)));
        }
Exemple #29
0
 static DvdController()
 {
     _repo = DvdRepositoryFactory.Create();
 }
Exemple #30
0
        public void DeleteDvd(int id)
        {
            IDvdRepository repo = DvdRepositoryFactory.Create();

            repo.DeleteDvd(id);
        }