public async Task <IActionResult> DeleteFile(DeleteFileViewModel model) { var user = await GetCurrentUserAsync(); var app = await _dbContext.Apps.FindAsync(model.AppId); if (app == null) { return(NotFound()); } if (app.CreatorId != user.Id) { return(Unauthorized()); } if (!ModelState.IsValid) { model.Recover(user, app.AppName); return(View(model)); } try { var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret); await _filesService.DeleteFileAsync(token, model.SiteName, model.Path); return(RedirectToAction(nameof(ViewFiles), new { appId = model.AppId, siteName = model.SiteName, path = model.Path.DetachPath() })); } catch (AiurUnexpectedResponse e) { ModelState.AddModelError(string.Empty, e.Response.Message); model.Recover(user, app.AppName); return(View(model)); } }
public async Task <IActionResult> DeleteFile(DeleteFileViewModel model) { var user = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.Recover(user); return(View(model)); } try { await _filesService.DeleteFileAsync(await AccessToken, user.SiteName, model.Path); return(RedirectToAction(nameof(ViewFiles), new { path = model.Path.DetachPath() })); } catch (AiurUnexpectedResponse e) { ModelState.AddModelError(string.Empty, e.Response.Message); model.Recover(user); return(View(model)); } }