예제 #1
0
        public IActionResult Save(Models.PostEditModel model)
        {
            // Validate
            if (string.IsNullOrWhiteSpace(model.Title))
            {
                ErrorMessage("The post could not be saved. Title is mandatory", false);
                return(View("Edit", editService.Refresh(model)));
            }
            if (string.IsNullOrWhiteSpace(model.SelectedCategory))
            {
                ErrorMessage("The post could not be saved. Category is mandatory", false);
                return(View("Edit", editService.Refresh(model)));
            }

            var ret = editService.Save(model, out var alias);

            // Save
            if (ret)
            {
                if (!string.IsNullOrWhiteSpace(alias))
                {
                    TempData["AliasSuggestion"] = alias;
                }

                SuccessMessage("The post has been saved.");
                return(RedirectToAction("Edit", new { id = model.Id }));
            }
            else
            {
                ErrorMessage("The post could not be saved.", false);
                return(View("Edit", editService.Refresh(model)));
            }
        }
예제 #2
0
        public async Task <IActionResult> Save(Models.PostEditModel model)
        {
            // Validate
            if (string.IsNullOrWhiteSpace(model.Title))
            {
                return(BadRequest());
            }
            if (string.IsNullOrWhiteSpace(model.SelectedCategory))
            {
                return(BadRequest());
            }

            var ret = editService.Save(model, out var alias);

            // Save
            if (ret)
            {
                if (_hub != null)
                {
                    await _hub.Clients.All.SendAsync("Update", model.Id);
                }

                if (!string.IsNullOrWhiteSpace(alias))
                {
                    return(Json(new
                    {
                        Location = Url.Action("Edit", new { id = model.Id }),
                        AliasSuggestion = new
                        {
                            Alias = $"{model.BlogSlug}/{alias}",
                            Redirect = $"{model.BlogSlug}/{model.Slug}",
                            BlogId = model.BlogId,
                            PostId = model.Id
                        }
                    }));
                }
                else
                {
                    return(Json(new { Location = Url.Action("Edit", new { id = model.Id }) }));
                }
            }
            else
            {
                return(StatusCode(500));
            }
        }