コード例 #1
0
        public ActionResult UpdatePhoto(int photoID)
        {
            ActionResult response = null;

            if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3)
            {
                try
                {
                    response = View(PhotoMapper.PhotoDOtoPO(_dataAccess.ReadPhotoById(photoID)));
                }
                catch (Exception ex)
                {
                    LogFile.DataFile(ex: ex);
                    throw ex;
                }
                finally
                {
                }
            }
            else
            {
                TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
コード例 #2
0
        public ActionResult Create(CreatePhotoViewModels photo, HttpPostedFileBase photoUpload)
        {
            Photo photoToDB = PhotoMapper.MapCreatePhotoViewModel(photo);

            try
            {
                photoToDB.UserID = userID;
                photoToDB.Id     = Guid.NewGuid();
                photoToDB.Date   = DateTime.Now;
                photoToDB.Path   = $" /Photos/{photoUpload.FileName}";
                photoRepository.AddPhotoToDB(photoToDB);

                photoUpload.SaveAs(Path.Combine(Server.MapPath("~/Photos"), photoUpload.FileName));
                return(Content(photoUpload.FileName));
            }
            catch
            {
                var model  = PhotoMapper.MapCreatePhotoViewModel(photoToDB);
                var albums = albumRepository.GettAllAlbumsByUserID(userID);
                model.Albums.Add(new SelectListItem {
                    Text = "Uncategorized", Value = ""
                });
                albums.ForEach(x => model.Albums.Add(new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                }));

                return(Content(photoUpload.FileName));
            }
        }
コード例 #3
0
        public ActionResult Delete(string Id)
        {
            try
            {
                Photo model = photoRepository.GetPhotoFromDbById(new Guid(Id));
                if (model.UserID == userID)
                {
                    photoRepository.DeletePhotoFromDB(model);

                    string fullPath = Request.MapPath(model.Path);

                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                }
            }
            catch
            {
            }
            List <Photo> photosFromDB = photoRepository.GetPhotoFromDbByUserId(userID);
            ICollection <IndexPhotoViewModels> models = new List <IndexPhotoViewModels>();

            photosFromDB.ForEach(x => models.Add(PhotoMapper.MapIndexPhotoViewModel(x)));


            return(PartialView("_Images", models));
        }
コード例 #4
0
        public ActionResult UpdatePhoto(PhotoPO form)
        {
            ActionResult response = null;

            if (Session["RoleID"] != null && (byte)Session["RoleId"] == 3)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        _dataAccess.UpdatePhoto(PhotoMapper.PhotoPOtoDO(form));
                        response = RedirectToAction("ViewAllPhotos", "Photo");
                    }
                    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);
        }
