예제 #1
0
 // current user update album title
 // return -1 if fail
 // return 0 if success
 public static int EditAlbumTitle(AlbumDTO albumEdit)
 {
     using (var context = new CF_FamsamEntities())
     {
         var post = context.GeneralPost.FirstOrDefault(p => p.Id == albumEdit.Id);
         post.lastUpdate = DateTime.Now;
         var album = context.Album.FirstOrDefault(a => a.id == albumEdit.Id);
         album.title = albumEdit.Title;
         try
         {
             context.Entry<Album>(album).State = EntityState.Modified;
             context.Entry<GeneralPost>(post).State = EntityState.Modified;
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Debug.WriteLine("Exception: " + ex.StackTrace);
             return -1;
         }
         return 0;
     }
 }
예제 #2
0
 // current user update album title
 // return -1 if fail
 // return 0 if success
 public static int EditAlbum(AlbumDTO albumEdit, List<PhotoDTO> listPhotoAdd, List<PhotoDTO> listPhotoRemove)
 {
     using (var context = new CF_FamsamEntities())
     {
         var post = context.GeneralPost.FirstOrDefault(p => p.Id == albumEdit.Id);
         var album = post.Album;
         post.lastUpdate = DateTime.Now;
         album.title = albumEdit.Title;
         post.description = albumEdit.Description;
         try
         {
             // add new list of photos to album
             if (listPhotoAdd.Count > 0)
             {
                 foreach (var newPhoto in listPhotoAdd)
                 {
                     album.Photo.Add(context.Photo.FirstOrDefault(p => p.id == newPhoto.Id));
                 }
             }
             // remove list of photos from album
             if (listPhotoRemove.Count > 0)
             {
                 foreach (var removePhoto in listPhotoRemove)
                 {
                     album.Photo.Remove(context.Photo.FirstOrDefault(p => p.id == removePhoto.Id));
                 }
             }
             context.Entry<Album>(album).State = EntityState.Modified;
             context.Entry<GeneralPost>(post).State = EntityState.Modified;
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Debug.WriteLine("Exception: " + ex.StackTrace);
             return -1;
         }
         return 0;
     }
 }
예제 #3
0
        /// <summary>
        /// Update photo
        /// </summary>
        /// <param name="photo"></param>
        /// <returns></returns>
        public static int EditDescription(PhotoDTO photoDTO)
        {


            using (var db = new CF_FamsamEntities())
            {
                Photo photo = db.Photo.Find(photoDTO.Id);
                if (photo == null) return -1;

                //update photo
                DateTime lastUpdate = DateTime.Now;
                photo.Post.lastUpdate = lastUpdate;
                photo.Post.description = photoDTO.Description;
                try
                {
                    db.Entry(photo).State = EntityState.Modified;
                    db.SaveChanges();
                    return 1;
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Exception on Edit photo description:" + ex.ToString());
                }
            }
            return 0;
        }