예제 #1
0
        public async Task <IActionResult> Edit(string sitemapId, string sourceId)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var sitemap = await _sitemapManager.GetSitemapAsync(sitemapId);

            if (sitemap == null)
            {
                return(NotFound());
            }

            var source = sitemap.SitemapSources.FirstOrDefault(x => String.Equals(x.Id, sourceId, StringComparison.OrdinalIgnoreCase));

            if (source == null)
            {
                return(NotFound());
            }

            var model = new EditSourceViewModel
            {
                SitemapId       = sitemapId,
                SitemapSource   = source,
                SitemapSourceId = source.Id,
                Editor          = await _displayManager.BuildEditorAsync(source, updater : _updateModelAccessor.ModelUpdater, isNew : false)
            };

            model.Editor.SitemapSource = source;

            return(View(model));
        }
예제 #2
0
        public JsonResult Edit([FromBody] EditSourceViewModel sourceViewModel)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return(Json("Model state is invalid"));
            }

            var sourceId = sourceViewModel.Id;
            var source   =
                _unifyDbContext.Sources.FirstOrDefault(
                    x => x.UnifyUserId == _userManager.GetUserId(User) && x.Id == sourceId);

            if (source == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(Json("Cannot find this source"));
            }

            source.Name = sourceViewModel.Name;
            source.Url  = sourceViewModel.Url;
            source.Tags = sourceViewModel.Tags;

            _unifyDbContext.SaveChanges();

            return(Json("Success"));
        }
예제 #3
0
        public EditSourceView()
        {
            ViewModel = new EditSourceViewModel();
            EdgesForExtendedLayout = UIRectEdge.None;
            Title = "Edit";

            _textView = new UITextView {
                Font = UIFont.FromName("Courier", UIFont.PreferredBody.PointSize),
                SpellCheckingType      = UITextSpellCheckingType.No,
                AutocorrectionType     = UITextAutocorrectionType.No,
                AutocapitalizationType = UITextAutocapitalizationType.None,
                AutoresizingMask       = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
            };
        }
예제 #4
0
        /// <summary>
        /// Need another function because Xamarin generates an Invalid IL if used inline above
        /// </summary>
        private async Task CommitThis(EditSourceViewModel viewModel, LiteComposer composer, string content, string message)
        {
            try
            {
                await this.DoWorkAsync("Commiting...", () => viewModel.Commit(content, message));

                NavigationController.DismissViewController(true, null);
            }
            catch (Exception ex)
            {
                AlertDialogService.ShowAlert("Error", ex.Message);
                composer.EnableSendButton = true;
            }
        }
예제 #5
0
        public async Task <IActionResult> Edit(EditSourceViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageSitemaps))
            {
                return(Forbid());
            }

            var sitemap = await _sitemapManager.LoadSitemapAsync(model.SitemapId);

            if (sitemap == null)
            {
                return(NotFound());
            }

            var source = sitemap.SitemapSources.FirstOrDefault(x => String.Equals(x.Id, model.SitemapSourceId, StringComparison.OrdinalIgnoreCase));

            if (source == null)
            {
                return(NotFound());
            }

            var editor = await _displayManager.UpdateEditorAsync(source, updater : _updateModelAccessor.ModelUpdater, isNew : false);

            if (ModelState.IsValid)
            {
                // Clear sitemap cache when source edited.
                await _sitemapCacheProvider.ClearSitemapCacheAsync(sitemap.Path);

                await _sitemapManager.SaveSitemapAsync(sitemap.SitemapId, sitemap);

                _notifier.Success(H["Sitemap source updated successfully"]);
                return(RedirectToAction("Display", "Admin", new { sitemapId = model.SitemapId }));
            }

            _notifier.Error(H["The sitemap source has validation errors"]);
            model.Editor = editor;

            // If we got this far, something failed, redisplay form
            return(View(model));
        }