示例#1
0
        public ActionResult Index()
        {
            List <AlbumPO> mappedItems = new List <AlbumPO>();

            try
            {
                //Business Logic
                BusinessLogic   countPhotos = new BusinessLogic();
                List <PhotosBO> fromBL      = countPhotos.CountPhotosInAlbum(allPhotos.ReadPhotosForCount());

                ViewBag.PhotoCount = new List <PhotosBO>();
                foreach (PhotosBO item in fromBL)
                {
                    ViewBag.PhotoCount.Add(new PhotosBO()
                    {
                        AlbumId = item.AlbumId, PhotoCount = item.PhotoCount
                    });
                }


                if ((long)Session["RoleId"] <= 2)
                {
                    //User is an Admin. Viewing all albums
                    List <AlbumDO> dataObjects = dataAccess.ReadAlbum();
                    mappedItems = AlbumMapper.MapDoToPO(dataObjects);
                }
                else
                {
                    //Display albums that belong to user and provide actions to authenticated users.
                    List <AlbumDO> dataObjects = dataAccess.ViewAlbumByUserId((long)Session["UserId"]);
                    mappedItems = AlbumMapper.MapDoToPO(dataObjects);
                }
            }
            catch (Exception ex)
            {
                //Logs exception using exceptionLog class.
                exceptionLog.ExceptionLog("Critical", ex.Message, "AlbumController", "Index", ex.StackTrace);
            }
            return(View(mappedItems));
        }
        public ActionResult UploadPhoto()
        {
            //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 ex)
            {
                //Logs exception using exceptionLog class.
                exceptionLog.ExceptionLog("Critical", ex.Message, "PhotosController", "Index", ex.StackTrace);
            }

            return(View());
        }