public async Task <ActionResult> Remove(RemoveMediaRequestVM vm) { await _media.RemoveAsync(vm, User); await _db.SaveChangesAsync(); return(RedirectToSuccess("Медиа-файл удален")); }
public async Task <ActionResult> Remove(Guid id, bool confirm) { await _media.RemoveAsync(id, User); await _db.SaveChangesAsync(); return(RedirectToSuccess("Медиа-файл удален")); }
public async Task <ActionResult> Remove(RemoveEntryRequestVM vm) { if (vm.RemoveCompletely) { await _media.RemoveCompletelyAsync(vm.Id, User); } else { await _media.RemoveAsync(vm.Id, User); } await _db.SaveChangesAsync(); return(RedirectToSuccess("Медиа-файл удален")); }
/// <summary> /// Reverts a change. /// </summary> public async Task RevertChangeAsync(Guid id, ClaimsPrincipal user) { var chg = await _db.Changes .AsNoTracking() .GetAsync(x => x.Id == id, "Правка не найдена"); var isRemoving = string.IsNullOrEmpty(chg.OriginalState); switch (chg.Type) { case ChangesetEntityType.Media: { if (isRemoving) { await _media.RemoveAsync(new RemoveMediaRequestVM { Id = chg.EditedMediaId.Value, RemoveFile = false }, user); } else { var vm = JsonConvert.DeserializeObject <MediaEditorVM>(chg.OriginalState); await _media.UpdateAsync(vm, user, id); } return; } case ChangesetEntityType.Page: { if (isRemoving) { var page = await _pages.RemoveAsync(chg.EditedPageId.Value, user); await _search.RemovePageAsync(page); } else { var vm = JsonConvert.DeserializeObject <PageEditorVM>(chg.OriginalState); var page = await _pages.UpdateAsync(vm, user, id); await _search.AddPageAsync(page); } return; } case ChangesetEntityType.Relation: { if (isRemoving) { await _rels.RemoveAsync(chg.EditedRelationId.Value, user); } else { var vm = JsonConvert.DeserializeObject <RelationEditorVM>(chg.OriginalState); await _rels.UpdateAsync(vm, user, id); } return; } default: throw new ArgumentException($"Неизвестный тип сущности: {chg.Type}!"); } }
/// <summary> /// Reverts a change. /// </summary> public async Task RevertChangeAsync(Guid id, ClaimsPrincipal user) { var(chg, prev) = await GetChangesetPairAsync(id, q => q.AsNoTracking()); var isRemoving = string.IsNullOrEmpty(prev?.UpdatedState); switch (chg.EntityType) { case ChangesetEntityType.Media: { if (isRemoving) { await _media.RemoveAsync(chg.EditedMediaId.Value, user); } else { var vm = JsonConvert.DeserializeObject <MediaEditorVM>(prev.UpdatedState); await _media.UpdateAsync(vm, user, id); } return; } case ChangesetEntityType.Page: { if (isRemoving) { var pageId = chg.EditedPageId.Value; await _pages.RemoveAsync(pageId, user); await _search.RemovePageAsync(pageId); } else { var vm = JsonConvert.DeserializeObject <PageEditorVM>(prev.UpdatedState); var pageId = vm.Id == Guid.Empty ? chg.EditedPageId.Value : vm.Id; // workaround for a legacy bug var page = await _pages.UpdateAsync(vm, user, id, pageId); await _search.AddPageAsync(page); } return; } case ChangesetEntityType.Relation: { if (isRemoving) { await _rels.RemoveAsync(chg.EditedRelationId.Value, user); } else { var vm = JsonConvert.DeserializeObject <RelationEditorVM>(prev.UpdatedState); await _rels.UpdateAsync(vm, user, id); } return; } default: throw new ArgumentException($"Неизвестный тип сущности: {chg.EntityType}!"); } }