Esempio n. 1
0
        public PhotoListModel Add(PhotoDetailModel photoDetailModel)
        {
            var addedPhoto = _dataContext.Photos.Add(Mapper.PhotoDetailModelToPhotoEntity(photoDetailModel));

            _dataContext.SaveChanges();
            return(Mapper.PhotoEntityToPhotoListModel(addedPhoto));
        }
Esempio n. 2
0
 public AddNewObjectOnPhotoCommand(ObjectsOnPhotoViewModel viewModel, PhotoRepository photoRepository, PhotoDetailModel photoDetailModel, IMessenger messenger)
 {
     this.viewModel        = viewModel;
     this.photoRepository  = photoRepository;
     this.messenger        = messenger;
     this.photoDetailModel = photoDetailModel;
 }
Esempio n. 3
0
        public PhotoDetailModel Insert(PhotoDetailModel detail)
        {
            using (var galleryDbContext = new GalleryDbContext())
            {
                var entity = mapper.MapPhotoDetailModelToPhotoEntity(detail);
                entity.Id = Guid.NewGuid();

                if (entity.Album != null)
                {
                    var album = galleryDbContext.Albums.First(x => x.Id == entity.Album.Id);
                    entity.Album = album;
                }

                foreach (var objectOnPhotoEntity in entity.ObjectsOnPhoto)
                {
                    var thing  = galleryDbContext.Things.FirstOrDefault(x => x.Id == objectOnPhotoEntity.Object.Id);
                    var person = galleryDbContext.Persons.FirstOrDefault(x => x.Id == objectOnPhotoEntity.Object.Id);
                    if (thing != null)
                    {
                        objectOnPhotoEntity.Object = thing;
                    }
                    else if (person != null)
                    {
                        objectOnPhotoEntity.Object = person;
                    }
                }

                galleryDbContext.Photos.Add(entity);

                galleryDbContext.SaveChanges();

                return(mapper.MapPhotoEntityToPhotoDetailModel(entity));
            }
        }
Esempio n. 4
0
        public static PhotoDetailModel PhotoEntityToPhotoDetailModel(PhotoEntity photoEntity)
        {
            var model = new PhotoDetailModel
            {
                Id          = photoEntity.Id,
                Name        = photoEntity.Name,
                Path        = photoEntity.Path,
                CreatedTime = photoEntity.CreatedTime,
                Format      = photoEntity.Format,
                AlbumId     = photoEntity.AlbumId,
                Resolution  = new ResolutionModel()
                {
                    Height = photoEntity.Resolution.Height,
                    Width  = photoEntity.Resolution.Width,
                    Id     = photoEntity.Resolution.Id
                },
                Note     = photoEntity.Note,
                Location = photoEntity.Location,
            };

            if (photoEntity?.Tags == null)
            {
                return(model);
            }
            var tags = TagEntitiesToTagModels(photoEntity.Tags);

            model.Tags = tags;

            return(model);
        }
Esempio n. 5
0
        public void PhotoInsert_WithObjects()
        {
            ThingEntity someThing;

            using (var context = new GalleryDbContext())
            {
                someThing = context.Things.First();
            }

            ObjectOnPhotoEntity thingOnPhoto = new ObjectOnPhotoEntity()
            {
                PositionX = 1,
                PositionY = 2,
                Id        = Guid.NewGuid(),
                Object    = someThing
            };

            var detail = new PhotoDetailModel()
            {
                Name           = "ThingsTestPhoto",
                ObjectsOnPhoto = { mapper.MapObjectOnPhotoEntityToModel(thingOnPhoto) }
            };

            var photo = photoRepositorySUT.Insert(detail);

            Assert.NotNull(photo);

            using (var context = new GalleryDbContext())
            {
                Assert.Contains(context.Photos, x => x.Id == photo.Id);
            }
        }
