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); }
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); }
public void DeleteDvd(int dvdId) { DvdItem deletedDvd = DvdItems.FirstOrDefault(d => d.DvdId == dvdId); DvdItems.Remove(deletedDvd); SaveChanges(); }
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; } }
public IHttpActionResult GetDvdById(int id) { DvdItem found = _dvdRepository.GetDvdById(id); if (found == null) { return(NotFound()); } return(Ok(found)); }
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); }
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); }
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); }
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(); }
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); }
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(); }
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(); } }
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); }
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); }
public IHttpActionResult CreateDvd(DvdItem dvdItem) { _dvdRepository.CreateDvd(dvdItem); return(Created($"contact/{dvdItem.DvdId}", dvdItem)); }
public void UpdateDvd(DvdItem dvdItem) { _dvdRepository.UpdateDvd(dvdItem); }
public DvdItem GetDvdById(int id) { DvdItem dvdById = DvdItems.Where(d => d.DvdId == id).FirstOrDefault(); return(dvdById); }