public ActionResult UpdateAlbum(int albumID) { ActionResult response = null; if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3) { try { AlbumPO useralbums = new AlbumPO(); useralbums = AlbumMapper.AlbumDOtoPO(_dataAccess.ReadAlbumByID(albumID)); useralbums.UserSelectList = FillUsersListDropDown(); response = View(useralbums); } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } } else { TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting."; response = RedirectToAction("Index", "Home"); } return(response); }
public ActionResult AddAlbum(AlbumPO form) { ActionResult response = null; if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3) { if (ModelState.IsValid) { try { _dataAccess.AddAlbum(AlbumMapper.AlbumPOtoDO(form)); response = RedirectToAction("ViewAlbums", "Albums"); } catch (Exception ex) { LogFile.DataFile(ex: ex); } finally { } } else { response = View(form); } } else { TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting."; response = RedirectToAction("Index", "Home"); } return(response); }
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 static AlbumBO AlbumPOtoBO(AlbumPO from) { AlbumBO to = new AlbumBO(); to.AlbumID = from.AlbumID; to.AlbumName = from.AlbumName; to.AlbumType = from.AlbumType; to.UserID = from.UserID; to.PhotoID = from.PhotoID; to.Photo = from.Photo; to.PhotoName = from.PhotoName; return(to); }
public static PhotosBO MapPoToBO(AlbumPO from) { PhotosBO to = new PhotosBO(); try { to.AlbumId = from.AlbumId; to.PhotoCount = from.PhotoCount; } catch (Exception e) { throw e; } return(to); }
public string[] UpdateCovers(Album album) { ObjectId albumObjectId; string[] covers = new string[] { }; if (ObjectId.TryParse(album.Id, out albumObjectId)) { var cursor = Database.GetCollection <PhotoPO>(Collections.Photos).FindAs <PhotoPO>(Query.EQ("AlbumId", albumObjectId)).SetLimit(3); covers = cursor.Select(x => x.ThumbURI).ToArray(); AlbumPO albumPO = album.ToAlbumPO(); albumPO.CoverURIs = covers; Database.GetCollection <AlbumPO>(Collections.Albums).Save(albumPO); } return(covers); }
public string SaveAlbum(Album album) { AlbumPO albumPO = album.ToAlbumPO(); if (albumPO.CoverURIs == null) { albumPO.CoverURIs = new string[] { } } ; if (string.IsNullOrEmpty(album.Id)) // Don't update this property if the entity is not new { albumPO.CreatedOn = DateTime.Now.ToUniversalTime(); } Database.GetCollection <AlbumPO>(Collections.Albums).Save(albumPO); return(albumPO.Id); }
public static AlbumDO MapPoToDO(AlbumPO from) { AlbumDO to = new AlbumDO(); try { to.AlbumId = from.AlbumId; to.UserId = from.UserId; to.AlbumName = from.AlbumName; to.AlbumDescription = from.AlbumDescription; } catch (Exception e) { throw e; } return(to); }
public ActionResult Update(long albumId) { AlbumPO mappedAlbum = new AlbumPO(); ViewBag.DropDown = new List <SelectListItem>(); //Defaults redirect to view. ActionResult oResponse = View(); if (ModelState.IsValid) { try { //List username and Id in the viewbag as to use for a dropdown list in view. List <UserDO> dataObjects = userData.ReadUsers(); mappedAlbum = AlbumMapper.MapDoToPO(dataAccess.ViewAlbumById(albumId)); 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() }); } //Returns mappedalbum to view. oResponse = View(mappedAlbum); } catch (Exception ex) { //Logs exception using exceptionLog class. exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Update", ex.StackTrace); //Sets redirect to index of album controller. oResponse = RedirectToAction("Index", "Album"); } } else { //Returns albumId to view. oResponse = View(albumId); } return(oResponse); }
/// <summary> /// Mapping a List from the Data Layer to the Presentation layer. /// </summary> /// <param name="from">List from the Data Layer</param> /// <returns></returns> public static List <AlbumPO> MapDoToPO(List <AlbumDO> from) { List <AlbumPO> to = new List <AlbumPO>(); try { foreach (AlbumDO item in from) { AlbumPO mappedItem = MapDoToPO(item); to.Add(mappedItem); } } catch (Exception e) { throw e; } return(to); }
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); }