コード例 #1
0
        public ActionResult Create(ArticleViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.Article.ArticleHeadline = new MultiLangString(vm.ArticleHeadline,
                    CultureHelper.GetCurrentNeutralUICulture(), vm.ArticleHeadline,
                    nameof(vm.Article) + "." + vm.Article.ArticleId + "." + nameof(vm.Article.ArticleHeadline));
                vm.Article.ArticleBody = new MultiLangString(vm.ArticleBody, CultureHelper.GetCurrentNeutralUICulture(),
                    vm.ArticleBody,
                    nameof(vm.Article) + "." + vm.Article.ArticleId + "." + nameof(vm.Article.ArticleBody));

                _uow.Articles.Add(vm.Article);
                _uow.Commit();
                return RedirectToAction(nameof(Index));
            }

            return View(vm);
        }
コード例 #2
0
 // GET: Admin/Articles/Edit/5
 public ActionResult Edit(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Article article = _uow.Articles.GetById(id);
     if (article == null)
     {
         return HttpNotFound();
     }
     var vm = new ArticleViewModel
     {
         Article = article,
         ArticleHeadline = article.ArticleHeadline.Translate(),
         ArticleBody = article.ArticleBody.Translate()
     };
     return View(vm);
 }
コード例 #3
0
        public ActionResult Edit(ArticleViewModel vm)
        {
            if (ModelState.IsValid)
            {
                vm.Article.ArticleHeadline = _uow.MultiLangStrings.GetById(vm.Article.ArticleHeadlineId);
                vm.Article.ArticleHeadline.SetTranslation(vm.ArticleHeadline, CultureHelper.GetCurrentNeutralUICulture(),
                    nameof(vm.Article) + "." + vm.Article.ArticleId + "." + nameof(vm.Article.ArticleHeadline));

                vm.Article.ArticleBody = _uow.MultiLangStrings.GetById(vm.Article.ArticleBodyId);
                vm.Article.ArticleBody.SetTranslation(vm.ArticleBody, CultureHelper.GetCurrentNeutralUICulture(),
                    nameof(vm.Article) + "." + vm.Article.ArticleId + "." + nameof(vm.Article.ArticleBody));

                _uow.Articles.Update(vm.Article);
                _uow.Commit();
                return RedirectToAction(nameof(Index));
            }
            return View(vm);
        }