Exemplo n.º 1
0
        public DvdItem GetDvdById(int id)
        {
            DvdItem dvd = null;

            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("SearchById", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@DvdId", id);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    if (dr.Read())
                    {
                        dvd             = new DvdItem();
                        dvd.DvdId       = (int)dr["DvdId"];
                        dvd.Title       = dr["DvdTitle"].ToString();
                        dvd.ReleaseYear = dr["ReleaseYear"].ToString();
                        dvd.Director    = dr["Director"].ToString();
                        dvd.RatingType  = dr["Rating"].ToString();
                        dvd.Notes       = dr["Notes"].ToString();
                    }
                }
            }

            return(dvd);
        }
Exemplo n.º 2
0
        public IEnumerable <DvdItem> GetDvdByRating(string rating)
        {
            List <DvdItem> dvds = new List <DvdItem>();

            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("SearchByRating", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@Rating", rating);

                cn.Open();

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        DvdItem row = new DvdItem();

                        row.DvdId       = (int)dr["DvdId"];
                        row.Title       = dr["DvdTitle"].ToString();
                        row.ReleaseYear = dr["ReleaseYear"].ToString();
                        row.Director    = dr["Director"].ToString();
                        row.RatingType  = dr["Rating"].ToString();
                        row.Notes       = dr["Notes"].ToString();

                        dvds.Add(row);
                    }
                }
            }

            return(dvds);
        }
Exemplo n.º 3
0
        public void DeleteDvd(int dvdId)
        {
            DvdItem deletedDvd = DvdItems.FirstOrDefault(d => d.DvdId == dvdId);

            DvdItems.Remove(deletedDvd);
            SaveChanges();
        }
Exemplo n.º 4
0
        void IDvdRepository.CreateDvd(DvdItem dvdItem)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("CreateDvd", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter param = new SqlParameter("@DvdId", SqlDbType.Int);
                param.Direction = ParameterDirection.Output;

                cmd.Parameters.Add(param);

                cmd.Parameters.AddWithValue("@DvdTitle", dvdItem.Title);
                cmd.Parameters.AddWithValue("@ReleaseYear", dvdItem.ReleaseYear);
                cmd.Parameters.AddWithValue("@Director", dvdItem.Director);
                cmd.Parameters.AddWithValue("@Rating", dvdItem.RatingType);
                cmd.Parameters.AddWithValue("@Notes", dvdItem.Notes);

                cn.Open();

                cmd.ExecuteNonQuery();

                dvdItem.DvdId = (int)param.Value;
            }
        }
Exemplo n.º 5
0
        public IHttpActionResult GetDvdById(int id)
        {
            DvdItem found = _dvdRepository.GetDvdById(id);

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

            return(Ok(found));
        }
Exemplo n.º 6
0
        public void CreateDvd(string title, string releaseYear, string director, string rating, string notes)
        {
            DvdItem updatedItem = new DvdItem();

            updatedItem.DvdId      = DvdItems.Max(d => d.DvdId) + 1;
            updatedItem.Title      = title;
            updatedItem.Director   = director;
            updatedItem.RatingType = rating;
            updatedItem.Notes      = notes;

            DvdItems.Add(updatedItem);
        }
Exemplo n.º 7
0
        public void UpdateDvd(string dvdId, string title, string releaseYear, string director, string rating, string notes)
        {
            DvdItem updatedDvd = new DvdItem();

            _dvds.RemoveAll(d => d.DvdId == Int32.Parse(dvdId));
            updatedDvd.Title       = title;
            updatedDvd.ReleaseYear = releaseYear;
            updatedDvd.Director    = director;
            updatedDvd.RatingType  = rating;
            updatedDvd.Notes       = notes;

            _dvds.Add(updatedDvd);
        }
Exemplo n.º 8
0
        public void UpdateDvd(DvdItem dvdItem)
        {
            DvdItem updatedDvd = new DvdItem();

            _dvds.RemoveAll(d => d.DvdId == dvdItem.DvdId);
            updatedDvd.Title       = dvdItem.Title;
            updatedDvd.ReleaseYear = dvdItem.ReleaseYear;
            updatedDvd.Director    = dvdItem.Director;
            updatedDvd.RatingType  = dvdItem.RatingType;
            updatedDvd.Notes       = dvdItem.Notes;

            _dvds.Add(updatedDvd);
        }