Esempio n. 6
0
        public int Add(TagModel item, PhotoDetailModel photo)
        {
            var itemEntity = _dataContext.Items.FirstOrDefault(x => x.Name == item.Name) ?? _dataContext.Items.Add(new ItemEntity()
            {
                Name = item.Name
            });

            _dataContext.SaveChanges();

            var photoEntity = _dataContext.Photos.SingleOrDefault(x => x.Id == photo.Id);

            if (photoEntity == null)
            {
                return(-1);
            }

            var newItemTag = new ItemTagEntity()
            {
                Item      = itemEntity,
                ItemId    = itemEntity.Id,
                XPosition = item.XPosition,
                YPosition = item.YPosition,
            };

            photoEntity.Tags.Add(newItemTag);
            _dataContext.SaveChanges();
            return(newItemTag.Id);
        }
Esempio n. 7
0
        public PhotoDetailModel ChoosePhoto()
        {
            var fileDialog = new OpenFileDialog
            {
                InitialDirectory = "c:\\",
                Filter           = "Image files (*.jpg, *.jpeg, *.jpe, *.bmp, *.png, *.Tif, *.Tiff) | *.jpg; *.jpeg; *.jpe; *.bmp; *.png; *.Tif; *.Tiff",
                FilterIndex      = 2,
                RestoreDirectory = true
            };

            if (fileDialog.ShowDialog() != true)
            {
                return(null);
            }

            var path  = fileDialog.FileName;
            var photo = new PhotoDetailModel()
            {
                Name        = Path.GetFileName(path),
                Path        = path,
                Note        = fileDialog.Title,
                Format      = GetFileFormat(path),
                CreatedTime = GetCreatedTime(path),
                Resolution  = GetResolution(path),
            };

            return(photo);
        }
Esempio n. 8
0
        public PhotoDetailModel Update(PhotoDetailModel detail)
        {
            using (var galleryDbContext = new GalleryDbContext())
            {
                var entity = galleryDbContext.Photos.First(r => r.Id == detail.Id);

                entity.CreationTime = detail.CreationTime;
                entity.Format       = detail.Format;
                entity.Width        = detail.Width;
                entity.Height       = detail.Height;
                entity.Note         = detail.Note;

                if (detail.Album != null)
                {
                    var album = galleryDbContext.Albums.First(x => x.Id == detail.Album.Id);
                    entity.Album = album;
                }

                foreach (var objectOnPhotoEntity in entity.ObjectsOnPhoto.ToList())
                {
                    galleryDbContext.ObjectOnPhotoEntities.Remove(objectOnPhotoEntity);
                    galleryDbContext.SaveChanges();
                }

                foreach (var objectOnPhotoModel in detail.ObjectsOnPhoto)
                {
                    ObjectOnPhotoEntity toAdd = new ObjectOnPhotoEntity()
                    {
                        PositionX = objectOnPhotoModel.PositionX,
                        PositionY = objectOnPhotoModel.PositionY,
                        Id        = Guid.NewGuid(),
                        Photo     = entity
                    };

                    var thing  = galleryDbContext.Things.FirstOrDefault(x => x.Id == objectOnPhotoModel.Object.Id);
                    var person = galleryDbContext.Persons.FirstOrDefault(x => x.Id == objectOnPhotoModel.Object.Id);

                    if (thing != null)
                    {
                        toAdd.Object = thing;
                    }

                    else if (person != null)
                    {
                        toAdd.Object = person;
                    }

                    galleryDbContext.ObjectOnPhotoEntities.Add(toAdd);
                }


                galleryDbContext.SaveChanges();

                return(mapper.MapPhotoEntityToPhotoDetailModel(entity));
            }
        }
