/// <summary> /// Creates and stores the artist submitted to the site /// </summary> /// <returns></returns> public ActionResult CreateArtist(ArtistViewModel iViewModel) { ActionResult oResponse = null; // Ensures the user is authenticated and is an Admin/SuperUser for creating an artist if (Session["Email"] != null && (int)Session["Role"] >= 4) { if (ModelState.IsValid) { try { // Maps Artist properties from Presentation Objects to Data Objects for creation IArtistDO lArtistForm = ArtistMapper.MapArtistPOtoDO(iViewModel.Artist); // Passes lArtistForm to the AddArtist method artistDA.AddArtist(lArtistForm); oResponse = RedirectToAction("ViewAllArtists", "Artist"); } catch (Exception ex) { using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "We apologize, but are unable to handle request at this time.."; // Map data to populate form drop down //PopulateDropDownLists(iViewModel); oResponse = View(iViewModel); } } else { oResponse = View(iViewModel); } } else { // User doesn't have access redirect to home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }
/// <summary> /// Will modify the changes made to a given artist based off of their Artist ID /// </summary> /// <returns></returns> public ActionResult UpdateArtist(ArtistViewModel iViewModel) { ActionResult oResponse = null; // Ensures the user is Authenticated and is an Admin/SuperUser for Updating an Artist if (Session["Email"] != null && (int)Session["Role"] >= 4) { if (ModelState.IsValid) { try { // Maps Artist from Presenation Object to Data Object IArtistDO lArtistForm = ArtistMapper.MapArtistPOtoDO(iViewModel.Artist); // Passes lArtistForm properties to map From Presentation Objects to Data Objects for Update submission artistDA.UpdateArtistInformation(lArtistForm); oResponse = RedirectToAction("ViewAllArtists", "Artist"); } catch (Exception ex) { using (StreamWriter fileWriter = new StreamWriter(@"C:\Course Content\ForgetTheMilk\RockersUnite\Logger\Log.txt")) { fileWriter.WriteLine("{0}-{1}", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), ex.Message, true); } iViewModel.ErrorMessage = "Sorry, something went wrong. Please try again."; // Mapp all data to appropriate types to populate drop down //PopulateDropDownLists(iViewModel); oResponse = View(iViewModel); } } else { oResponse = View(iViewModel); } } else { // User doesn't have privileges to Update an Artist, redirect to home oResponse = RedirectToAction("Index", "Home"); } return(oResponse); }