public async Task <IActionResult> DeleteApp(DeleteAppViewModel model) { var cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.RootRecover(cuser, 1); return(View(model)); } var target = await _dbContext.Apps.FindAsync(model.AppId); if (target == null) { return(NotFound()); } else if (target.CreatorId != cuser.Id) { return(new UnauthorizedResult()); } try { var token = await _appsContainer.AccessToken(target.AppId, target.AppSecret); await _siteService.DeleteAppAsync(token, target.AppId); await _ossApiService.DeleteAppAsync(token, target.AppId); } catch (AiurUnexceptedResponse e) { if (e.Response.Code != ErrorType.HasDoneAlready) { throw e; } } _dbContext.Apps.Remove(target); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(AllApps))); }
public async Task <IActionResult> DeleteApp([FromRoute] string id, DeleteAppViewModel model) { var currentUser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.RootRecover(currentUser); return(View(model)); } var target = await _dbContext.Apps.FindAsync(id); if (target == null) { return(NotFound()); } else if (target.CreatorId != currentUser.Id) { return(new UnauthorizedResult()); } try { var token = await _appsContainer.AccessToken(target.AppId, target.AppSecret); await _siteService.DeleteAppAsync(token, target.AppId); await _recordsService.DeleteAppAsync(token, target.AppId); await _eventService.DeleteAppAsync(token, target.AppId); } catch (AiurUnexpectedResponse e) when(e.Response.Code == ErrorType.HasSuccessAlready) { } _dbContext.Apps.Remove(target); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(AllApps))); }