예제 #1
0
        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();
            }
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
 public bool FileNameExists(PhotoEntity entity)
 {
     using (this.mEntities = new photoshareEntities())
     {
         return this.mEntities.photos.Any(x => x.AlbumId == entity.AlbumId && x.FileName == entity.FileName);
     }
 }
예제 #4
0
 public IEnumerable<TagEntity> All()
 {
     using (this.mEntities = new photoshareEntities())
     {
         var list = this.mEntities.tags.ToList();
         return Mapper.Map<IEnumerable<TagEntity>>(list);
     }
 }
예제 #5
0
 /// <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;
     }
 }
예제 #6
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;
 }
예제 #7
0
 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;
 }
예제 #8
0
 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;
 }
예제 #9
0
 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();
         }
     }
 }
예제 #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;
 }
예제 #11
0
 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;
 }
예제 #12
0
 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;
 }
예제 #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();
         }
     }
 }
예제 #14
0
 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();
     }
 }
예제 #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();
     }
 }