public ActionResult Update(AlbumPO album) { //Defaulting redirect to index of album controller ActionResult OResponse = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Updates album in datatable using valid user input. dataAccess.UpdateAlbum(AlbumMapper.MapPoToDO(album)); TempData["Message"] = "Album successfully updated."; } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Update", ex.StackTrace); OResponse = View(album); } } else { //Returns album to view. OResponse = View(album); } return(OResponse); }
public ActionResult Create(AlbumPO album) { //Defaults redirect to index of album controller. ActionResult oResponse = RedirectToAction("Index", "Album"); if (ModelState.IsValid) { try { //Adds album to datatable using valid album. dataAccess.CreateAlbum(AlbumMapper.MapPoToDO(album)); TempData["Message"] = "Album successfully created."; } catch (Exception e) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", e.Message, "AlbumController", "Create", e.StackTrace); try { List <UserDO> dataObjects = userData.ReadUsers(); ViewBag.DropDown = new List <SelectListItem>(); foreach (UserDO user in dataObjects) { //Adds username and user Id to a dropdown list of users in viewbag. ViewBag.DropDown.Add(new SelectListItem() { Text = user.Username, Value = user.UserId.ToString() }); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Create", ex.StackTrace); } oResponse = View(album); } } else { //Modelstate was invalid. try { List <UserDO> dataObjects = userData.ReadUsers(); ViewBag.DropDown = new List <SelectListItem>(); foreach (UserDO user in dataObjects) { //Adds username and user Id to a dropdown list of users in viewbag. ViewBag.DropDown.Add(new SelectListItem() { Text = user.Username, Value = user.UserId.ToString() }); } } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Create", ex.StackTrace); } oResponse = View(album); } return(oResponse); }