public ActionResult Update(PhotosPO photos)
        {
            //Defaults redirect to index of photos controller passing albumId.
            ActionResult oResult = RedirectToAction("Index", "Photos", new { albumId = photos.AlbumId });

            if (ModelState.IsValid)
            {
                try
                {
                    //Passing photo object and photo location to use in stored procedure.
                    dataAccess.UpdatePhoto(PhotosMapper.MapPoToDO(photos, photos.PhotoLocation));
                    TempData["Message"] = "Photo successfully updated.";
                }
                catch (Exception ex)
                {
                    //Logs exception using exceptionLog class.
                    exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "Update", ex.StackTrace);
                    oResult = View(new { albumId = photos.AlbumId });
                }
            }
            else
            {
                //returns the albumId to the view.
                oResult = View(new { albumId = photos.AlbumId });
            }

            return(oResult);
        }
        public ActionResult UploadPhoto(HttpPostedFileBase uploadedPhoto, PhotosPO photo)
        {
            //Defaults redirect to index of album controller.
            ActionResult oResult = RedirectToAction("Index", "Album");

            if (ModelState.IsValid)
            {
                try
                {
                    //Gets filepath
                    List <FileInfo> files = Directory.GetFiles("/").Select(path => new FileInfo(path)).ToList();

                    //Creates a unique id for naming save files to prevent overriding, saves file in
                    //userPhotos folder of current directory.
                    string newName      = Guid.NewGuid().ToString() + uploadedPhoto.FileName.Remove(0, uploadedPhoto.FileName.IndexOf('.'));
                    string pathToSaveTo = Path.Combine(Server.MapPath("/userPhotos/"), newName);

                    //Uploads photo to userPhotos folder in current directory.
                    uploadedPhoto.SaveAs(pathToSaveTo);
                    pathToSaveTo = $"~/userPhotos/{newName}";

                    //Adds photo to table using a stored procedure and properties gathered from user input.
                    dataAccess.CreatePhoto(PhotosMapper.MapPoToDO(photo, pathToSaveTo));

                    //Lets user know that upload was successful.
                    TempData["Message"] = "Photo upload successful.";
                }
                catch (Exception ex)
                {
                    //Logs exception using exceptionLog class.
                    exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "UploadPhoto", ex.StackTrace);
                    TempData["Error"] = "Oops there was a problem uploading your photo, please try again.";
                }
            }
            else
            {
                //Instanciating a new list of selectlistitem to fill dropdown.
                ViewBag.DropDown = new List <SelectListItem>();
                try
                {
                    //Stores Album name and Id in viewbag as a list to use for a dropdown list in view.
                    List <AlbumDO> dataObjects = albumData.ReadAlbum();
                    foreach (AlbumDO item in dataObjects)
                    {
                        ViewBag.DropDown.Add(new SelectListItem()
                        {
                            Text = item.AlbumName, Value = item.AlbumId.ToString()
                        });
                    }
                }
                catch (Exception e)
                {
                    //Logs exception using exceptionLog class.
                    exceptionLog.ExceptionLog("Critical", e.Message, "PhotosController", "UploadPhoto", e.StackTrace);
                }

                //Modelstate wasn't valid, returning photo to view.
                oResult = View(photo);
            }

            return(oResult);
        }