コード例 #1
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);
            }
        }
コード例 #2
0
        public bool AddPerson(string firstName, string lastName, string group)
        {
            var alreadyExists = context.Persons.Any(p => p.FirstName == firstName && p.LastName == lastName && p.Group == group);

            if (alreadyExists)
            {
                return(false);
            }
            else
            {
                Persons p = new Persons()
                {
                    FirstName = firstName,
                    LastName  = lastName,
                    Group     = group
                };
                context.Persons.Add(p);
                context.SaveChanges();
                return(true);
            }
        }