public void Edit(dvd dvd) { var repository = new DvdLibraryEF(); var newDirector = repository.Directors.FirstOrDefault(d => d.DirectorName == dvd.director); if (newDirector == null) { newDirector = repository.Directors.Add(new DirectorEF { DirectorName = dvd.director }); repository.SaveChanges(); } var newRating = repository.Ratings.FirstOrDefault(d => d.RatingName == dvd.rating); if (newRating == null) { newRating = repository.Ratings.Add(new RatingEF { RatingName = dvd.rating }); repository.SaveChanges(); } var TheDvd = repository.DVDs.FirstOrDefault(d => d.dvdId == dvd.dvdId); TheDvd.director = newDirector; TheDvd.notes = dvd.notes; TheDvd.realeaseYear = dvd.realeaseYear; TheDvd.rating = newRating; TheDvd.title = dvd.title; repository.SaveChanges(); }
public IHttpActionResult New(AddDvdRequest model) { dvd movie = new dvd(); // if (ModelState.IsValid) // { movie.title = model.title; movie.rating = model.rating; movie.director = model.director; movie.realeaseYear = model.realeaseYear; movie.notes = model.notes; _dvdRepository.Add(movie); // DvdRepoMock.Edit(movie); return(Ok(movie)); // } // else { return NotFound(); } // return Ok(DvdRepoMock.GetAll()); }
public dvd Get(int dvdid) { dvd dvds = new dvd(); using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdLibrary"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "RetreiveDvdByID"; cmd.Parameters.AddWithValue("@DvdID", dvdid); conn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { dvd currentRow = new dvd(); currentRow.dvdId = (int)rdr["dvdId"]; currentRow.title = rdr["title"].ToString(); currentRow.realeaseYear = (string)rdr["releaseYear"]; currentRow.director = rdr["Name"].ToString(); currentRow.rating = rdr["Rating"].ToString(); if (rdr["Notes"] != DBNull.Value) { currentRow.notes = rdr["Notes"].ToString(); } dvds = currentRow; } } } return(dvds); }
public List <dvd> GetAll() { List <dvd> dvds = new List <dvd>(); using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdLibrary"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "RetreivingAllDvds"; conn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { dvd currentRow = new dvd(); currentRow.dvdId = (int)rdr["dvdId"]; currentRow.title = rdr["title"].ToString(); currentRow.realeaseYear = (string)rdr["releaseYear"]; currentRow.director = rdr["Name"].ToString(); currentRow.rating = rdr["Rating"].ToString(); if (rdr["notes"] != DBNull.Value) { currentRow.notes = rdr["notes"].ToString(); } dvds.Add(currentRow); } } } return(dvds); }
public List <dvd> GetYear(string dvdYear) { List <dvd> dvds = new List <dvd>(); using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdLibrary"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = "RetreiveDvdByReleaseYear"; cmd.Parameters.AddWithValue("@ReleaseYear", dvdYear); conn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { dvd currentRow = new dvd(); currentRow.dvdId = (int)rdr["dvdId"]; currentRow.title = rdr["title"].ToString(); currentRow.realeaseYear = (string)rdr["releaseYear"]; currentRow.director = rdr["Name"].ToString(); currentRow.rating = rdr["Rating"].ToString(); dvds.Add(currentRow); } } } return(dvds); }
public ActionResult DeleteConfirmed(int id) { dvd dvd = db.dvd.Find(id); db.dvd.Remove(dvd); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Edit(dvd dvd) { var found = _dvds.FirstOrDefault(m => m.dvdId == dvd.dvdId); if (found != null) { found = dvd; } }
public ActionResult Edit([Bind(Include = "dvdId,dvdTitle,dvdDirector,genre")] dvd dvd) { if (ModelState.IsValid) { db.Entry(dvd).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dvd)); }
public ActionResult Create([Bind(Include = "dvdId,dvdTitle,dvdDirector,genre")] dvd dvd) { if (ModelState.IsValid) { db.dvd.Add(dvd); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(dvd)); }
// GET: dvd/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dvd dvd = db.dvd.Find(id); if (dvd == null) { return(HttpNotFound()); } return(View(dvd)); }
public IHttpActionResult Get(int dvdId) { dvd movie = _dvdRepository.Get(dvdId); //dvd movie = DvdRepoMock.Get(dvdId); if (movie == null) { return(NotFound()); } else { return(Ok(movie)); } }
// GET: Dvds/Edit/5 public ActionResult Edit(byte?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dvd dvd = db.dvd.Find(id); if (dvd == null) { return(HttpNotFound()); } ViewBag.cast_id = new SelectList(db.cast, "id", "first_name", dvd.cast_id); ViewBag.genres_id = new SelectList(db.Genres, "id", "genres1", dvd.genres_id); ViewBag.producer_id = new SelectList(db.producer, "id", "first_name", dvd.producer_id); ViewBag.studio_id = new SelectList(db.studio, "id", "name", dvd.studio_id); return(View(dvd)); }
public void Delete(int dvdid) { var repository = new DvdLibraryEF(); var DVD = repository.DVDs.Find(dvdid); if (DVD != null) { dvd deleted = new dvd { dvdId = DVD.dvdId, director = DVD.director.DirectorName, notes = DVD.notes, realeaseYear = DVD.realeaseYear, rating = DVD.rating.RatingName, title = DVD.title }; repository.DVDs.Remove(DVD); repository.SaveChanges(); } }
public dvd Get(int dvdid) { var repository = new DvdLibraryEF(); var DVD = repository.DVDs.Find(dvdid); dvd returnList = new dvd(); if (DVD != null) { returnList.dvdId = DVD.dvdId; returnList.director = DVD.director.DirectorName; returnList.notes = DVD.notes; returnList.realeaseYear = DVD.realeaseYear; returnList.rating = DVD.rating.RatingName; returnList.title = DVD.title; return(returnList); } else { return(null); } }
public ActionResult Edit([Bind(Include = "id,copy_number,title,released_date,genres_id,stock,date_added,studio_id,producer_id,cast_id,cover")] dvd dvd, HttpPostedFileBase cover) { if (ModelState.IsValid) { if (cover != null) { string pic = System.IO.Path.GetFileName(cover.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/media/dvdPoster"), pic); dvd.cover = cover.FileName; cover.SaveAs(path); } db.Entry(dvd).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.cast_id = new SelectList(db.cast, "id", "first_name", dvd.cast_id); ViewBag.genres_id = new SelectList(db.Genres, "id", "genres1", dvd.genres_id); ViewBag.producer_id = new SelectList(db.producer, "id", "first_name", dvd.producer_id); ViewBag.studio_id = new SelectList(db.studio, "id", "name", dvd.studio_id); return(View(dvd)); }
public void Edit(dvd dvd) { using (SqlConnection conn = new SqlConnection()) { conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdLibrary"].ConnectionString; SqlCommand cmd = new SqlCommand("UpdateDvd", conn); cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Title", dvd.title); cmd.Parameters.AddWithValue("@DirectorName", dvd.director); cmd.Parameters.AddWithValue("@Rating", dvd.rating); cmd.Parameters.AddWithValue("@ReleaseYear", dvd.realeaseYear); cmd.Parameters.AddWithValue("@Notes", dvd.notes); cmd.Parameters.AddWithValue("@DirectorID", SqlDbType.Int); cmd.Parameters.AddWithValue("@RatingID", SqlDbType.Int); cmd.Parameters.AddWithValue("@DvdID", dvd.dvdId); conn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.Read()) { dvd.dvdId = (int)rdr["dvdId"]; dvd.title = rdr["title"].ToString(); dvd.realeaseYear = (string)rdr["releaseYear"]; dvd.director = rdr["Name"].ToString(); dvd.rating = rdr["Rating"].ToString(); if (rdr["Notes"] != DBNull.Value) { dvd.notes = rdr["Notes"].ToString(); } } } } }
public void Add(dvd dvd) { using (SqlConnection conn = new SqlConnection()) { dvd dvds = new dvd(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["DvdLibrary"].ConnectionString; SqlCommand cmd = new SqlCommand("CreateNewDvd", conn); cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.StoredProcedure; conn.Open(); cmd.Parameters.AddWithValue("@Title", dvd.title); cmd.Parameters.AddWithValue("@DirectorName", dvd.director); cmd.Parameters.AddWithValue("@Rating", dvd.rating); cmd.Parameters.AddWithValue("@ReleaseYear", dvd.realeaseYear); cmd.Parameters.AddWithValue("@Notes", dvd.notes); cmd.Parameters.AddWithValue("@DirectorID", SqlDbType.Int); cmd.Parameters.AddWithValue("@RatingID", SqlDbType.Int); cmd.Parameters.AddWithValue("@DvdID", SqlDbType.Int); cmd.ExecuteNonQuery(); } }
public IHttpActionResult Edit(EditViewModel model) { dvd movie = _dvdRepository.Get(model.dvdId); if (ModelState.IsValid) { movie.dvdId = model.dvdId; movie.title = model.title; movie.rating = model.rating; movie.director = model.director; movie.realeaseYear = model.realeaseYear; _dvdRepository.Edit(movie); // DvdRepoMock.Edit(movie); return(Ok(movie)); } else { return(NotFound()); } // return Ok(DvdRepoMock.GetAll()); }
public void Add(dvd dvd) { var repository = new DvdLibraryEF(); var newDirector = repository.Directors.FirstOrDefault(d => d.DirectorName == dvd.director); if (newDirector == null) { newDirector = repository.Directors.Add(new DirectorEF { DirectorName = dvd.director }); repository.SaveChanges(); } var newRating = repository.Ratings.FirstOrDefault(d => d.RatingName == dvd.rating); if (newRating == null) { newRating = repository.Ratings.Add(new RatingEF { RatingName = dvd.rating }); repository.SaveChanges(); } var DVD = repository.DVDs.Add( new EF.dvdEF { dvdId = dvd.dvdId, director = newDirector, notes = dvd.notes, realeaseYear = dvd.realeaseYear, rating = newRating, title = dvd.title }); repository.SaveChanges(); }
public void Dvd() { lock (testLock) { // Copy resource file to the run-time directory GetInputFilePath("Actor.xsd", Resources.Actor); // Copy resource file to the run-time directory string inputFilePath = GetInputFilePath("Dvd.xsd", Resources.dvd); var generatorParams = GetGeneratorParams(inputFilePath); generatorParams.CollectionObjectType = CollectionType.List; generatorParams.TargetFramework = TargetFramework.Net35; generatorParams.EnableDataBinding = true; generatorParams.Miscellaneous.EnableSummaryComment = true; generatorParams.GenerateDataContracts = false; generatorParams.GenericBaseClass.Enabled = false; generatorParams.Serialization.GenerateXmlAttributes = true; generatorParams.TrackingChanges.Enabled = false; generatorParams.TrackingChanges.GenerateTrackingClasses = false; generatorParams.Serialization.EnableEncoding = false; generatorParams.Serialization.DefaultEncoder = DefaultEncoder.UTF8; var xsdGen = new GeneratorFacade(generatorParams); var result = xsdGen.Generate(); Assert.IsTrue(result.Success, result.Messages.ToString()); // Create new dvd collection and save it to file var dvd = new DvdCollection(); dvd.Dvds.Add(new dvd { Title = "Matrix יא?" }); var newitem = new dvd(); newitem.Actor.Add(new Actor { firstname = "Jamיs א&", nationality = "Us" }); dvd.Dvds.Add(newitem); var originalXml = dvd.Serialize(); var dvdFile = Path.Combine(OutputFolder, "dvd.xml"); dvd.SaveToFile(dvdFile); // Load data fom file and serialize it again. var loadedDvdCollection = DvdCollection.LoadFromFile(dvdFile); var finalXml = loadedDvdCollection.Serialize(); // Then comprate two xml string if (!originalXml.Equals(finalXml)) { Assert.Fail("Xml value are not equals"); } Exception exp; DvdCollection deserialiseDvd; var testEncodings = new [] { Encoding.ASCII, Encoding.UTF8, Encoding.Unicode, Encoding.UTF32 }; foreach (var encoding in testEncodings) { var encodedFile = Path.Combine(OutputFolder, "dvd" + encoding.EncodingName + ".xml"); dvd.SaveToFile(encodedFile, encoding); if (!DvdCollection.LoadFromFile(encodedFile, encoding, out deserialiseDvd, out exp)) { Assert.Fail("LoadFromFile failed on {0} encoding", encoding.EncodingName); } else if (!deserialiseDvd.Dvds[0].Title.Equals("Matrix יא?")) { Assert.Fail("LoadFromFile failed on {0} encoding", encoding.EncodingName); } } var compileResult = CompileCSFile(generatorParams.OutputFilePath); Assert.IsTrue(compileResult.Success, compileResult.Messages.ToString()); } }
public void Dvd() { lock (testLock) { // Copy resource file to the run-time directory GetInputFilePath("Actor.xsd", Resources.Actor); // Copy resource file to the run-time directory string inputFilePath = GetInputFilePath("Dvd.xsd", Resources.dvd); var generatorParams = GetGeneratorParams(inputFilePath); generatorParams.CollectionObjectType = CollectionType.List; generatorParams.TargetFramework = TargetFramework.Net35; generatorParams.EnableDataBinding = true; generatorParams.Miscellaneous.EnableSummaryComment = true; generatorParams.GenerateDataContracts = false; generatorParams.GenericBaseClass.Enabled = false; generatorParams.Serialization.GenerateXmlAttributes = true; generatorParams.TrackingChanges.Enabled = false; generatorParams.TrackingChanges.GenerateTrackingClasses = false; generatorParams.Serialization.EnableEncoding = false; generatorParams.Serialization.DefaultEncoder = DefaultEncoder.UTF8; //generatorParams.PropertyParams.AutomaticProperties = true; GenerateAndCompile(generatorParams); // Create new dvd collection and save it to file var dvd = new DvdCollection(); dvd.Dvds.Add(new dvd { Title = "Matrix יא?" }); var newitem = new dvd(); newitem.Actor.Add(new Actor { firstname = "Jamיs א&", nationality = "Us" }); dvd.Dvds.Add(newitem); var originalXml = dvd.Serialize(); var dataOutputFileName = GetOutputFullFileName("dvd.xml"); dvd.SaveToFile(dataOutputFileName); // Load data fom file and serialize it again. var loadedDvdCollection = DvdCollection.LoadFromFile(dataOutputFileName); var finalXml = loadedDvdCollection.Serialize(); // Then comprate two xml string if (!originalXml.Equals(finalXml)) { Assert.Fail("Xml value are not equals"); } Exception exp; foreach (var encoding in encodings) { DvdCollection deserialiseDvd; var dataEncodingOutputFileName = GetOutputFullFileName($"dvd{encoding.EncodingName}.xml"); dvd.SaveToFile(dataEncodingOutputFileName, encoding); if (!DvdCollection.LoadFromFile(dataEncodingOutputFileName, encoding, out deserialiseDvd, out exp)) { Assert.Fail($"LoadFromFile failed on {encoding.EncodingName} encoding "); } else { string title = /*(encoding == Encoding.ASCII) ? "Matrix ???" : */ "Matrix יא?"; if (!deserialiseDvd.Dvds[0].Title.Equals(title)) { Assert.Fail($"LoadFromFile failed on {encoding.EncodingName} encoding "); } } } } }
public ActionResult Create([Bind(Include = "id,date_out,num_copy,amount_paid,due,date_returned,penalty_charge,dvd_id,member_id,loan_status_id")] loan loan, dvd dvd) { if (ModelState.IsValid) { db.loan.Add(loan); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.dvd_id = new SelectList(db.dvd, "id", "title", loan.dvd_id); ViewBag.member_id = new SelectList(db.member, "id", "first_name", loan.member_id); ViewBag.loan_status_id = new SelectList(db.loan_status, "id", "loan_status", loan.loan_status_id); /* * db.Entry(dvd).State = EntityState.Modified; * var dv = db.dvd.Find(loan.dvd_id); * var result=dv.stock - loan.num_copy; * dvd dvd = new dvd() * { * * }; */ //db.SaveChanges(); return(View(loan)); }
public void Add(dvd dvd) { dvd.dvdId = _dvds.Max(m => m.dvdId) + 1; _dvds.Add(dvd); }