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); } } }
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); } }
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); } }
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); }
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); }
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); } } }
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(); }
protected override async Task ExecuteAsync(object parameter) { MemeTag memeTag = (MemeTag)parameter; await _dataStorage.RemoveMemeTag(memeTag); }