Пример #1
0
 public static void AddImage(Image image, string tags, bool[] filters)
 {
     var entity = new ImageNetworkEntities();
     if (tags != null)
     {
         string[] tagList = tags.Split(new Char[] { ' ', ',' });
         foreach (var item in tagList)
         {
             if (item == "") continue;
             var tag = new Tag
             {
                 Name = item,
             };
             tag.Name = tag.Name.TrimEnd().ToLower();
             if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) != null)
             {
                 tag = entity.Tag.FirstOrDefault(a => a.Name == tag.Name);
             }
             image.Tag.Add(tag);
             entity.SaveChanges();
         }
         for (int filterId = 1; filterId < filters.Length+1; filterId++)
         {
             if (filters[filterId - 1]) image.Filter.Add(entity.Filter.FirstOrDefault(a => a.Id == filterId));
         }
     }
     entity.Image.Add(image);
     entity.SaveChanges();
 }
Пример #2
0
        public static void AddTag(Tag tag)
        {
            var entity = new ImageNetworkEntities();
            tag.Name = tag.Name.TrimEnd().ToLower();

            if (entity.Tag.FirstOrDefault(a => a.Name == tag.Name) == null)
            {
                entity.Tag.Add(tag);
                entity.SaveChanges();
            }
        }
Пример #3
0
        public static Image[] GetImagesByTag(Tag tag)
        {
            var entity = new ImageNetworkEntities();

            return entity.Image.Where(a => a.Tag.FirstOrDefault(t => t.Name == tag.Name) != null).ToArray();
        }