public async Task <IActionResult> Create(BEArticleViewModel article, int?categoryId = null)
        {
            if (ModelState.IsValid)
            {
                //var vmArticle = new SWBEArticleViewModel<BackendBEArticleViewModel>(article);
                //var result = await vmArticle.SaveModelAsync();
                var repositoryResponse = await article.SaveModelAsync(true).ConfigureAwait(false);

                if (repositoryResponse.IsSucceed)
                {
                    if (categoryId.HasValue)
                    {
                        return(RedirectToAction("Contents", "Pages", new { id = categoryId }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(View(article));
                }
            }
            ViewBag.categoryId = categoryId;
            return(View(article));
        }
        public async Task <IActionResult> Edit(BEArticleViewModel article, string id, int?categoryId = null)
        {
            if (id != article.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var repositoryResponse = await article.SaveModelAsync(true).ConfigureAwait(false);

                    if (repositoryResponse.IsSucceed)
                    {
                        if (categoryId.HasValue)
                        {
                            return(RedirectToAction("Contents", "Pages", new { id = categoryId }));
                        }
                        else
                        {
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        if (repositoryResponse.Exception != null)
                        {
                            ModelState.AddModelError(string.Empty, repositoryResponse.Exception?.Message);
                        }

                        foreach (var error in repositoryResponse.Errors)
                        {
                            ModelState.AddModelError(string.Empty, error);
                        }

                        return(View(article));
                    }
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BEArticleViewModel.Repository.CheckIsExists(m => m.Id == article.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                //return RedirectToAction("Index");
            }
            return(View(article));
        }
        public async Task <RepositoryResponse <BEArticleViewModel> > Post([FromBody] BEArticleViewModel model)
        {
            if (model != null)
            {
                var result = await model.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.Domain = this._domain;
                }
                return(result);
            }
            return(new RepositoryResponse <BEArticleViewModel>());
        }
Exemple #4
0
        public async Task <RepositoryResponse <BEArticleViewModel> > Save([FromBody] BEArticleViewModel article)
        {
            if (article != null)
            {
                var result = await article.SaveModelAsync(true).ConfigureAwait(false);

                if (result.IsSucceed)
                {
                    result.Data.DetailsUrl = SwCmsHelper.GetRouterUrl("Article", new { seoName = article.SeoName }, Request, Url);
                }
                return(result);
            }
            return(new RepositoryResponse <BEArticleViewModel>());
        }
        public IActionResult Create(int?categoryId = null)
        {
            BEArticleViewModel bEArticleViewModel = new BEArticleViewModel(new SiocArticle()
            {
                Specificulture  = CurrentLanguage,
                CreatedBy       = User.Identity.Name,
                CreatedDateTime = DateTime.UtcNow
            })
            {
                Status = SWStatus.Published
            };

            if (categoryId.HasValue)
            {
                CategoryArticleViewModel categoryArticleViewModel = bEArticleViewModel.Categories.Find(c => c.CategoryId == categoryId);
                if (categoryArticleViewModel != null)
                {
                    categoryArticleViewModel.IsActived = true;
                }
            }
            ViewBag.categoryId = categoryId;
            return(View(bEArticleViewModel));
        }
        public IActionResult Create(int?categoryId = null)
        {
            var vmArticle = new BEArticleViewModel(new SiocArticle()
            {
                Specificulture  = CurrentLanguage,
                CreatedBy       = User.Identity.Name,
                CreatedDateTime = DateTime.UtcNow
            })
            {
                Status = SWStatus.Preview
            };

            if (categoryId.HasValue)
            {
                var activeCate = vmArticle.Categories.Find(c => c.CategoryId == categoryId);
                if (activeCate != null)
                {
                    activeCate.IsActived = true;
                }
            }
            ViewBag.categoryId = categoryId;
            return(View(vmArticle));
        }