Esempio n. 1
0
 public bool AddAllMediaFilesFromFolder(string path, bool recursive)
 {
     if (!manager.DirectoryExists(path))
     {
         return(false);
     }
     else
     {
         List <string> photos = manager.GetAllPhotos(path, recursive).ToList();
         List <string> videos = manager.GetAllVideos(path, recursive).ToList();
         foreach (var photo in photos)
         {
             if (!context.MediaItems.Any(i => i.Path == photo))
             {
                 MediaItems item = new MediaItems()
                 {
                     Path            = photo,
                     Title           = manager.GetFileName(photo, false),
                     Extension       = manager.GetFileExtension(photo),
                     IsPhoto         = true,
                     Description     = string.Empty,
                     MarkedForDelete = false,
                     PermanentDelete = false
                 };
                 context.MediaItems.Add(item);
             }
         }
         foreach (var video in videos)
         {
             if (context.MediaItems.Any(i => i.Path == video))
             {
                 MediaItems item = new MediaItems()
                 {
                     Path            = video,
                     Title           = manager.GetFileName(video, false),
                     Extension       = manager.GetFileExtension(video),
                     IsPhoto         = true,
                     Description     = string.Empty,
                     MarkedForDelete = false,
                     PermanentDelete = false
                 };
                 context.MediaItems.Add(item);
             }
         }
         context.SaveChanges();
         return(true);
     }
 }
Esempio n. 2
0
 public MediaItemDTO(MediaItems item)
 {
     this.Id              = item.ItemId;
     this.Title           = item.Title;
     this.Description     = item.Description;
     this.Path            = item.Path;
     this.Date            = item.Date;
     this.Extension       = item.Extension;
     this.IsPhoto         = item.IsPhoto;
     this.MarkedForDelete = item.MarkedForDelete;
     this.PermanentDelete = item.PermanentDelete;
     this.persons         = new List <PersonDTO>();
     this.properties      = new List <PropertyDTO>();
     if (item.Location == null)
     {
         this.Location = string.Empty;
     }
     else
     {
         this.Location = item.Location.Name;
     }
     if (item.Event == null)
     {
         this.Event = string.Empty;
     }
     else
     {
         this.Event = item.Event.Name;
     }
     foreach (var person in item.Persons)
     {
         this.persons.Add(new PersonDTO(person));
     }
     foreach (var property in item.DynamicProperties)
     {
         this.properties.Add(new PropertyDTO(property));
     }
 }
Esempio n. 3
0
        public bool AddLocalFile(string path, string description, DateTime date, bool overwrite)
        {
            if (!manager.IsImage(path) && !manager.IsVideo(path))
            {
                return(false);
            }
            bool alreadyExists = context.MediaItems.Any(i => i.Path == path);

            if (alreadyExists && !overwrite)
            {
                return(false);
            }
            else
            {
                if (!alreadyExists)
                {
                    bool       isPhoto   = manager.IsImage(path);
                    string     name      = manager.GetFileName(path, false);
                    string     extension = manager.GetFileExtension(path);
                    MediaItems item      = new MediaItems()
                    {
                        Path            = path,
                        Title           = name,
                        Extension       = extension,
                        IsPhoto         = isPhoto,
                        Description     = description,
                        Date            = date,
                        MarkedForDelete = false,
                        PermanentDelete = false
                    };
                    context.MediaItems.Add(item);
                }
                else if (alreadyExists && overwrite)
                {
                    var item = context.MediaItems.FirstOrDefault(i => i.Path == path);
                    foreach (var person in context.Persons.ToList())
                    {
                        if (person.MediaItems.Any(i => i.Path == path))
                        {
                            person.MediaItems.Remove(item);
                            item.Persons.Remove(person);
                        }
                    }
                    foreach (var property in context.DynamicProperties.ToList())
                    {
                        if (property.MediaItems.Any(i => i.Path == path))
                        {
                            property.MediaItems.Remove(item);
                            item.DynamicProperties.Remove(property);
                        }
                    }
                    if (item.Event != null)
                    {
                        item.Event.MediaItems1.Remove(item);
                        item.Event = null;
                    }
                    item.Description     = description;
                    item.MarkedForDelete = false;
                    item.PermanentDelete = false;
                }
                context.SaveChanges();
                return(true);
            }
        }