Esempio n. 9
0
        public void PhotoUpdate()
        {
            ThingEntity someThing;

            using (var context = new GalleryDbContext())
            {
                someThing = context.Things.First();
            }

            ObjectOnPhotoModel thingOnPhoto = new ObjectOnPhotoModel()
            {
                PositionX = 111,
                PositionY = 2,
                Id        = Guid.NewGuid(),
                Object    = someThing
            };

            ObjectOnPhotoModel thingOnPhoto2 = new ObjectOnPhotoModel()
            {
                PositionX = 1,
                PositionY = 2,
                Id        = Guid.NewGuid(),
                Object    = someThing
            };

            var detail = new PhotoDetailModel()
            {
                Name           = "UpdateTestPhotoStateBefore",
                ObjectsOnPhoto = { thingOnPhoto, thingOnPhoto2 }
            };

            var photo = photoRepositorySUT.Insert(detail);

            Assert.NotNull(photo);

            photo.Name           = "UpdateTestPhotoStateAfter";
            photo.ObjectsOnPhoto = new List <ObjectOnPhotoModel>();
            photo.ObjectsOnPhoto.Add(thingOnPhoto);

            var photoAfter = photoRepositorySUT.Update(photo);

            Assert.Equal("UpdateTestPhotoStateAfter", photoAfter.Name);
            Assert.Equal(1, photoAfter.ObjectsOnPhoto.Count);
            List <ObjectOnPhotoModel> list = (List <ObjectOnPhotoModel>)photoAfter.ObjectsOnPhoto;

            Assert.Equal(111, list[0].PositionX);


            using (var context = new GalleryDbContext())
            {
                var updatedPhoto = context.Photos.SingleOrDefault(x => x.Id == photoAfter.Id);
                Assert.NotNull(updatedPhoto);
                Assert.Equal("UpdateTestPhotoStateAfter", updatedPhoto.Name);
            }
        }
Esempio n. 10
0
        private void PhotoDetailChanged(SendDetailPhotoModel detailPhotoModel)
        {
            var model = _photoDetailModel = detailPhotoModel.PhotoDetailModel;

            _id         = model.Id;
            Name        = model.Name;
            CreatedTime = model.CreatedTime;
            Format      = model.Format;
            Resolution  = model.Resolution;
            Location    = model.Location;
            Note        = model.Note;
            Tags        = new ObservableCollection <TagModel>(model.Tags);
        }
Esempio n. 11
0
 private void OnLoad(SendFilterWithPhoto filterAndPhoto)
 {
     _photo = _unitOfWork.Photos.GetDetailModelById(filterAndPhoto.PhotoId);
     SendPhotoToDetailVm(_photo);
     SetPhotoProperties(_photo);
     // fetch filtered and sorted data which are from correct album or contains good tag
     _photosIds = _unitOfWork.Photos.GetSortedFilteredPhotosIds(filterAndPhoto.FilterSortSettings,
                                                                filterAndPhoto.ChosenItem);
     // Zistenie aktualneho indexu
     CurrentPhotoIndex = _photosIds.IndexOf(_photo.Id);
     // Zistenie poctu fotiek
     NumOfPhotos = _photosIds.Count;
 }
Esempio n. 12
0
        public PhotoDetailModel Insert(PhotoDetailModel photoDetail, Guid albumId)
        {
            using (var context = new PhotoLibraryDbContext())
            {
                var photoEntity = mapper.DetailModelToEntity(photoDetail);
                photoEntity.Id    = Guid.NewGuid();
                photoEntity.Album = context.Albums.First(a => a.Id == albumId);

                context.Photos.Add(photoEntity);
                context.SaveChanges();

                return(mapper.EntityToDetailModel(photoEntity));
            }
        }
Esempio n. 13
0
        public IActionResult PhotoDetail(int id)
        {
            var photo = _photoService.GetById(id);
            var model = new PhotoDetailModel()
            {
                Id      = photo.Id,
                Title   = photo.Title,
                Created = photo.DateCreated,
                Url     = photo.Url,
                Tags    = photo.Tags.Select(t => t.Description).ToList()
            };

            return(View(model));
        }
Esempio n. 14
0
 public static PhotoEntity PhotoDetailModelToPhotoEntity(PhotoDetailModel photoDetailModel)
 {
     return(new PhotoEntity()
     {
         Id = photoDetailModel.Id,
         Name = photoDetailModel.Name,
         AlbumId = photoDetailModel.AlbumId,
         Format = photoDetailModel.Format,
         Note = photoDetailModel.Note,
         Path = photoDetailModel.Path,
         Location = photoDetailModel.Location,
         ResolutionId = photoDetailModel.Resolution.Id,
         CreatedTime = photoDetailModel.CreatedTime,
     });
 }
Esempio n. 15
0
 public PhotoEntity MapPhotoDetailModelToPhotoEntity(PhotoDetailModel model)
 {
     return(new PhotoEntity()
     {
         Id = model.Id,
         Name = model.Path,
         Album = model.Album,
         CreationTime = model.CreationTime,
         Format = model.Format,
         Height = model.Height,
         Note = model.Note,
         Width = model.Width,
         ObjectsOnPhoto = MapObjectsOnPhotoModelToEnityList(model.ObjectsOnPhoto)
     });
 }
