public ActionResult Upload(Photo addGallery, HttpPostedFileBase file) { if (string.IsNullOrWhiteSpace(addGallery.PhotoName)) { ModelState.AddModelError("error", "Namnet får inte vara tomt!"); return(View("error", addGallery)); } if (file == null || file.ContentLength == 0) { ModelState.AddModelError("error", "En fil vill jag gärna att du laddar upp!"); // Vi skickar med model tillbaka så att vi kan få Name förifyllt! return(PartialView("error", addGallery)); } var destination = Server.MapPath("~/GalleryFolder/"); if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); } file.SaveAs(Path.Combine(destination, file.FileName)); var photo = new Photo { PhotoId = Guid.NewGuid(), PhotoPath = file.FileName, PhotoName = addGallery.PhotoName, PhotoComment = addGallery.PhotoComment }; PhotoRepository.Add(photo); return(RedirectToAction("Index")); }
public int AddPhoto(Photo photo) { //var path=Path.Combine(Server) //PhotoPath.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Upload"), photo.Name); //var path = Path.Combine(Server.MapPath("~/Upload"), ""); return(_photoRepository.Add(photo)); }
public ActionResult UploadPhoto(GalleryPhotoViewModel model, HttpPostedFileBase photo) { if (!ModelState.IsValid) { return(PartialView(model)); } photoRepository.Add(model.MapPhoto(photo.FileName, UserRepo.GetUserId(User.Identity.Name))); photo.SaveAs(Path.Combine(Server.MapPath("~/Photos"), photo.FileName)); return(RedirectToAction("Index")); }
public void CreatePhoto(PhotoViewModel photoViewModel) { PhotoRepository photoRepository = new PhotoRepository(); var photo = new Photo(); photo.Description = photoViewModel.Description; photo.ImagePath = photoViewModel.ImagePath; photo.ThumbPath = photoViewModel.ThumbPath; photo.CreatedOn = DateTime.Now; photoRepository.Add(photo); photoRepository.SaveChanges(); }
public ActionResult Create(Image image) { string filename = Path.GetFileNameWithoutExtension(image.ImageFile.FileName); string extension = Path.GetExtension(image.ImageFile.FileName); filename = filename + DateTime.Now.ToString("yymmssfff") + extension; image.ImagePath = "~/Image/" + filename; filename = Path.Combine(Server.MapPath("~/Image/"), filename); image.ImageFile.SaveAs(filename); repo.Add(image); ModelState.Clear(); return(RedirectToAction("List")); }
public ActionResult Create(PhotoViewModel model, HttpPostedFileBase file, Guid id) { if (ModelState.IsValid) { if (file != null || file.ContentLength != 0) { model.Id = Guid.NewGuid(); model.Url = @"/img/" + file.FileName; model.AlbumRefId = id; PhotoRepository.Add(model.ToEntity()); file.SaveAs(Path.Combine(Server.MapPath("~/img"), file.FileName)); } } return(List(id)); }
public async Task AddPhoto() { // Arrange var options = new DbContextOptionsBuilder <MyAlbumDbContext>() .UseInMemoryDatabase(databaseName: "PhotoRepository_AddPhoto_MyAlbumDatabase") .Options; using (var context = new MyAlbumDbContext(options)) { UnitOfWork unitOfWork = new UnitOfWork(context); PhotoRepository photoRepository = new PhotoRepository(context); string seed = Guid.NewGuid().ToString(); string seedUserId = Guid.NewGuid().ToString(); int seedPhotoId = new Random().Next(1, 100); string expectedUserName = string.Format("test_{0}@gmail.com", seed); Photo originalPhoto = new Photo() { Id = seedPhotoId, Author = new User() { Id = seedUserId, UserName = expectedUserName } }; // Act photoRepository.Add(originalPhoto); await unitOfWork.CompleteAsync(); // Assert Assert.Equal(1, await context.Photos.CountAsync(c => true)); var savedPhoto = await context.Photos.FirstAsync(c => true); Assert.NotEqual(0, savedPhoto.Id); Assert.Equal(originalPhoto.Name, savedPhoto.Name); Assert.Equal(originalPhoto.Author.Id, savedPhoto.Author.Id); Assert.Equal(originalPhoto.Author.UserName, savedPhoto.Author.UserName); } }
public ActionResult UploadPhoto(Photo model) { ImageManipulation imageManipulation = new ImageManipulation(); if (ModelState.IsValid) { if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { model.PhotoFile = imageManipulation.MakePhotoFileFromStream(file.InputStream, file.FileName); _repository.Add(model); } } return(RedirectToAction("Index")); } else { return(View(model)); } }
private static long LoadFiles(DbContainer container, DirectoryInfo origin, bool update, int?parentId = null) { Console.WriteLine($"Loading Files on folder [{origin.FullName}]."); var sw = new Stopwatch(); sw.Start(); var originFolder = container.FolderSet.FirstOrDefault(f => f.Name == origin.Name && f.ParentId == parentId); if (originFolder != null) { var added = 0; var updated = 0; foreach (var folderFile in origin.EnumerateFiles()) { Console.WriteLine($"[ONGOING] {folderFile.FullName} executionTime: {sw.ElapsedMilliseconds} "); var type = FileTypes.Find(type => type.Name == folderFile.Extension[1..].ToUpper()); if (type == null) { continue; } var file = container.FileSet.FirstOrDefault(f => f.Fullpath == folderFile.FullName); if (file == null) { file = GetFile(folderFile, originFolder.Id, type.Id); container.Add(file); container.SaveChanges(); } var photo = container.PhotoSet.FirstOrDefault(f => f.FileId == file.Id); if (photo == null) { added++; photo = photos.Load(file.Fullpath); if (photo != null) { if (type.Name != FileTypeEnum.CR2.ToString()) { var image = Image.FromFile(file.Fullpath); var thumb = image.Width > 0 && image.Height > 0 ? image.GetThumbnailImage(image.Width / Constants.ImageProperties.ThumbMultiplier, image.Height / Constants.ImageProperties.ThumbMultiplier, () => false, IntPtr.Zero) : image.GetThumbnailImage(Constants.ImageProperties.ThumbWidth, Constants.ImageProperties.ThumbHeight, () => false, IntPtr.Zero); photo.Thumbnail = new ImageConverter().ConvertTo(thumb, typeof(byte[])) as byte[]; image.Dispose(); thumb.Dispose(); } photoRep.Add(photo); container.SaveChanges(); } } else { var newPhoto = photos.Load(file.Fullpath); photo ??= new Photo(); photo.Iso = newPhoto.Iso; photo.Height = newPhoto.Height; photo.Width = newPhoto.Width; photo.FocalLength = newPhoto.FocalLength; photo.FStop = newPhoto.FStop; photo.DateTaken = newPhoto.DateTaken; photoRep.Update(photo); container.SaveChanges(); updated++; } } container.SaveChanges(); Console.WriteLine($"Added: {added}; updated/skipped: {updated}; executionTime: {sw.ElapsedMilliseconds} "); var dirs = origin.EnumerateDirectories(); foreach (var folder in dirs) { LoadFiles(container, folder, true, originFolder.Id); } } sw.Stop(); return(sw.ElapsedMilliseconds); }