public void Update(PhotoAlbumEntity t)
        {
            using (this.mEntities = new photoshareEntities())
            {
                photoalbum current = this.mEntities.photoalbums.FirstOrDefault(x => x.Id == t.Id);
                this.mEntities.photoalbums.Attach(current);
                photoalbum album = Mapper.Map<photoalbum>(t);
                this.mEntities.photoalbums.ApplyCurrentValues(album);

                if (t.Favorite)
                {
                    var favorite = this.mEntities.favoritealbums.FirstOrDefault(x => x.AlbumId == t.Id && x.Owner == t.Owner);
                    if (favorite == null)
                    {
                        favoritealbum favoriteEntity = new favoritealbum();
                        Mapper.Map(album, favoriteEntity);
                        this.mEntities.favoritealbums.AddObject(favoriteEntity);
                    }
                }
                else
                {
                    var favorite = this.mEntities.favoritealbums.FirstOrDefault(x => x.AlbumId == t.Id && x.Owner == t.Owner);
                    if (favorite != null)
                    {
                        this.mEntities.favoritealbums.DeleteObject(favorite);
                    }
                }

                this.mEntities.SaveChanges();
            }
        }
        public void Update(PhotoEntity t)
        {
            using (this.mEntities = new photoshareEntities())
            {
                photo current = this.mEntities.photos.FirstOrDefault(x => x.Id == t.Id);
                this.mEntities.photos.Attach(current);
                photo photo = Mapper.Map<photo>(t);
                this.mEntities.photos.ApplyCurrentValues(photo);

                if (t.Favorite)
                {
                    favoritephoto favorite = new favoritephoto();
                    favorite.Date = DateTime.UtcNow;
                    Mapper.Map(photo, favorite);
                    this.mEntities.favoritephotos.AddObject(favorite);
                }
                else
                {
                    var favorite = this.mEntities.favoritephotos.FirstOrDefault(x => x.PhotoId == t.Id && x.Owner == t.Owner);
                    this.mEntities.favoritephotos.DeleteObject(favorite);
                }

                this.mEntities.SaveChanges();
            }
        }
 public bool FileNameExists(PhotoEntity entity)
 {
     using (this.mEntities = new photoshareEntities())
     {
         return this.mEntities.photos.Any(x => x.AlbumId == entity.AlbumId && x.FileName == entity.FileName);
     }
 }
 public IEnumerable<TagEntity> All()
 {
     using (this.mEntities = new photoshareEntities())
     {
         var list = this.mEntities.tags.ToList();
         return Mapper.Map<IEnumerable<TagEntity>>(list);
     }
 }
 /// <summary>
 /// Get user by Id
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public UserEntity Get(Guid id)
 {
     using (this.mEntities = new photoshareEntities())
     {
         user user = this.mEntities.users.FirstOrDefault(x => x.Id == id);
         UserEntity entity = Mapper.Map<UserEntity>(user);
         entity.PhotoAlbums.ForEach(x => x.Favorite = user.favoritealbums.Any(y => y.AlbumId == x.Id));
         return entity;
     }
 }
 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 PhotoEntity Get(Guid id)
 {
     PhotoEntity photo = new PhotoEntity();
     using (this.mEntities = new photoshareEntities())
     {
         var entity = this.mEntities.photos.FirstOrDefault(x => x.Id == id);
         Mapper.Map(entity, photo);
         photo.Favorite = entity.favoritephotos.Count > 0;
     }
     return photo;
 }
 public PhotoAlbumEntity Get(Guid id)
 {
     PhotoAlbumEntity album = new PhotoAlbumEntity();
     using (this.mEntities = new photoshareEntities())
     {
         var entity = this.mEntities.photoalbums.FirstOrDefault(x => x.Id == id);
         Mapper.Map(entity, album);
         album.Favorite = entity.favoritealbums.Count > 0;
     }
     return album;
 }
 public void Delete(PhotoEntity t)
 {
     using (this.mEntities = new photoshareEntities())
     {
         photo current = this.mEntities.photos.FirstOrDefault(x => x.Id == t.Id);
         if (current != null)
         {
             this.mEntities.photos.DeleteObject(current);
             this.mEntities.SaveChanges();
         }
     }
 }
Beispiel #10
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;
 }
 public PhotoEntity Add(PhotoEntity t)
 {
     photo photo = new photo();
     Mapper.Map(t, photo);
     using (this.mEntities = new photoshareEntities())
     {
         this.mEntities.photos.AddObject(photo);
         if (t.Favorite)
         {
             favoritephoto favorite = new favoritephoto();
             Mapper.Map(photo, favorite);
             this.mEntities.favoritephotos.AddObject(favorite);
         }
         this.mEntities.SaveChanges();
     }
     return t;
 }
 public PhotoAlbumEntity Add(PhotoAlbumEntity t)
 {
     photoalbum album = new photoalbum();
     Mapper.Map(t, album);
     using (this.mEntities = new photoshareEntities())
     {
         this.mEntities.photoalbums.AddObject(album);
         if (t.Favorite)
         {
             favoritealbum favorite = new favoritealbum();
             Mapper.Map(album, favorite);
             this.mEntities.favoritealbums.AddObject(favorite);
         }
         this.mEntities.SaveChanges();
     }
     return t;
 }
Beispiel #13
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();
         }
     }
 }
 public void Update(UserEntity t)
 {
     using (this.mEntities = new photoshareEntities())
     {
         user current = this.mEntities.users.FirstOrDefault(x => x.Id == t.Id);
         this.mEntities.users.Attach(current);
         user user = Mapper.Map<user>(t);
         this.mEntities.users.ApplyCurrentValues(user);
         this.mEntities.SaveChanges();
     }
 }
Beispiel #15
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();
     }
 }