Esempio n. 16
0
        public void PhotoInsert_Simple()
        {
            var detail = new PhotoDetailModel()
            {
                Name = "SimpleTestPhoto"
            };

            var photo = photoRepositorySUT.Insert(detail);

            Assert.NotNull(photo);

            using (var context = new GalleryDbContext())
            {
                Assert.Contains(context.Photos, x => x.Id == photo.Id);
            }
        }
Esempio n. 17
0
        public bool Update(PhotoDetailModel photoDetail)
        {
            var photoEntity = _dataContext.Photos.SingleOrDefault(x => x.Id == photoDetail.Id);

            if (photoEntity == null)
            {
                return(false);
            }

            photoEntity.Name     = photoDetail.Name;
            photoEntity.Note     = photoDetail.Note;
            photoEntity.Location = photoDetail.Location;
            //photoEntity.Tags = Mapper.TagModelsToTagEntities(photoDetail.Tags);
            _dataContext.SaveChanges();
            return(true);
        }
Esempio n. 18
0
        public void Update(PhotoDetailModel photoDetail)
        {
            using (var context = new PhotoLibraryDbContext())
            {
                var photoEntity = context.Photos.First(a => a.Id == photoDetail.Id);

                photoEntity.Name        = photoDetail.Name;
                photoEntity.DateTime    = photoDetail.DateTime;
                photoEntity.FileFormat  = photoDetail.FileFormat;
                photoEntity.Description = photoDetail.Description;
                photoEntity.Path        = photoDetail.Path;
                photoEntity.Width       = photoDetail.Width;
                photoEntity.Height      = photoDetail.Height;

                context.SaveChanges();
            }
        }
Esempio n. 19
0
        public void PhotoRemove()
        {
            var detail = new PhotoDetailModel()
            {
                Name = "RemoveTestPhoto"
            };

            var photo = photoRepositorySUT.Insert(detail);

            Assert.NotNull(photo);

            photoRepositorySUT.Remove(photo.Id);

            using (var context = new GalleryDbContext())
            {
                Assert.DoesNotContain(context.Photos, x => x.Id == photo.Id);
            }
        }
Esempio n. 20
0
 public Photo DetailModelToEntity(PhotoDetailModel photo)
 {
     if (photo == null)
     {
         return(null);
     }
     return(new Photo()
     {
         Id = photo.Id,
         Name = photo.Name,
         DateTime = photo.DateTime,
         FileFormat = photo.FileFormat,
         Path = photo.Path,
         Description = photo.Description,
         Width = photo.Width,
         Height = photo.Height
     });
 }
Esempio n. 21
0
 private void SelectedPhoto(SelectedMessage message)
 {
     Detail = photoRepository.FindById(message.Id);
     AddNewObject.photoDetailModel = Detail;
     ThingsOnPhoto.Clear();
     PersonsOnPhoto.Clear();
     foreach (var objectOnPhotoModel in Detail.ObjectsOnPhoto)
     {
         if (objectOnPhotoModel.Object.GetType() == typeof(ThingEntity))
         {
             ThingsOnPhoto.Add(objectOnPhotoModel);
         }
         else
         {
             PersonsOnPhoto.Add(objectOnPhotoModel);
         }
     }
 }
Esempio n. 22
0
        private void SaveChanges()
        {
            var photo = new PhotoDetailModel()
            {
                Id       = _id,
                Name     = Name,
                Location = Location,
                Note     = Note,
                Tags     = Tags.ToList(),
            };

            _unitOfWork.Photos.Update(photo);

            if (_photoDetailModel.Name != Name)
            {
                _messenger.Send(new SendNewPhotoName(Name));
            }
            _photoDetailModel = photo;
        }
