예제 #1
0
        protected virtual void Create(T item, PlaylistContext context)
        {
            item.CreatedBy = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value;
            item.CreatedOn = DateTime.UtcNow;

            context.Set <T>().Add(item);
        }
예제 #2
0
 public Task <MediaItemModel> GetMediaItemByPlaylistIdAsync(int id)
 {
     return(Task.Run(() =>
     {
         using (var context = new PlaylistContext())
             return GetMediaItemByPlaylistIdInternalAsync(id, context);
     }));
 }
예제 #3
0
 public Task <T> GetByIdAsync(int Id)
 {
     return(Task.Run(() =>
     {
         using (var context = new PlaylistContext())
             return GetByIdInternalAsync(Id, context);
     }));
 }
예제 #4
0
 public Task <MediaPlayer> GetMainMediaPlayerAsync()
 {
     return(Task.Run(() =>
     {
         using (var context = new PlaylistContext())
             return GetMainMediaPlayerInternal(context);
     }));
 }
예제 #5
0
 public Task <IReadOnlyCollection <MediaPlayer> > GetOptionalMediaPlayersAsync()
 {
     return(Task.Run(() =>
     {
         using (var context = new PlaylistContext())
             return GetOptionalMediaPlayersInternal(context);
     }));
 }
예제 #6
0
 public Task <IReadOnlyCollection <T> > GetAsync()
 {
     return(Task.Run(() =>
     {
         using (var context = new PlaylistContext())
             return GetInternalAsync(context);
     }));
 }
예제 #7
0
        protected virtual void Update(T item, PlaylistContext context)
        {
            var entity = GetEntities(context).Find(item.Id);

            if (entity == null)
            {
                return;
            }

            item.UpdatedOn = DateTime.UtcNow;
            item.UpdatedBy = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value;


            context.Entry(entity).CurrentValues.SetValues(item);
        }
예제 #8
0
        protected virtual void SaveInternal(T item, PlaylistContext context)
        {
            if (item.IsNew)
            {
                Create(item, context);
            }
            else
            {
                if (item.IsDeleted)
                {
                    context.Database.Log = (message) => Debug.WriteLine(message);
                    Delete(item, context);
                }
                else
                {
                    Update(item, context);
                }
            }

            context.SaveChanges();
        }
예제 #9
0
 protected override DbSet <MediaItemModel> GetEntities(PlaylistContext context)
 {
     return(context.MediaItems);
 }
예제 #10
0
 protected override DbSet <MediaPlayer> GetEntities(PlaylistContext context)
 {
     return(context.Mediaplayers);
 }
예제 #11
0
 protected override IReadOnlyCollection <MediaPlayer> GetInternalAsync(PlaylistContext context)
 {
     return(GetEntities(context).Include(p => p.Playlist).ToList());
 }
예제 #12
0
 private IReadOnlyCollection <MediaPlayer> GetOptionalMediaPlayersInternal(PlaylistContext context)
 {
     return(GetEntities(context).Include(p => p.Playlist)
            .Where(p => !p.IsPrimary)
            .ToList());
 }
예제 #13
0
 private MediaPlayer GetMainMediaPlayerInternal(PlaylistContext context)
 {
     return(GetEntities(context).Include(p => p.Playlist)
            .FirstOrDefault(p => p.IsPrimary));
 }
예제 #14
0
 protected virtual IReadOnlyCollection <T> GetInternalAsync(PlaylistContext context)
 {
     return(GetEntities(context).ToList());
 }
예제 #15
0
 protected virtual T GetByIdInternalAsync(int id, PlaylistContext context)
 {
     return(GetEntities(context).FirstOrDefault(p => p.Id == id));
 }
예제 #16
0
 private MediaItemModel GetMediaItemByPlaylistIdInternalAsync(int id, PlaylistContext context)
 {
     return(context.MediaItems.FirstOrDefault(p => p.Playlist.Id == id));
 }
예제 #17
0
 protected override DbSet <PlaylistModel> GetEntities(PlaylistContext context)
 {
     return(context.Playlists);
 }
예제 #18
0
 protected virtual void Delete(T item, PlaylistContext context)
 {
     context.Set <T>().Remove(item);
 }
예제 #19
0
 protected abstract DbSet <T> GetEntities(PlaylistContext context);
예제 #20
0
 public void Save(T item)
 {
     using (var context = new PlaylistContext())
         SaveInternal(item, context);
 }