public ActionResult Create(Role role) { if (ModelState.IsValid) { db.Roles.Add(role); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.Role_GenreId = new SelectList(db.Genres, "Genre_Id", "Genre_Name", role.Role_GenreId); ViewBag.Role_PieceId = new SelectList(db.Pieces, "Piece_Id", "Piece_Name", role.Role_PieceId); ViewBag.Role_TypeId = new SelectList(db.Types, "Type_Id", "Type_Name", role.Role_TypeId); return View(role); }
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 EditRole(Role role) { if (ModelState.IsValid) { db.Entry(role).State = EntityState.Modified; db.SaveChanges(); ViewBag.Role_GenreId = new SelectList(db.Genres, "Genre_Id", "Genre_Name", role.Role_GenreId); ViewBag.Role_PieceId = new SelectList(db.Pieces, "Piece_Id", "Piece_Name", role.Role_PieceId); ViewBag.Role_TypeId = new SelectList(db.Types, "Type_Id", "Type_Name", role.Role_TypeId); return PartialView("DetailsRole", role); } else { return Content("Please review your form"); } }
public ActionResult NewRole(Role Role) { if (ModelState.IsValid) { db.Roles.Add(Role); db.SaveChanges(); ViewBag.Type = db.Types.Find(Role.Role_TypeId); return PartialView("DetailsRole", Role); } else { return Content("Please review your form"); } }
public ActionResult NewRole(int PieceId) { Piece Piece = db.Pieces.Single(p => p.Piece_Id == PieceId); ViewBag.PieceId = PieceId; ViewBag.Role_TypeId = new SelectList( db.Types .OrderBy(r => r.Type_Name), "Type_Id", "Type_Name"); Role role = new Role(); role.Role_PieceId = PieceId; role.Role_Rank = db.Roles.Where(r => r.Role_PieceId == PieceId).Select(r => r.Role_Rank).Max() + 1; return PartialView("NewRole", role); }
public ActionResult EditRole(Role Role) { if (ModelState.IsValid) { db.Entry(Role).State = EntityState.Modified; db.SaveChanges(); ViewBag.Type = db.Types.FirstOrDefault(v => v.Type_Id == Role.Role_TypeId); return PartialView("DetailsRole", Role); } else { return Content("Please review your form"); } }