Esempio n. 23
0
        public void Execute(object parameter)
        {
            Mapper mapper = new Mapper();

            int.TryParse(viewModel.InputPosX, out int posx);
            int.TryParse(viewModel.InputPosY, out int posy);
            photoDetailModel.ObjectsOnPhoto.Add(new ObjectOnPhotoModel()
            {
                Photo  = mapper.MapPhotoDetailModelToPhotoEntity(photoDetailModel),
                Object = new ObjectEntity()
                {
                    Id = viewModel.SelectedObject
                },
                PositionX = posx,
                PositionY = posy
            });

            photoDetailModel = photoRepository.Update(photoDetailModel);
            messenger.Send(new UpdateDetailListsMessage()
            {
                Id = photoDetailModel.Id
            });
        }
Esempio n. 24
0
        public int Add(TagModel person, PhotoDetailModel photo)
        {
            var name         = person.Name.Split(' ');
            var fisrt        = name[0];
            var last         = name[1];
            var personEntity = _dataContext.Persons.FirstOrDefault(x => x.FirstName == fisrt);

            if (personEntity == null)
            {
                personEntity = new PersonEntity()
                {
                    FirstName = fisrt,
                    LastName  = last
                };
                _dataContext.Persons.Add(personEntity);
            }
            _dataContext.SaveChanges();

            var photoEntity = _dataContext.Photos.SingleOrDefault(x => x.Id == photo.Id);

            if (photoEntity == null)
            {
                return(-1);
            }
            var newPersonTag = new PersonTagEntity()
            {
                Person    = personEntity,
                PersonId  = personEntity.Id,
                XPosition = person.XPosition,
                YPosition = person.YPosition,
            };

            photoEntity.Tags.Add(newPersonTag);
            _dataContext.SaveChanges();

            return(newPersonTag.Id);
        }
Esempio n. 25
0
        public void PhotoInsert_WithAlbum()
        {
            AlbumEntity album;

            using (var context = new GalleryDbContext())
            {
                album = context.Albums.First();
            }

            var detail = new PhotoDetailModel()
            {
                Name  = "AlbumTestPhoto",
                Album = album
            };

            var photo = photoRepositorySUT.Insert(detail);

            Assert.NotNull(photo);

            using (var context = new GalleryDbContext())
            {
                Assert.Contains(context.Photos, x => x.Id == photo.Id);
            }
        }
Esempio n. 26
0
 public UpdatedPhotoMessage(PhotoDetailModel model)
 {
     Model = model;
 }
Esempio n. 27
0
 public SendDetailPhotoModel(PhotoDetailModel photoDetailModel)
 {
     PhotoDetailModel = photoDetailModel;
 }
Esempio n. 28
0
        public void AddNewPictures(IDataObject dropData)
        {
            var filePaths = ((string[])dropData.GetData(DataFormats.FileDrop));

            if (filePaths == null)
            {
                return;
            }
            Console.WriteLine(filePaths[0].ToString());
            foreach (var filePath in filePaths)
            {
                Image image;

                try
                {
                    image = Image.FromFile(filePath);
                }
                catch (OutOfMemoryException)
                {
                    Console.Write("File is probably not an image:" + filePath);
                    continue;
                }


                FormatType format;
                if (ImageFormat.Jpeg.Equals(image.RawFormat))
                {
                    format = FormatType.jpeg;
                }
                else if (ImageFormat.Png.Equals(image.RawFormat))
                {
                    format = FormatType.png;
                }
                else if (ImageFormat.Gif.Equals(image.RawFormat))
                {
                    format = FormatType.gif;
                }
                else if (ImageFormat.Bmp.Equals(image.RawFormat))
                {
                    format = FormatType.bmp;
                }
                else if (ImageFormat.Icon.Equals(image.RawFormat))
                {
                    format = FormatType.icon;
                }
                else
                {
                    format = FormatType.unknown;
                }

                PhotoDetailModel newImage = new PhotoDetailModel()
                {
                    CreationTime = File.GetCreationTime(filePath),
                    Height       = image.Height,
                    Width        = image.Width,
                    Name         = filePath,
                    Path         = filePath,
                    Format       = format
                };

                photoRepository.Insert(newImage);
                OnLoad();
            }
        }
Esempio n. 29
0
 private void NewPhotoMessageRecieved(NewPhotoMessage message)
 {
     Detail = new PhotoDetailModel();
 }
Esempio n. 30
0
 private void NewPhotoMessageReceived(NewMessage obj)
 {
     Detail = new PhotoDetailModel();
 }