Example #1
0
        public async Task <IActionResult> DeleteApp(DeleteAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(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
            {
                await _ossApiService.DeleteAppAsync(await _appsContainer.AccessToken(target.AppId, target.AppSecret), target.AppId);
            }
            catch (AiurUnexceptedResponse e)
            {
                if (e.Response.Code != ErrorType.HasDoneAlready)
                {
                    throw e;
                }
            }
            _dbContext.Apps.Remove(target);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(AllApps)));
        }
Example #2
0
        public async Task <IActionResult> DeleteApp(DeleteAppViewModel model)
        {
            var cuser = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(cuser, 1);
                return(View(model));
            }
            var target = await _dbContext.Apps.FindAsync(model.AppId);

            if (target == null)
            {
                return(NotFound());
            }
            else if (target.CreaterId != cuser.Id)
            {
                return(new UnauthorizedResult());
            }
            await _ossApiService.DeleteAppAsync(await _appsContainer.AccessToken(target.AppId, target.AppSecret), target.AppId);

            _dbContext.Apps.Remove(target);
            await _dbContext.SaveChangesAsync();

            return(RedirectToAction(nameof(AllApps)));
        }