示例#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 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;
 }
示例#3
0
 public void Delete(PhotoAlbumEntity t)
 {
     using (this.mEntities = new photoshareEntities())
     {
         photoalbum current = this.mEntities.photoalbums.FirstOrDefault(x => x.Id == t.Id);
         if(current != null)
         {
             this.mEntities.photoalbums.DeleteObject(current);
         }
         this.mEntities.SaveChanges();
     }
 }
示例#4
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;
 }
示例#5
0
 private void CreateDirectory(PhotoAlbumEntity entity)
 {
     var path = Path.Combine(HttpContext.Current.Server.MapPath(string.Format("~/Albums/{0}", entity.Id)));
     if (!Directory.Exists(path))
     {
         Directory.CreateDirectory(path);
         Directory.CreateDirectory(path + "/Thumb");
         Directory.CreateDirectory(path + "/Small");
         Directory.CreateDirectory(path + "/Medium");
         Directory.CreateDirectory(path + "/Large");
         Directory.CreateDirectory(path + "/Original");
     }
 }