public DvdDetails Insert(DvdDetails dvd) { using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("DvdInsert", cn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter param = new SqlParameter("@DvdID", SqlDbType.Int); param.Direction = ParameterDirection.Output; cmd.Parameters.Add(param); cmd.Parameters.AddWithValue("@Title", dvd.Title); cmd.Parameters.AddWithValue("@Year", dvd.Year); cmd.Parameters.AddWithValue("@RatingValue", dvd.RatingValue); cmd.Parameters.AddWithValue("@DirectorName", dvd.DirectorName); cmd.Parameters.AddWithValue("@NoteInfo", dvd.Note); //cmd.Parameters.AddWithValue("@ReleaseID", dvd.ReleaseID); //cmd.Parameters.AddWithValue("@RatingID", dvd.RatingID); //cmd.Parameters.AddWithValue("@DirectorID", dvd.DirectorID); cn.Open(); cmd.ExecuteNonQuery(); dvd.DvdID = (int)param.Value; } return(dvd); }
public DvdDetails Update(DvdDetails dvd) { using (var context = new DvdContextModel()) { var idParameter = new SqlParameter { ParameterName = "@DvdID", SqlDbType = SqlDbType.Int, Value = dvd.DvdID }; var titleParameter = new SqlParameter { ParameterName = "@Title", SqlDbType = SqlDbType.VarChar, Value = dvd.Title }; var yearParameter = new SqlParameter { ParameterName = "@Year", SqlDbType = SqlDbType.Int, Value = dvd.Year }; var directorParameter = new SqlParameter { ParameterName = "@DirectorName", SqlDbType = SqlDbType.VarChar, Value = dvd.DirectorName }; var ratingParameter = new SqlParameter { ParameterName = "@RatingValue", SqlDbType = SqlDbType.VarChar, Value = dvd.RatingValue }; var noteParameter = new SqlParameter { ParameterName = "@Note", SqlDbType = SqlDbType.VarChar, Value = dvd.Note }; context.Database.SqlQuery <DvdDetails>("DvdUpdate @DvdID, @Title, @Year, @DirectorName, @RatingValue, @Note", idParameter, titleParameter, yearParameter, directorParameter, ratingParameter, noteParameter).SingleOrDefault(); } return(dvd); }
public void ADOCanEditDvd() { var repo = new DvdRepoADO(); var dvdToAdd = new DvdDetails(); dvdToAdd.Title = "Test"; dvdToAdd.Year = 2020; dvdToAdd.Note = "Test, test"; dvdToAdd.DirectorName = "Tester"; dvdToAdd.RatingValue = "X"; //dvdToAdd.DirectorID = 15; //dvdToAdd.RatingID = 15; //dvdToAdd.ReleaseID = 15; repo.Insert(dvdToAdd); dvdToAdd.Title = "Test2"; dvdToAdd.Year = 2022; dvdToAdd.Note = "Test, test2"; dvdToAdd.DirectorName = "Tester2"; dvdToAdd.RatingValue = "X2"; repo.Update(dvdToAdd); Assert.AreEqual(7, dvdToAdd.DvdID); Assert.AreEqual("Test2", dvdToAdd.Title); Assert.AreEqual(2022, dvdToAdd.Year); Assert.AreEqual("Tester2", dvdToAdd.DirectorName); Assert.AreEqual("X2", dvdToAdd.RatingValue); Assert.AreEqual("Test, test2", dvdToAdd.Note); }
public void ADOCanDeleteDvd() { var repo = new DvdRepoADO(); var dvdToAdd = new DvdDetails(); dvdToAdd.Title = "Test"; dvdToAdd.Year = 2020; dvdToAdd.Note = "Test, test"; dvdToAdd.DirectorName = "Tester"; dvdToAdd.RatingValue = "X"; //dvdToAdd.DirectorID = 15; //dvdToAdd.RatingID = 15; //dvdToAdd.ReleaseID = 15; repo.Insert(dvdToAdd); var loaded = repo.GetByID(7); Assert.IsNotNull(loaded); repo.Delete(7); loaded = repo.GetByID(7); Assert.IsNull(loaded); }
public IHttpActionResult Update(UpdateDvdRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var repo = DvdRepoFactory.GetRepository(); DvdDetails dvd = repo.GetByID(request.dvdId); if (dvd == null) { return(NotFound()); } dvd.Title = request.title; dvd.Year = request.realeaseYear; dvd.DirectorName = request.director; dvd.RatingValue = request.rating.ToUpper(); dvd.Note = request.notes; repo.Update(dvd); return(Ok(dvd)); }
public ActionResult DeleteConfirmed(int id) { DvdDetails dvdDetails = db.DvdDetails.Find(id); db.DvdDetails.Remove(dvdDetails); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "DvdId,DvdTitle,DvdDescription,TotalDvdCopies,ReleaseDate,DateAdded,AgeRestiriction,Studio,Producer,Cast")] DvdDetails dvdDetails) { if (ModelState.IsValid) { db.Entry(dvdDetails).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dvdDetails)); }
public IHttpActionResult Delete(int dvdId) { DvdDetails dvd = DvdRepoFactory.GetRepository().GetByID(dvdId); if (dvd == null) { return(NotFound()); } DvdRepoFactory.GetRepository().Delete(dvdId); return(Ok()); }
public IHttpActionResult Get(int dvdId) { DvdDetails dvd = DvdRepoFactory.GetRepository().GetByID(dvdId); if (dvd == null) { return(NotFound()); } else { return(Ok(dvd)); } }
public static DvdDetails Delete(int dvdId) { DvdDetails dvdToDelete = _dvds.Where(d => d.DvdID == dvdId).FirstOrDefault(); if (dvdToDelete == null) { return(null); } else { _dvds.RemoveAll(d => d.DvdID == dvdId); return(dvdToDelete); } }
public static DvdDetails Update(DvdDetails dvd) { var found = _dvds.FirstOrDefault(d => d.DvdID == dvd.DvdID); if (found != null) { //found = dvd; return(dvd); } else { return(null); } }
public static DvdDetails Insert(DvdDetails dvd) { if (_dvds.Count() == 0) { dvd.DvdID = 1; } else { dvd.DvdID = _dvds.Max(d => d.DvdID) + 1; } _dvds.Add(dvd); return(dvd); }
// GET: DvdDetails/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DvdDetails dvdDetails = db.DvdDetails.Find(id); if (dvdDetails == null) { return(HttpNotFound()); } return(View(dvdDetails)); }
public DvdDetails GetByID(int DvdID) { DvdDetails dvd = new DvdDetails(); using (var context = new DvdContextModel()) { var idParameter = new SqlParameter { ParameterName = "@DvdID", SqlDbType = SqlDbType.Int, Value = DvdID }; dvd = context.Database.SqlQuery <DvdDetails>("DvdDetailsByID @DvdID", idParameter).SingleOrDefault(); } return(dvd); }
public DvdDetails Delete(int dvdID) { DvdDetails dvdToDelete = this.GetByID(dvdID); using (var context = new DvdContextModel()) { var idParamter = new SqlParameter { ParameterName = "@DvdID", SqlDbType = SqlDbType.Int, Value = dvdID }; context.Database.SqlQuery <DvdDetails>("DvdDelete @DvdID", idParamter).SingleOrDefault(); } return(dvdToDelete); }
public DvdDetails Delete(int dvdID) { DvdDetails dvdDeleted = this.GetByID(dvdID); using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("DvdDelete", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DvdID", dvdID); cn.Open(); cmd.ExecuteNonQuery(); } return(dvdDeleted); }
public IHttpActionResult Add(AddDvdRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } DvdDetails dvd = new DvdDetails() { Title = request.title, Year = request.realeaseYear, DirectorName = request.director, RatingValue = request.rating.ToUpper(), Note = request.notes }; DvdRepoFactory.GetRepository().Insert(dvd); return(Created($"dvd/{dvd.DvdID}", dvd)); }
public DvdDetails Update(DvdDetails dvd) { using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("DvdUpdate", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DvdID", dvd.DvdID); cmd.Parameters.AddWithValue("@Title", dvd.Title); cmd.Parameters.AddWithValue("@Year", dvd.Year); cmd.Parameters.AddWithValue("@RatingValue", dvd.RatingValue); cmd.Parameters.AddWithValue("@DirectorName", dvd.DirectorName); cmd.Parameters.AddWithValue("@NoteInfo", dvd.Note); cn.Open(); cmd.ExecuteNonQuery(); } return(dvd); }
public List <DvdDetails> GetByDirector(string director) { List <DvdDetails> dvds = new List <DvdDetails>(); using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("DvdDetailsByDirector", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DirectorName", director); cn.Open(); //SELECT DvdID, Title, ReleaseID, DirectorID, RatingID, Note using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { DvdDetails currentRow = new DvdDetails(); currentRow.DvdID = (int)dr["DvdID"]; currentRow.Title = dr["Title"].ToString(); currentRow.ReleaseID = (int)dr["ReleaseID"]; currentRow.DirectorID = (int)dr["DirectorID"]; currentRow.RatingID = (int)dr["RatingID"]; currentRow.DirectorName = dr["DirectorName"].ToString(); currentRow.RatingValue = dr["RatingValue"].ToString(); currentRow.Year = (int)dr["Year"]; if (dr["Note"] != DBNull.Value) { currentRow.Note = dr["Note"].ToString(); } dvds.Add(currentRow); } } } return(dvds); }
public DvdDetails GetByID(int DvdID) { DvdDetails dvd = null; using (var cn = new SqlConnection(Settings.GetConnectionString())) { SqlCommand cmd = new SqlCommand("DvdDetailsByID", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@DvdID", DvdID); cn.Open(); //SELECT DvdID, Title, ReleaseID, DirectorID, RatingID, Note using (SqlDataReader dr = cmd.ExecuteReader()) { if (dr.Read()) { dvd = new DvdDetails(); dvd.DvdID = (int)dr["DvdID"]; dvd.Title = dr["Title"].ToString(); dvd.ReleaseID = (int)dr["ReleaseID"]; dvd.DirectorID = (int)dr["DirectorID"]; dvd.RatingID = (int)dr["RatingID"]; dvd.DirectorName = dr["DirectorName"].ToString(); dvd.RatingValue = dr["RatingValue"].ToString(); dvd.Year = (int)dr["Year"]; if (dr["Note"] != DBNull.Value) { dvd.Note = dr["Note"].ToString(); } } } } return(dvd); }
public DvdDetails Update(DvdDetails dvd) { return(MockRepo.Update(dvd)); }
public DvdDetails Insert(DvdDetails dvd) { return(MockRepo.Insert(dvd)); }