Exemplo n.º 9
0
        public void CreateDvd(DvdItem dvdItem)
        {
            DvdItem updatedItem = new DvdItem();

            updatedItem.DvdId       = DvdItems.Max(d => d.DvdId) + 1;
            updatedItem.Title       = dvdItem.Title;
            updatedItem.ReleaseYear = dvdItem.ReleaseYear;
            updatedItem.Director    = dvdItem.Director;
            updatedItem.RatingType  = dvdItem.RatingType;
            updatedItem.Notes       = dvdItem.Notes;

            DvdItems.Add(updatedItem);
            SaveChanges();
        }
Exemplo n.º 10
0
        public void UpdateDvd(string dvdId, string title, string releaseYear, string director, string rating, string notes)
        {
            DvdItem updatedItem = new DvdItem();

            updatedItem.DvdId       = Int32.Parse(dvdId);
            updatedItem.Title       = title;
            updatedItem.Director    = director;
            updatedItem.RatingType  = rating;
            updatedItem.ReleaseYear = releaseYear;
            updatedItem.Notes       = notes;
            DvdItem dvdToUpdate = DvdItems.Where(d => d.DvdId == Int32.Parse(dvdId)).FirstOrDefault();

            DvdItems.Remove(dvdToUpdate);
            DvdItems.Add(updatedItem);
        }
Exemplo n.º 11
0
        public void UpdateDvd(DvdItem dvdItem)
        {
            DvdItem updatedItem = new DvdItem();

            updatedItem.DvdId       = dvdItem.DvdId;
            updatedItem.Title       = dvdItem.Title;
            updatedItem.Director    = dvdItem.Director;
            updatedItem.RatingType  = dvdItem.RatingType;
            updatedItem.ReleaseYear = dvdItem.ReleaseYear;
            updatedItem.Notes       = dvdItem.Notes;
            DvdItem dvdToUpdate = DvdItems.Where(d => d.DvdId == dvdItem.DvdId).FirstOrDefault();

            DvdItems.Remove(dvdToUpdate);
            DvdItems.Add(updatedItem);
            SaveChanges();
        }
Exemplo n.º 12
0
        public void UpdateDvd(DvdItem dvdItem)
        {
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                SqlCommand cmd = new SqlCommand("UpdateDvd", cn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@DvdId", dvdItem.DvdId);
                cmd.Parameters.AddWithValue("@DvdTitle", dvdItem.Title);
                cmd.Parameters.AddWithValue("@ReleaseYear", dvdItem.ReleaseYear);
                cmd.Parameters.AddWithValue("@Director", dvdItem.Director);
                cmd.Parameters.AddWithValue("@Rating", dvdItem.RatingType);
                cmd.Parameters.AddWithValue("@Notes", dvdItem.Notes);

                cn.Open();

                cmd.ExecuteNonQuery();
            }
        }
Exemplo n.º 13
0
        public void CreateDvd(DvdItem dvdItem)
        {
            DvdItem newDvd = new DvdItem();

            if (_dvds.Any())
            {
                newDvd.DvdId = _dvds.Max(d => d.DvdId) + 1;
            }
            else
            {
                newDvd.DvdId = 0;
            }

            newDvd.Title       = dvdItem.Title;
            newDvd.ReleaseYear = dvdItem.ReleaseYear;
            newDvd.Director    = dvdItem.Director;
            newDvd.RatingType  = dvdItem.RatingType;
            newDvd.Notes       = dvdItem.Notes;

            _dvds.Add(newDvd);
        }
Exemplo n.º 14
0
        public void CreateDvd(string title, string releaseYear, string director, string ratingType, string notes)
        {
            DvdItem newDvd = new DvdItem();

            if (_dvds.Any())
            {
                newDvd.DvdId = _dvds.Max(d => d.DvdId) + 1;
            }
            else
            {
                newDvd.DvdId = 0;
            }

            newDvd.Title       = title;
            newDvd.ReleaseYear = releaseYear;
            newDvd.Director    = director;
            newDvd.RatingType  = ratingType;
            newDvd.Notes       = notes;

            _dvds.Add(newDvd);
        }
Exemplo n.º 15
0
        public IHttpActionResult CreateDvd(DvdItem dvdItem)
        {
            _dvdRepository.CreateDvd(dvdItem);

            return(Created($"contact/{dvdItem.DvdId}", dvdItem));
        }
Exemplo n.º 16
0
 public void UpdateDvd(DvdItem dvdItem)
 {
     _dvdRepository.UpdateDvd(dvdItem);
 }
Exemplo n.º 17
0
        public DvdItem GetDvdById(int id)
        {
            DvdItem dvdById = DvdItems.Where(d => d.DvdId == id).FirstOrDefault();

            return(dvdById);
        }