コード例 #1
0
        public ActionResult Create(ArticleCreateViewModel article)
        {
            if (ModelState.IsValid)
            {
                var articleObj = PrepareArticleViewModelToUpdate(article);
                var response = _articleManager.CreateNewArticle(articleObj);
                if(response.Success && response.Result.ArticleId > 0)
                    return RedirectToAction("Index");
                else
                    ModelState.AddModelErrors("", response.Messages);
            }

            return View(article);
        }
コード例 #2
0
 public static ArticleCreateViewModel MapToArticleCreateViewModel(this Article article)
 {
     var obj = new ArticleCreateViewModel
                 {
                     ArticleId = article.ArticleId,
                     ArticleName = article.ArticleName,
                     Title = article.Title,
                     Content = article.Content,
                     CreatedDate = article.CreatedDate,
                     LastUpdatedDate = article.LastUpdatedDate.Value,
                     PublishDate = article.PublishDate,
                     Places = article.Places
                 };
     string str = string.Empty;
     foreach (var place in article.Places)
     {
         str += place.PlaceId.ToString() + ',';
     }
     obj.PlacesIdsString = str;
     return obj;
 }
コード例 #3
0
 private Article PrepareArticleViewModelToUpdate(ArticleCreateViewModel viewModel)
 {
     var articleIds = !string.IsNullOrEmpty(viewModel.PlacesIdsString) ? viewModel.PlacesIdsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : null;
     var articleObj = viewModel.TransformToArticle();
     foreach (var id in articleIds)
     {
         var place = new Place { PlaceId = int.Parse(id) };
         if(articleObj.Places == null)
             articleObj.Places = new List<Place>();
         articleObj.Places.Add(place);
     }
     return articleObj;
 }
コード例 #4
0
        public ActionResult Edit(ArticleCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                var articleIds = !string.IsNullOrEmpty(model.PlacesIdsString) ? model.PlacesIdsString.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : null;
                var articleObj = model.TransformToArticle();
                foreach (var id in articleIds)
                {
                    var place = new Place { PlaceId = int.Parse(id) };
                    if (articleObj.Places == null)
                        articleObj.Places = new List<Place>();
                    articleObj.Places.Add(place);
                }

                var response = _articleManager.EditArticle(articleObj);

                if (response.Success)
                {
                    TempData[Constants.TempdataKeys.EditArticleSuccessKey] = true;
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelErrors("", response.Messages);
                }
            }
            return RedirectToAction("Edit");
        }