Beispiel #1
0
        public async Task <IActionResult> Settings(SettingsViewModel model)
        {
            var user = await GetCurrentUserAsync();

            if (!ModelState.IsValid)
            {
                model.Recover(user);
                return(View(model));
            }
            try
            {
                var token = await _appsContainer.AccessToken();

                await _sitesService.UpdateSiteInfoAsync(token, model.OldSiteName, model.NewSiteName, model.OpenToUpload, model.OpenToDownload);

                user.SiteName = model.NewSiteName;
                await _userManager.UpdateAsync(user);

                _cache.Clear($"site-public-status-{model.OldSiteName}");
                _cache.Clear($"site-public-status-{model.NewSiteName}");
                return(RedirectToAction(nameof(Settings), "Dashboard", new { JustHaveUpdated = true }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user);
                model.NewSiteName = model.OldSiteName;
                return(View(model));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> Edit(EditViewModel 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.ModelStateValid = false;
                model.Recover(user, app.AppName);
                return(View(model));
            }
            try
            {
                var token = await _appsContainer.AccessToken(app.AppId, app.AppSecret);

                await _sitesService.UpdateSiteInfoAsync(token, model.OldSiteName, model.NewSiteName, model.OpenToUpload, model.OpenToDownload);

                _cache.Clear($"site-public-status-{model.OldSiteName}");
                _cache.Clear($"site-public-status-{model.NewSiteName}");
                return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.ModelStateValid = false;
                model.Recover(user, app.AppName);
                model.NewSiteName = model.OldSiteName;
                return(View(model));
            }
        }
        public async Task <IActionResult> Edit(EditViewModel 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 _recordsService.UpdateRecordInfoAsync(token, model.OldRecordName, model.NewRecordName, model.Type, model.URL, model.Tags?.Split(',') ?? Array.Empty <string>(), model.Enabled);

                _cache.Clear($"Record-public-status-{model.OldRecordName}");
                _cache.Clear($"Record-public-status-{model.NewRecordName}");
                return(RedirectToAction(nameof(AppsController.ViewApp), "Apps", new { id = app.AppId, JustHaveUpdated = true }));
            }
            catch (AiurUnexpectedResponse e)
            {
                ModelState.AddModelError(string.Empty, e.Response.Message);
                model.Recover(user, app.AppName);
                model.NewRecordName = model.OldRecordName;
                return(View(model));
            }
        }