public ActionResult Create(Artist artist) { if (ModelState.IsValid) { db.Artists.Add(artist); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.Artist_AgentId = new SelectList(db.Agents.OrderBy(a => a.Agent_Name), "Agent_Id", "Agent_Name", artist.Artist_AgentId); ViewBag.Artist_CountryId = new SelectList(db.CountryRegions.OrderBy(c => c.CountryRegion_Name), "CountryRegion_Id", "CountryRegion_Name", artist.Artist_CountryId); ViewBag.Artist_StateProvinceId = new SelectList(db.StateProvinces.OrderBy(s => s.StateProvince_Name), "StateProvince_Id", "StateProvince_Name", artist.Artist_StateProvinceId); ViewBag.Artist_TypeId = new SelectList(db.Types.OrderBy(t => t.Type_Name), "Type_Id", "Type_Name", artist.Artist_TypeId); return View(artist); }
public ActionResult EditPerformanceArtist(PerformanceArtist performanceArtist, string OtherRole, string PerformanceArtist_ArtistFullName) { if (ModelState.IsValid) { // Role if (OtherRole != null && OtherRole.Length > 0) { //Check the Role Role role = db.Roles.FirstOrDefault(r => r.Role_Id == performanceArtist.PerformanceArtist_RoleId); if (role.Role_Name == "Other") { // Create a new Role // remove any unnecessary spaces OtherRole = OtherRole.Replace(" ", " ").Trim(); Role newRole = new Role(); newRole.Role_Name = OtherRole; Performance performance = db.Performances.FirstOrDefault(p => p.Performance_Id == performanceArtist.PerformanceArtist_PerformanceId); newRole.Role_PieceId = performance.Performance_PieceId; newRole.Role_Rank = db.Roles.Where(r => r.Role_PieceId == performance.Performance_PieceId).Select(r => r.Role_Rank).Max() + 1; db.Roles.Add(newRole); performanceArtist.PerformanceArtist_RoleId = newRole.Role_Id; } } // Artist Artist artist = db.Artists.FirstOrDefault(a => string.Concat(a.Artist_FirstName, " ", a.Artist_LastName).Equals(PerformanceArtist_ArtistFullName)); if (artist != null) { //attach the artist performanceArtist.PerformanceArtist_ArtistId = artist.Artist_Id; } else { //create a new artist // remove any unnecessary spaces PerformanceArtist_ArtistFullName = PerformanceArtist_ArtistFullName.Replace(" ", " ").Trim(); string firstName = ""; string lastName; // find the position of the last space int i = PerformanceArtist_ArtistFullName.LastIndexOf(" "); if (i > 0) { //there are two words or more firstName = PerformanceArtist_ArtistFullName.Substring(0, i).Trim(); lastName = PerformanceArtist_ArtistFullName.Substring(i, PerformanceArtist_ArtistFullName.Length - i).Trim(); } else { //there's only one word lastName = PerformanceArtist_ArtistFullName; } Artist newArtist = new Artist(); newArtist.Artist_FirstName = firstName; newArtist.Artist_LastName = lastName; db.Artists.Add(newArtist); performanceArtist.PerformanceArtist_ArtistId = newArtist.Artist_Id; } db.Entry(performanceArtist).State = EntityState.Modified; db.SaveChanges(); ViewBag.artist = db.Artists.Find(performanceArtist.PerformanceArtist_ArtistId); ViewBag.role = db.Roles.Find(performanceArtist.PerformanceArtist_RoleId); // Can the current user edit this event? ViewBag.UserCanEditEvent = true; return PartialView("DetailsPerformanceArtist", performanceArtist); } else { return Content("Please review your form"); } }
public ActionResult NewPieceArtist(PieceArtist PieceArtist, string PieceArtist_ArtistFullName) { if (ModelState.IsValid) { Artist artist = db.Artists.FirstOrDefault(a => string.Concat(a.Artist_FirstName, " ", a.Artist_LastName).Equals(PieceArtist_ArtistFullName)); if (artist != null) { //attach the artist PieceArtist.PieceArtist_ArtistId = artist.Artist_Id; } else { //create a new artist // remove any unnecessary spaces PieceArtist_ArtistFullName.Replace(" ", " ").Trim(); string firstName = ""; string lastName; // find the position of the last space int i = PieceArtist_ArtistFullName.LastIndexOf(" "); if (i > 0) { //there are two words or more firstName = PieceArtist_ArtistFullName.Substring(0, i); lastName = PieceArtist_ArtistFullName.Substring(i, PieceArtist_ArtistFullName.Length - i); } else { //there's only one word lastName = PieceArtist_ArtistFullName; } Artist newArtist = new Artist(); newArtist.Artist_FirstName = firstName; newArtist.Artist_LastName = lastName; db.Artists.Add(newArtist); PieceArtist.PieceArtist_ArtistId = newArtist.Artist_Id; } db.PieceArtists.Add(PieceArtist); db.SaveChanges(); ViewBag.artist = db.Artists.Find(PieceArtist.PieceArtist_ArtistId); ViewBag.pieceArtistType = db.PieceArtistTypes.Find(PieceArtist.PieceArtist_PieceArtistTypeId); return PartialView("DetailsPieceArtist", PieceArtist); } else { return Content("Please review your form"); } }
public ActionResult ThisIsMe(Artist artist) { if (ModelState.IsValid) { db.Entry(artist).State = EntityState.Modified; db.SaveChanges(); ViewBag.Type = db.Types.FirstOrDefault(t => t.Type_Id == artist.Artist_TypeId); ViewBag.Agent = db.Agents.FirstOrDefault(a => a.Agent_Id == artist.Artist_AgentId); ViewBag.CountryRegion = db.CountryRegions.FirstOrDefault(c => c.CountryRegion_Id == artist.Artist_CountryId); ViewBag.StateProvince = db.StateProvinces.FirstOrDefault(c => c.StateProvince_Id == artist.Artist_StateProvinceId); ViewBag.AmITheArtist = true; return PartialView("DetailsArtist", artist); } else { return Content("Please review your form"); } }
public ActionResult EditArtist(Artist artist) { if (ModelState.IsValid) { db.Entry(artist).State = EntityState.Modified; db.SaveChanges(); ViewBag.Type = db.Types.FirstOrDefault(t => t.Type_Id == artist.Artist_TypeId); ViewBag.Agent = db.Agents.FirstOrDefault(a => a.Agent_Id == artist.Artist_AgentId); ViewBag.CountryRegion = db.CountryRegions.FirstOrDefault(c => c.CountryRegion_Id == artist.Artist_CountryId); ViewBag.StateProvince = db.StateProvinces.FirstOrDefault(c => c.StateProvince_Id == artist.Artist_StateProvinceId); // Am I the artist? ViewBag.AmITheArtist = false; if (Request.IsAuthenticated && artist.Artist_UserId == (int)Session["UserID"]) { ViewBag.AmITheArtist = true; } // Could I be the artist? ViewBag.CouldIBeTheArtist = false; if (Request.IsAuthenticated && artist.Artist_UserId == null) { ViewBag.CouldIBeTheArtist = true; } return PartialView("DetailsArtist", artist); } else { return Content("Please review your form"); } }