コード例 #5
0
        public ActionResult ViewPhotoDetails(int photoID)
        {
            ActionResult response = null;
            PhotoDO      photo    = new PhotoDO();

            if (Session["RoleID"] != null)
            {
                try
                {
                    photo    = _dataAccess.ReadPhotoById(photoID);
                    response = View(PhotoMapper.PhotoDOtoPO(photo));
                }
                catch (Exception ex)
                {
                    LogFile.DataFile(ex: ex);
                }
                finally
                {
                }
            }
            else
            {
                TempData["Statement"] = "Please register to view this page.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
コード例 #6
0
        public ActionResult ViewAllPhotos()
        {
            ActionResult           response   = null;
            List <PhotoDO>         photoList  = new List <PhotoDO>();
            List <List <PhotoPO> > listPhotos = new List <List <PhotoPO> >();

            if (Session["RoleID"] != null && (byte)Session["RoleID"] >= 1)
            {
                try
                {
                    photoList = _dataAccess.ViewAllPhotos();
                    for (int i = 0; i < (float)photoList.Count / 4; i++)
                    {
                        listPhotos.Add(PhotoMapper.ListPhotoDOtoPO(photoList.Skip(i * 4).Take(4).ToList()));
                    }
                }
                catch (Exception ex)
                {
                    LogFile.DataFile(ex: ex);
                }
                finally
                {
                }
                response = View(listPhotos);
            }
            else
            {
                TempData["Statement"] = "Please register to view page you are requesting.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
コード例 #7
0
        public ActionResult Edit(Guid id)
        {
            var E = PhotoRepository.Photos.FirstOrDefault(c => c.PhotoId == id);

            var rr = PhotoMapper.MapDetailsPhotoView(E);

            return(View(rr));
        }
コード例 #8
0
ファイル: PhotoController.cs プロジェクト: CashmereBob/MVC
        public ActionResult AlbumPhotoes(string id)
        {
            List <Photo> photosFromDB         = photoRepository.GetAllPhotoesInAlbumByID(id);
            List <IndexPhotoViewModel> photos = new List <IndexPhotoViewModel>();

            photosFromDB.ForEach(x => photos.Add(PhotoMapper.MapIndexPhotoViewModel(x)));
            return(PartialView("_thumbnails", photos));
        }
コード例 #9
0
ファイル: PhotoController.cs プロジェクト: CashmereBob/MVC
        public ActionResult Details(DetailsPhotoViewModel photo)
        {
            Photo photoFromDB = photoRepository.GetPhotoFromDbById(photo.Id);

            photo = PhotoMapper.MapDetailsPhotoViewModel(photoFromDB);

            return(PartialView("_PhotoDetail", photo));
        }
コード例 #10
0
        // GET: User/Edit
        public ActionResult Index()
        {
            List <Photo> photosFromDB = photoRepository.GetPhotoFromDbByUserId(userID);
            ICollection <IndexPhotoViewModels> model = new List <IndexPhotoViewModels>();

            photosFromDB.ForEach(x => model.Add(PhotoMapper.MapIndexPhotoViewModel(x)));

            return(View(model));
        }
コード例 #11
0
ファイル: PhotoController.cs プロジェクト: CashmereBob/MVC
        public ActionResult Index()
        {
            List <Photo> photosFromDB         = photoRepository.GetAllPhotosFromDb();
            List <IndexPhotoViewModel> photos = new List <IndexPhotoViewModel>();

            photosFromDB.ForEach(x => photos.Add(PhotoMapper.MapIndexPhotoViewModel(x)));

            return(View(photos));
        }
コード例 #12
0
 public iNaturalistMapperFactory()
 {
     CommentMapper = new CommentMapper();
     PhotoMapper = new PhotoMapper();
     TaxonMapper = new TaxonMapper(PhotoMapper);
     IdentificationMapper = new IdentificationMapper(TaxonMapper);
     UserMapper = new UserMapper();
     ObservationMapper = new ObservationMapper(CommentMapper, IdentificationMapper,
         PhotoMapper, TaxonMapper, UserMapper);
 }
コード例 #13
0
ファイル: HomeController.cs プロジェクト: CashmereBob/MVC
        public ActionResult Data()
        {
            var model = new DataViewModel()
            {
                users    = userRepository.GetAllUsers().Count().ToString(),
                albums   = albumRepository.GettAllAlbums().Count().ToString(),
                comments = commentRepository.GetAllComments().Count().ToString(),
                photos   = photoRepository.GetAllPhotosFromDb().Count().ToString(),
                latest   = PhotoMapper.MapIndexPhotoViewModel(photoRepository.GetLastAddedPhoto()).Path
            };

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
コード例 #14
0
        public ActionResult Edit(EditPhotoViewModels photo, FormCollection collection)
        {
            Photo model = PhotoMapper.MapEditPhotoViewModel(photo);

            try
            {
                photoRepository.UdaptePhoto(model);
                return(Content(photo.Name));
            }
            catch
            {
                return(Content("Error"));
            }
        }
コード例 #15
0
        // GET: User/Edit/Delete/5
        public ActionResult Delete(DeletePhotoViewModels photo)
        {
            Photo model = photoRepository.GetPhotoFromDbById(photo.Id);

            photo = PhotoMapper.MapDeletePhotoViewModel(model);

            if (model.UserID == userID)
            {
                return(View(photo));
            }
            else
            {
                return(View());
            }
        }
コード例 #16
0
ファイル: HomeController.cs プロジェクト: CashmereBob/MVC
 public ActionResult Media(string Search, string Filter)
 {
     if (Filter == "photo")
     {
         List <Photo> photosFromDB         = photoRepository.GetSearchPhotosFromDb(Search);
         List <IndexPhotoViewModel> photos = new List <IndexPhotoViewModel>();
         photosFromDB.ForEach(x => photos.Add(PhotoMapper.MapIndexPhotoViewModel(x)));
         return(PartialView("_thumbnails", photos));
     }
     else
     {
         List <Album>          albumsFromDB = albumRepository.GetSearchAlbumsFromDB(Search).Where(x => x.Photos.Count() > 0).ToList();
         List <AlbumViewModel> albums       = new List <AlbumViewModel>();
         albumsFromDB.ForEach(x => albums.Add(AlbumMapper.MapAlbumViewModel(x, photoRepository)));
         return(PartialView("_thumbnailsAlbum", albums));
     }
 }
コード例 #17
0
ファイル: PhotoController.cs プロジェクト: CashmereBob/MVC
        public ActionResult Details(DetailsPhotoViewModel photo, FormCollection collection)
        {
            var comment = new Comment
            {
                Date    = DateTime.Now,
                Content = collection["comment"],
                UserID  = UserHelper.GetLogedInUser(userRepository).Id,
                PhotoID = photo.Id
            };

            commentRepository.AddComment(comment);

            Photo photoFromDB = photoRepository.GetPhotoFromDbById(photo.Id);

            photo = PhotoMapper.MapDetailsPhotoViewModel(photoFromDB);

            return(View(photo));
        }
コード例 #18
0
ファイル: PhotoMapperTest.cs プロジェクト: kgarsuta/iseahorse
        public void PhotoMapTest()
        {
            // Arrange
            var photoMapper = new PhotoMapper();

            dynamic obj = new JObject();
            obj.id = "101";
            obj.attribution = "Nice!";
            obj.thumb_url = "http://iseahorse.org/photo.jpg";

            var photo = new Photo();

            // Act
            photoMapper.Map(obj, photo);

            // Assert
            Assert.AreEqual(photo.Id, 101);
            Assert.AreEqual(photo.Attribution, "Nice!");
            Assert.AreEqual(photo.Uri, new Uri("http://iseahorse.org/photo.jpg"));
        }
コード例 #19
0
        public ActionResult Upload(HttpPostedFileBase file, PhotoPO form)
        {
            ActionResult response = null;

            if (Session["RoleID"] != null && (byte)Session["RoleID"] == 3)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        if (file.ContentLength > 0)
                        {
                            string fileName     = Path.GetFileName(file.FileName);
                            string path         = Path.Combine(Server.MapPath("~/Pictures"), fileName);
                            string relativePath = "/" + path.Replace(Server.MapPath("/"), "").Replace("\\", "/");
                            file.SaveAs(path);
                            form.Photo       = relativePath;
                            form.DateCreated = DateTime.Now;
                            _dataAccess.AddPhoto(PhotoMapper.PhotoPOtoDO(form));
                            response = RedirectToAction("ViewAllPhotos", "Photo");
                        }

                        else
                        {
                            response = View(form);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogFile.DataFile(ex: ex);
                        throw ex;
                    }
                }
            }
            else
            {
                TempData["Statement"] = "Please contact Admin to gain permissions to the page you are requesting.";
                response = RedirectToAction("Index", "Home");
            }
            return(response);
        }
コード例 #20
0
        public void SetBackgroundImageTempData()
        {
            int photoID;
            List <PhotoAlbumDO> junctionList = new List <PhotoAlbumDO>();

            try
            {
                junctionList = _dataAccess.ReadAllJunctions();
                PhotoAlbumBLO photoAlbumBLO = new PhotoAlbumBLO();
                photoID = photoAlbumBLO.PhotoInMostAlbums(PhotoAlbumMapper.ListPhotoAlbumDOtoPO(junctionList));
                PhotoPO mostCommonPhoto = PhotoMapper.PhotoDOtoPO(_photoDataAccess.ReadPhotoById(photoID));
                Session["BackgroundImageLocation"] = mostCommonPhoto.Photo;
            }
            catch (Exception ex)
            {
                LogFile.DataFile(ex: ex);
            }
            finally
            {
            }
        }
コード例 #21
0
        public static List <AlbumDm> LoadAlbums()
        {
            using (var webClient = new WebClient())
            {
                var json           = webClient.DownloadString(URL);
                var reader         = new JsonTextReader(new StringReader(json));
                var currentAlbumId = 0;
                while (reader.Read())
                {
                    if (reader.TokenType == JsonToken.StartObject)
                    {
                        var obj = JObject.Load(reader);
                        if (currentAlbumId != Convert.ToInt32(obj["albumId"]))
                        {
                            var album = new AlbumDm
                            {
                                AlbumId = Convert.ToInt32(obj["albumId"]),
                                Photos  = new List <PhotoDm>()
                            };

                            AlbumList.Add(album);

                            currentAlbumId = Convert.ToInt32(obj["albumId"]);

                            var photo = PhotoMapper.Map(obj);
                            AlbumList[AlbumList.Count - 1].Photos.Add(photo);
                        }
                        else
                        {
                            var photo = PhotoMapper.Map(obj);
                            AlbumList[AlbumList.Count - 1].Photos.Add(photo);
                        }
                    }
                }
            }
            return(AlbumList);
        }
コード例 #22
0
        // GET: User/Edit/Edit/5
        public ActionResult Edit(EditPhotoViewModels photo)
        {
            Photo model = photoRepository.GetPhotoFromDbById(photo.Id);

            photo         = PhotoMapper.MapEditPhotoViewModel(model);
            photo.AlbumId = model.AlbumID != null ? (Guid)model.AlbumID : Guid.Empty;
            var albums = albumRepository.GettAllAlbumsByUserID(userID);

            photo.Albums.Add(new SelectListItem {
                Text = "Uncategorized", Value = Guid.Empty.ToString()
            });
            albums.ForEach(x => photo.Albums.Add(new SelectListItem {
                Text = x.Name, Value = x.Id.ToString()
            }));

            if (model.UserID == userID)
            {
                return(View(photo));
            }
            else
            {
                return(View());
            }
        }