public ActionResult EditArtist(DetailArtist model, HttpPostedFileBase file) { if (Url.RequestContext.RouteData.Values["id"] != null) { model.ArtistId = (int)Double.Parse(Url.RequestContext.RouteData.Values["id"].ToString()); } if (model.File != null) { var Photo_error = new Tuple <byte[], string>(null, null); // Photo_error = ArtistFunctions.VerifyPhoto(model.File); if (Photo_error.Item2 != null) { ModelState.AddModelError("", Photo_error.Item2); return(View()); } model.Photo = Photo_error.Item1; } DetailArtist NewModelfromDB = new DetailArtist(); NewModelfromDB = EditArtistDB.EditArtist(model); if (model != NewModelfromDB) { Cookies.RemoveCookie("BirthDate"); return(RedirectToAction("DetailsArtist", new { id = NewModelfromDB.ArtistId })); } return(View(NewModelfromDB)); }
// GET ARTIST DETAILS public ActionResult Detail(int id) { Debug.WriteLine(id); //Get the sql from the database, although we are getting only one result we need to specify we only one the first one the Sql Query bring back Artist Artist = db.Artists.SqlQuery("select * from artists where artistid= @id", new SqlParameter("@id", id)).FirstOrDefault(); if (Artist == null) { return(HttpNotFound()); } //find data about all songs the artist has string aside_query = "select * from Songs inner join ArtistSongs on Songs.SongID = ArtistSongs.Song_SongID where ArtistSongs.Artist_ArtistID=@id"; Debug.WriteLine(aside_query); //List of all the songs var fk_parameter = new SqlParameter("@id", id); List <Song> songsbyartist = db.Songs.SqlQuery(aside_query, fk_parameter).ToList(); DetailArtist viewmodel = new DetailArtist(); viewmodel.artist = Artist; viewmodel.songs = songsbyartist; return(View(viewmodel)); }
public static string SingleNamesFromId(string ArtistId) { string sql = @"select Firstname, Lastname from dbo.Artist where ArtistId = " + ArtistId + ";"; DetailArtist Single = new DetailArtist(); Single = DataAccess.LoadData <DetailArtist>(sql).First(); return(Single.Firstname + " " + Single.Lastname); }
public static DetailArtist EditArtist(DetailArtist NewModel) { DetailArtist OldModel = DetailArtistDB.DetailFromId(NewModel.ArtistId); string sql = ArtistFunctions.ModifyArtistSring(NewModel, OldModel); DataAccess.SaveData(sql, NewModel); DetailArtist NewModelfromDB = new DetailArtist(); NewModelfromDB = DetailArtistDB.DetailFromId(OldModel.ArtistId); return(NewModelfromDB); }
public static string ModifyArtistSring(DetailArtist NewModel, DetailArtist Oldmodel) { int Numberofchange = 0; string sql = @"UPDATE dbo.Artist Set "; if (NewModel.Firstname != null) { if (NewModel.Firstname != Oldmodel.Firstname) { sql += "Firstname = @Firstname, "; Numberofchange++; } } if (NewModel.Lastname != Oldmodel.Lastname) { sql += "Lastname = @Lastname, "; Numberofchange++; } if (NewModel.Birthdate != null) { if (NewModel.Birthdate != Oldmodel.Birthdate) { sql += "Birthdate = @Birthdate, "; Numberofchange++; } } if (NewModel.AdditionalInfo != Oldmodel.AdditionalInfo) { sql += "AdditionalInfo = @AdditionalInfo, "; Numberofchange++; } if (NewModel.Photo != Oldmodel.Photo) { sql += "Photo = @Photo, "; Numberofchange++; } sql = sql.Remove(sql.Length - 2, 2); sql += " Where ArtistId = @ArtistId; "; if (Numberofchange != 0) { return(sql); } else { return(null); } }
public ActionResult EditArtist() { if (Url.RequestContext.RouteData.Values["id"] != null) { int ArtistId = (int)Double.Parse(Url.RequestContext.RouteData.Values["id"].ToString()); DetailArtist model = DetailArtistDB.DetailFromId(ArtistId); Cookies.CreateDay(model.Birthdate); Cookies.Today(); return(View(model)); } else { return(RedirectToAction("ListArtist")); } }
// GET: Artysta/Details/5 public ActionResult DetailsArtist(DetailArtist model) { if (Url.RequestContext.RouteData.Values["id"] != null) { int ArtistId = (int)Double.Parse(Url.RequestContext.RouteData.Values["id"].ToString()); model = DetailArtistDB.DetailFromId(ArtistId); } else { return(RedirectToAction("ListArtist")); } var dupa = model.Birthdate.ToString(); var ad = dupa; /* * Po create * "31.12.2020 00:00:00 +01:00" * */ return(View(model)); }