public async Task <IActionResult> Edit(int id, [Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD) { if (id != musicCD.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(musicCD); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicCDExists(musicCD.ProductId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(musicCD)); }
public async Task <IActionResult> Edit(int id, [Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD) { if (id != musicCD.ProductId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(musicCD); _context.Entry <MusicCD>(musicCD).Property(x => x.CreatedDate).IsModified = false; await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MusicCDExists(musicCD.ProductId)) { return(NotFound()); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } return(RedirectToAction(nameof(Index))); } return(View(musicCD)); }
protected void Page_Load(object sender, EventArgs e) { MusicCD myCD = new MusicCD("The Beatles", "Revolver (Remastered)", 128.00M, 2009); myCD.Label = "EMI"; myCD.ImageURL = "images/revolver.jpg"; ltrProductInfo.Text += myCD.GetHTML(); }
public ActionResult Show(int artistId, int musicCDId) { MusicCD musicCD = MusicCD.Find(musicCDId); Dictionary <string, object> model = new Dictionary <string, object>(); Artist artist = Artist.Find(artistId); model.Add("musicCD", musicCD); model.Add("artist", artist); return(View(model)); }
static repository() { TimeSpan time = new TimeSpan(5, 15, 15); DateTime randomDate = new DateTime(2019, 12, 31); MusicCD John = new MusicCD("System of a down", "Mezmerize", 15, 123); John.AddTrack("Question", "Daron Malakian", time); John.AddTrack("B.Y.O.B.", "Daron Malakian", time); John.AddTrack("Violent Pornography", "Daron Malakian", time); John.AddTrack("Lost in Hollywood", "Daron Malakian", time); Book OnTheRoad = new Book("Jack Kerouac", "On The Road", 15M, 1957); Book BladeRunner = new Book("Philip K. Dick", "Do Androids Dream Of Electric Sheep", 15M, 1968); Movie Annihilation = new Movie("Annihilation", 20, "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcS1RJJUBGRZFEzfSmdG4biDlXDAhsrpvgwLWkO-wSIfyePuZJAj", "Alex Garland"); John.ImageURL = "https://i.pinimg.com/originals/81/6a/8f/816a8f315b46181231d4f42524322a5f.jpg"; OnTheRoad.ImageURL = "https://i.pinimg.com/originals/92/b6/c0/92b6c06203fedad753fdebefa2c62624.jpg"; BladeRunner.ImageURL = "https://pictures.abebooks.com/BIBLIOSOPHER/22778546150.jpg"; Products.Add(John); Products.Add(OnTheRoad); Products.Add(BladeRunner); Products.Add(Annihilation); Customer Neo = new Customer(1, "Neo", "The One", "Chicago", "0000", "Zion"); Customer Shephard = new Customer(2, "John", "Sephard", "Mindoir", "999999", "N7"); OrderId newMusic = new OrderId(John, 22); OrderId newBook = new OrderId(OnTheRoad, 4); OrderId newBookTwo = new OrderId(BladeRunner, 6); OrderId newMovie = new OrderId(Annihilation, 2); OrderId otherBook = new OrderId(BladeRunner, 1); OrderId otherMovie = new OrderId(Annihilation, 4); Invoice newInvoice = new Invoice(1, randomDate, Neo); newInvoice.AddOrderItem(newMusic.Product, newMusic.Quantity); newInvoice.AddOrderItem(newBook.Product, newBook.Quantity); newInvoice.AddOrderItem(newBookTwo.Product, newBookTwo.Quantity); newInvoice.AddOrderItem(newMovie.Product, newMovie.Quantity); Invoice otherInvoice = new Invoice(2, randomDate, Shephard); otherInvoice.AddOrderItem(otherBook.Product, otherBook.Quantity); otherInvoice.AddOrderItem(otherMovie.Product, otherMovie.Quantity); Invoices.Add(newInvoice); Invoices.Add(otherInvoice); }
public async Task <IActionResult> Create([Bind("Artist,Label,Released,ProductId,Title,Price,ImageUrl,Category")] MusicCD musicCD) { if (ModelState.IsValid) { _context.Add(musicCD); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(musicCD)); }
public void GetTitle_ReturnsTitle_String() { //Arrange string title = "Walk the dog."; MusicCD newMusicCD = new MusicCD(title); //Act string result = newMusicCD.GetTitle(); //Assert Assert.AreEqual(title, result); }
public void GetAll_ReturnsEmptyList_MusicCDList() { //Arrange List <MusicCD> newList = new List <MusicCD> { }; //Act List <MusicCD> result = MusicCD.GetAll(); //Assert CollectionAssert.AreEqual(newList, result); }
public ActionResult Delete(int id) { try { MusicCD musicCD = repo.GetItem(id); } catch (DataException) { return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
public void GetId_MusicCDsInstantiateWithAnIdAndGetterReturns_Int() { //Arrange string title = "Walk the dog."; MusicCD newMusicCD = new MusicCD(title); //Act int result = newMusicCD.GetId(); //Assert Assert.AreEqual(1, result); }
public ActionResult Create(int artistId, string albumName) { Dictionary <string, object> model = new Dictionary <string, object>(); Artist foundArtist = Artist.Find(artistId); MusicCD newMusicCD = new MusicCD(albumName); foundArtist.AddCD(newMusicCD); List <MusicCD> allArtists = foundArtist.GetMusicCD(); model.Add("musicCD", allArtists); model.Add("artist", foundArtist); return(View("Show", model)); }
public ActionResult Delete(int id) { try { MusicCD musicCD = db.MusicCDs.Find(id); db.MusicCDs.Remove(musicCD); db.SaveChanges(); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
// GET: Admin/Music/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MusicCD musicCD = repo.GetById((int)id); if (musicCD == null) { return(HttpNotFound()); } return(View(musicCD)); }
// GET: Admin/MusicCDs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MusicCD musicCD = db.MusicCDs.Find(id); if (musicCD == null) { return(HttpNotFound()); } return(View(musicCD)); }
public void Find_ReturnsCorrectMusicCD_MusicCD() { //Arrange string title01 = "Walk the dog"; string title02 = "Wash the dishes"; MusicCD newMusicCD1 = new MusicCD(title01); MusicCD newMusicCD2 = new MusicCD(title02); //Act MusicCD result = MusicCD.Find(2); //Assert Assert.AreEqual(newMusicCD2, result); }
static Repository() { Book b1 = new Book("Georg Martin", "With a Little Help from My Friends: The Making of Sgt. Pepper", 19.95M, 1995); Book b2 = new Book("Mr Smith", "Californication", 59.95M, 2001); Book b3 = new Book("Magnus", "The life rules", 39.95M, 2013); b1.ISBN = "978-3-16-148410-0"; b2.ISBN = "456-3-16-148410-0"; b3.ISBN = "678-3-16-148410-0"; Products.Add(b1); Products.Add(b2); Products.Add(b3); Products.Add(new Movie("Run in 60", 60.50M, "https://picsum.photos/200/300", "Steven")); Products.Add(new Movie("The Street", 154.50M, "https://picsum.photos/200/300", "Mozart")); Products.Add(new Movie("Forrest Gump", 99.50M, "https://picsum.photos/200/300", "Someone elese")); MusicCD cd1 = new MusicCD("Taylor Swift", "The Man", 6.95M, 2019); cd1.Label = "CG Records"; cd1.AddTrack(new Track("The candle", new TimeSpan(0, 3, 35))); cd1.AddTrack(new Track("The avocado", new TimeSpan(0, 2, 25))); cd1.AddTrack(new Track("With tuna", new TimeSpan(0, 5, 25))); MusicCD cd2 = new MusicCD("Lady Gaga", "The wrecking ball", 6.95M, 2019); cd2.Label = "Universal Music Group"; cd2.AddTrack(new Track("Lights goes off", new TimeSpan(0, 1, 35))); cd2.AddTrack(new Track("OnePlus", new TimeSpan(0, 2, 35))); cd2.AddTrack(new Track("Cucumber", new TimeSpan(0, 4, 25))); Products.Add(cd1); Products.Add(cd2); Customer c1 = new Customer(11, "Mohamed", "Jensen", "Kilen 62", "9510", "Arden"); Customer c2 = new Customer(22, "Laurits", "Petersen", "Ribelandevej 50", "6372", "Bylderup-Bov"); Customer c3 = new Customer(33, "Mads", "Madsen", "Nyhavn 59", "2880", "Bagsværd "); Customer c4 = new Customer(44, "Cecilie S.", "Bruun", "Gammel Byvej 93", "4681", "Herfølge"); Invoice i1 = new Invoice(1, new DateTime(), c1); Invoice i2 = new Invoice(2, new DateTime(), c2); Invoice i3 = new Invoice(3, new DateTime(), c3); Invoice i4 = new Invoice(4, new DateTime(), c4); i1.AddOrderItem(Products[2], 1).AddOrderItem(Products[0], 1); i2.AddOrderItem(Products[3], 1).AddOrderItem(Products[4], 1); Invoices.Add(i1); Invoices.Add(i2); Invoices.Add(i3); Invoices.Add(i4); }
public void SetTitle_SetTitle_String() { //Arrange string title = "Walk the dog."; MusicCD newMusicCD = new MusicCD(title); //Act string updatedTitle = "Do the dishes"; newMusicCD.SetTitle(updatedTitle); string result = newMusicCD.GetTitle(); //Assert Assert.AreEqual(updatedTitle, result); }
public ActionResult Edit([Bind(Include = "ProductId,Title,Price,ImageUrl,Category,Artist,Label,Released")] MusicCD musicCD) { try { if (ModelState.IsValid) { repo.SaveItem(musicCD); return(RedirectToAction("Index")); } } catch (DataException) { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(musicCD)); }
public void GetAll_ReturnsMusicCDs_MusicCDList() { //Arrange string title01 = "Walk the dog"; string title02 = "Wash the dishes"; MusicCD newMusicCD1 = new MusicCD(title01); MusicCD newMusicCD2 = new MusicCD(title02); List <MusicCD> newList = new List <MusicCD> { newMusicCD1, newMusicCD2 }; //Act List <MusicCD> result = MusicCD.GetAll(); //Assert CollectionAssert.AreEqual(newList, result); }
private void OnPanelClick(object sender, EventArgs e) { string[] name = ((Button)sender).Name.Split('-'); if (int.Parse(name[1]) != lastbutton) { MusicCD musicCD = MusicCD.CreateFromID(int.Parse(name[1])); item.Product = musicCD; item.Quantity = 1; lblName.Text = musicCD.Name; lblIssue.Text = musicCD.Issue; lblSinger.Text = musicCD.Singer; lblType.Text = musicCD.Type; lblQty.Text = item.Quantity.ToString(); lblPrice.Text = "€" + (item.Quantity * item.Product.Price).ToString("0.00"); } lastbutton = int.Parse(name[1]); }
public ActionResult Create([Bind(Include = "Title, Price, ImageUrl, Category, Artist, Label, Released")] MusicCD musicCD) { try { if (ModelState.IsValid) { repo.SaveItem(musicCD); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { // Log the error (uncomment dex variable name and add a line here to write a log.) ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(musicCD)); }
public ActionResult Delete(int id) { try { MusicCD musicCD = repo.DeleteItem((int)id); //db.MusicCDs.Remove(musicCD); // Alternative to the lines above. A performance improvement //MusicCD MusicCDToDelete = new MusicCD() { ProductId = id }; //db.Entry(MusicCDToDelete).State = EntityState.Deleted; //db.SaveChanges(); } catch (DataException /* dex */) { // Log the error (uncomment dex variable name and add a line here to write a log.) return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ProductId,Title,Price,ImageUrl,Category,Artist,Label,Released")] MusicCD musicCD) { try { if (ModelState.IsValid) { db.Entry(musicCD).State = EntityState.Modified; db.Entry(musicCD).Property(c => c.CreatedDate).IsModified = false; db.SaveChanges(); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, " + "and if the problem persists see your system administrator."); } return(View(musicCD)); }
public async Task <IActionResult> Create([Bind("Artist,Label,Released,Title,Price,ImageUrl,Category")] MusicCD musicCD) { try { if (ModelState.IsValid) { _context.Add(musicCD); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } return(View(musicCD)); }
// GET: Admin/MusicCDs/Delete/5 public ActionResult Delete(int?id, bool?saveChangesError = false) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (saveChangesError.GetValueOrDefault()) { ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator."; } MusicCD musicCD = db.MusicCDs.Find(id); if (musicCD == null) { return(HttpNotFound()); } return(View(musicCD)); }
public static HtmlString TracksList(this HtmlHelper helper, MusicCD cd) { StringBuilder sb = new StringBuilder(); sb.Append("<div>"); sb.Append("<strong> Tracks:</strong>"); sb.Append("<ol>"); foreach (Track track in @cd.Tracks) { sb.Append("<li>" + track.Title + " (" + track.Composer + ") "); sb.Append(track.Length.Minutes + ": " + track.Length.Seconds + "</li>"); } sb.Append("</ol>"); sb.Append("<p><strong>Total playing time</strong>: " + cd.GetPlayingTime().Minutes + ": " + cd.GetPlayingTime().Seconds + "</p>"); sb.Append("</div>"); return(new HtmlString(sb.ToString())); }
public ActionResult Delete(int id) { try { //MusicCD musicCD = db.MusicCDs.Find(id); //db.MusicCDs.Remove(musicCD); MusicCD MusicCDToDelete = new MusicCD() { ProductId = id }; db.Entry(MusicCDToDelete).State = EntityState.Deleted; db.SaveChanges(); } catch (DataException /* dex */) { //Log the error (uncomment dex variable name and add a line here to write a log. return(RedirectToAction("Delete", new { id = id, saveChangesError = true })); } return(RedirectToAction("Index")); }
public IActionResult Index() { List <Book> books = new List <Book>(); Book b1 = new Book("Stanley Kubrick", "The Shining", 150, 28 - 1 - 1977, "/Images/shining.jfif"); Book b2 = new Book("Gud", "Biblen", 250, 0 - 0 - 0, "/Images/bible.jfif"); books.Add(b1); books.Add(b2); List <MusicCD> musiclist = new List <MusicCD>(); var Beatles = new MusicCD("Beatles", "Abbey Road", 125, 26 - 9 - 1969, "/Images/abbey.jfif"); Beatles.AddTracks(new Track("Come together", "John Lennon", new TimeSpan(0, 7, 30))); Beatles.AddTracks(new Track("Something", "John Lennon", new TimeSpan(0, 5, 34))); Beatles.AddTracks(new Track("Maxwell's Silver Hammer", "Paul Mccartney", new TimeSpan(0, 5, 34))); Beatles.AddTracks(new Track("Oh! Darling", "", new TimeSpan(0, 3, 20))); Beatles.AddTracks(new Track("Octopus's Darling", "John Lennon", new TimeSpan(0, 2, 10))); var Veto = new MusicCD("VETO", "There's a Beat in All Machines", 190, 27 - 2 - 2006, "/Images/veto.jfif"); Veto.AddTracks(new Track("Can you see anything", "Troels Abrahamsen", new TimeSpan(0, 3, 42))); Veto.AddTracks(new Track("We are not friends", "Troels Abrahamsen", new TimeSpan(0, 4, 12))); Veto.AddTracks(new Track("You Are a Knife", "VETO", new TimeSpan(0, 3, 32))); musiclist.Add(Beatles); musiclist.Add(Veto); ViewBag.musiclist = musiclist; ViewBag.books = books; ViewBag.Products = repository.Products; return(View()); }
public void MusicCDConstructor_CreatesInstanceOfMusicCD_MusicCD() { MusicCD newMusicCD = new MusicCD("test"); Assert.AreEqual(typeof(MusicCD), newMusicCD.GetType()); }
protected void Page_Load(object sender, EventArgs e) { MusicCD myCD = new MusicCD("The Beatles", "Revolver (Remastered)", 128.00M, 2009); myCD.Label = "EMI"; myCD.ImageURL = "images/revolver.jpg"; Track track01 = new Track("Taxman", "2:28"); track01.Composer = "Harrison"; myCD.AddTrack(track01); Track track02 = new Track("Eleanor Rigby", "2:06"); track02.Composer = "Lennon, McCartney"; myCD.AddTrack(track02); Track track03 = new Track("I'm Only Sleeping", "3:00"); track03.Composer = "Lennon, McCartney"; myCD.AddTrack(track03); Track track04 = new Track("Love You To", "2:59"); track04.Composer = "Harrison"; myCD.AddTrack(track04); Track track05 = new Track("Here, There And Everywhere", "2:23"); track05.Composer = "Harrison"; myCD.AddTrack(track05); Track track06 = new Track("Yellow Submarine", "2:38"); track06.Composer = "Lennon, McCartney"; myCD.AddTrack(track06); Track track07 = new Track("She Said She Said", "2:36"); track07.Composer = "Lennon, McCartney"; myCD.AddTrack(track07); Track track08 = new Track("Good Day Sunshine", "2:09"); track08.Composer = "Lennon, McCartney"; myCD.AddTrack(track08); Track track09 = new Track("And Your Bird Can Sing", "2:00"); track09.Composer = "Lennon, McCartney"; myCD.AddTrack(track09); Track track10 = new Track("For No One", "1:59"); track10.Composer = "Lennon, McCartney"; myCD.AddTrack(track10); Track track11 = new Track("Doctor Robert", "1:14"); track11.Composer = "Lennon, McCartney"; myCD.AddTrack(track11); Track track12 = new Track("I Want To Tell You", "2:27"); track12.Composer = "Harrison"; myCD.AddTrack(track12); Track track13 = new Track("Got To Get You Into My Life", "2:29"); track13.Composer = "Lennon, McCartney"; myCD.AddTrack(track13); Track track14 = new Track("Tomorrow Newer Knows", "3:01"); track14.Composer = "Lennon, McCartney"; myCD.AddTrack(track14); ltrProductInfo.Text += myCD.GetHTML(); ltrProductInfo.Text += "<p><strong>Total playing time: </strong>" + myCD.GetPlayingTime() + "</p>"; }
public void Dispose() { MusicCD.ClearAll(); }