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()); }
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; }
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; }
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; }
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(); } } }
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(); } }