예제 #1
0
        public ActionResult UploadPicture(string comment, HttpPostedFileBase[] files, Photo photo)
        {
            Thread.Sleep(3000);
            if (!ModelState.IsValid)
            {
                return(View(photo));
            }
            if (files == null)
            {
                ModelState.AddModelError("error", "Ingen Bild!");
                return(View(photo));
            }
            foreach (var file in files)
            {
                file.SaveAs(
                    Path.Combine(Server.MapPath("~/Image"), file.FileName));
                photo.PhotoID      = Guid.NewGuid();
                photo.PhotoName    = file.FileName;
                photo.PhotoComment = new List <Comments> {
                    new Comments {
                        Id = Guid.NewGuid(), CommentOnPicture = comment
                    }
                };
                var photos = PhotoModelMapper.EntityToModel(photo);
                photoRepo.AddPhoto(photos);
                //photos.Add(new Photo { PhotoID = Guid.NewGuid(), PhotoName = file.FileName,
                //    PhotoComment = new List<Comments> { new Comments { CommentOnPicture = comment } } });
            }

            return(PartialView("Index", photoRepo.GetAllPhoto().Select(x => PhotoModelMapper.ModelToEntity(x)).ToList()));
        }
예제 #2
0
 public ActionResult AddNewPhoto(string comment, HttpPostedFileBase[] files, Photo newphoto)
 {
     Thread.Sleep(3000);
     if (!ModelState.IsValid)
     {
         return(View(newphoto));
     }
     if (files == null)
     {
         ModelState.AddModelError("error", "No picture");
     }
     foreach (var file in files)
     {
         file.SaveAs(Path.Combine(Server.MapPath("/Image"), file.FileName));
         newphoto.PhotoID      = Guid.NewGuid();
         newphoto.PhotoName    = file.FileName;
         newphoto.PhotoComment = new List <Comments> {
             new Comments {
                 Id = Guid.NewGuid(), CommentOnPicture = comment
             }
         };
         var photos = PhotoModelMapping.EntityToModel(newphoto);
         photorepo.AddPhoto(photos);
     }
     return(PartialView("Index", photorepo.GetPhotos().Select(x => PhotoModelMapping.ModelToEntity(x)).ToList()));
 }
        public JsonResult Upload(UploadModel model)
        {
            PhotoRepository repo = new PhotoRepository();

            model.userid = User.Identity.GetUserId();
            bool resp = repo.AddPhoto(model);

            return(Json(resp, JsonRequestBehavior.AllowGet));
        }
예제 #4
0
        public HomeViewModel()
        {
            Title           = "Home";
            photoRepository = new PhotoRepository();
            Photos          = photoRepository.Photos;

            MessagingCenter.Subscribe <PhotoDetailsPage, Photo>(this, Constants.EDIT_PHOTO, async(obj, photo) =>
            {
                var editPhoto = photo;
                var oldPhoto  = Photos.Where((Photo arg) => arg.Id == photo.Id).FirstOrDefault();
                oldPhoto      = editPhoto;

                photoRepository.UpdatePhoto(editPhoto);
            });

            MessagingCenter.Subscribe <PhotoDetailsPage, Photo>(this, Constants.DELETE_PHOTO, async(obj, photo) =>
            {
                Photos.Remove(photo);
                photoRepository.DeletePhoto(photo);
            });

            MessagingCenter.Subscribe <AddNewPhotoPage, Photo>(this, Constants.ADD_NEW_PHOTO, async(obj, photo) =>
            {
                Photos.Insert(0, photo);
                Photo newPhoto = new Photo
                {
                    AlbumId      = 5,
                    Id           = photo.Id,
                    Title        = photo.Title,
                    Url          = photo.Url,
                    ThumbnailUrl = photo.ThumbnailUrl
                };

                photoRepository.AddPhoto(newPhoto);
            });
        }
예제 #5
0
 public int AddPhoto(Photo photo)
 {
     return(photoRepository.AddPhoto(photo));
 }
예제 #6
0
 public void AddPhoto(Photo photo)
 {
     PhotoRepository.AddPhoto(photo);
 }