예제 #1
0
 public List<TagModel> GetTags(TagModel model)
 {
     TagEntity entity = new TagEntity()
     {
         Type = model.Type.ToString(),
         ParentId = model.ParentId
     };
     return Mapper.Map<List<TagModel>>(this.mTagRepository.All(entity).ToList());
 }
예제 #2
0
 public TagEntity Get(Guid id)
 {
     TagEntity tag = new TagEntity();
     using (this.mEntities = new photoshareEntities())
     {
         var entity = this.mEntities.tags.FirstOrDefault(x => x.Id == id);
         Mapper.Map(entity, tag);
     }
     return tag;
 }
예제 #3
0
 public IEnumerable<TagEntity> All(TagEntity entity)
 {
     IEnumerable<TagEntity> all = this.All();
     all = all.Where(x => x.Type == entity.Type);
     if (entity.ParentId != Guid.Empty)
     {
         all = all.Where(x => x.ParentId == entity.ParentId);
     }
     all = all.GroupBy(x => x.Name).Select(x => x.First());
     return all;
 }
예제 #4
0
 public TagEntity Add(TagEntity t)
 {
     tag tag = new tag();
     Mapper.Map(t, tag);
     using (this.mEntities = new photoshareEntities())
     {
         tag existingTag = this.mEntities.tags.FirstOrDefault(x => x.Name.ToUpper() == t.Name.ToUpper() && x.Type == t.Type && x.ParentId == t.ParentId);
         if (existingTag == null)
         {
             this.mEntities.tags.AddObject(tag);
             this.mEntities.SaveChanges();
         }
     }
     return t;
 }
예제 #5
0
 public void Delete(TagEntity t)
 {
     using (this.mEntities = new photoshareEntities())
     {
         var item = this.mEntities.tags.FirstOrDefault(x => x.Id == t.Id);
         if (item != null)
         {
             //Delete ALL of the specific tag references.
             if (t.IsCategory)
             {
                 var tags = this.mEntities.tags.Where(x => x.Name == item.Name && x.Type == item.Type);
                 tags.ToList().ForEach(this.mEntities.tags.DeleteObject);
             }
             else
             {
                 this.mEntities.tags.DeleteObject(item);
             }
             this.mEntities.SaveChanges();
         }
     }
 }
예제 #6
0
 public void Update(TagEntity t)
 {
     using (this.mEntities = new photoshareEntities())
     {
         tag current = this.mEntities.tags.FirstOrDefault(x => x.Id == t.Id);
         this.mEntities.tags.Attach(current);
         tag tag = Mapper.Map<tag>(t);
         this.mEntities.tags.ApplyCurrentValues(tag);
         this.mEntities.SaveChanges();
     }
 }