Ejemplo n.º 1
0
        public virtual async Task <MemeTag> Update(Guid guid, MemeTag entity)
        {
            using (MemeFolderDbContext context = _contextFactory.CreateDbContext(null))
            {
                try
                {
                    var original = await context.MemeTags.FirstOrDefaultAsync(e => e.Id == guid);

                    foreach (PropertyInfo propertyInfo in original.GetType().GetProperties())
                    {
                        if (propertyInfo.GetValue(entity, null) == null)
                        {
                            propertyInfo.SetValue(entity, propertyInfo.GetValue(original, null), null);
                        }
                    }
                    context.Entry(original).CurrentValues.SetValues(entity);
                    await context.SaveChangesAsync();

                    return(entity);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Ошибка обновления");
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        public virtual async Task <MemeTag> Get(Guid guid)
        {
            using (MemeFolderDbContext context = _contextFactory.CreateDbContext(null))
            {
                MemeTag entity = await context.MemeTags.FirstOrDefaultAsync(e => e.Id == guid);

                return(entity);
            }
        }
Ejemplo n.º 3
0
        public virtual async Task <bool> Delete(Guid guid)
        {
            using (MemeFolderDbContext context = _contextFactory.CreateDbContext(null))
            {
                MemeTag entity = await context.MemeTags.FirstOrDefaultAsync(e => e.Id == guid);

                context.MemeTags.Remove(entity);

                await context.SaveChangesAsync();

                return(true);
            }
        }
Ejemplo n.º 4
0
        protected override async Task ExecuteAsync(object parameter)
        {
            DialogTagVM dialogMemeTagVM = new DialogTagVM(new MemeTag(), "Создание тега");

            MemeTag memeTag = (MemeTag)await MaterialDesignThemes.Wpf.DialogHost.Show(dialogMemeTagVM, _dialogId);

            if (memeTag == null)
            {
                return;
            }

            await _dataStorage.AddMemeTag(memeTag);
        }
Ejemplo n.º 5
0
        protected override async Task ExecuteAsync(object parameter)
        {
            MemeTag memeTag = (MemeTag)parameter;

            DialogTagVM dialogMemeTagVM = new DialogTagVM(memeTag, "Редактирование папки");

            MemeTag editedMemeTag = (MemeTag)await MaterialDesignThemes.Wpf.DialogHost.Show(dialogMemeTagVM, _dialogId);

            if (editedMemeTag == null)
            {
                return;
            }

            await _dataStorage.EditMemeTag(memeTag);
        }
Ejemplo n.º 6
0
        public virtual async Task <MemeTag> Create(MemeTag meme)
        {
            using (MemeFolderDbContext context = _contextFactory.CreateDbContext(null))
            {
                try
                {
                    EntityEntry <MemeTag> createdResult = await context.MemeTags.AddAsync(meme);

                    await context.SaveChangesAsync();

                    return(createdResult.Entity);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Ошибка создания");
                    return(null);
                }
            }
        }
Ejemplo n.º 7
0
        public virtual async Task <MemeTagNode> Create(MemeTagNode memeTagNode)
        {
            using (MemeFolderDbContext context = _contextFactory.CreateDbContext(null))
            {
                try
                {
                    Meme meme = await context.Memes.FirstOrDefaultAsync(m => m.Id == memeTagNode.Meme.Id);

                    if (meme != null)
                    {
                        memeTagNode.Meme = meme;
                    }
                    else
                    {
                        throw new ArgumentNullException("Meme can not be null");
                    }

                    MemeTag memeTag = await context.MemeTags.FirstOrDefaultAsync(mt => mt.Id == memeTagNode.MemeTag.Id);

                    if (memeTag != null)
                    {
                        memeTagNode.MemeTag = memeTag;
                    }
                    else
                    {
                        throw new ArgumentNullException("MemeTag can not be null");
                    }

                    EntityEntry <MemeTagNode> createdResult = await context.MemeTagNodes.AddAsync(memeTagNode);

                    await context.SaveChangesAsync();

                    return(createdResult.Entity);
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Ошибка создания");
                    return(null);
                }
            }
        }
 private void _dataStorage_OnRemoveMemeTag(MemeTag memeTag)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
 protected override async Task ExecuteAsync(object parameter)
 {
     MemeTag memeTag = (MemeTag)parameter;
     await _dataStorage.RemoveMemeTag(memeTag);
 }