Esempio n. 1
0
        public ActionResult Create(ArticleViewModel model)
        {
            ViewBag.Data_ArticleCode = GetForeignData();
            ServiceResult result = new ServiceResult();
            TempData["Service_Result"] = result;
            if (ModelState.IsValid)
            {
                try
                {
                    Article article = new Article()
                    {
                        AddTime = DateTime.Now,
                        ArticleCodeValue = model.ArticleCode,
                        Content = model.Content,
                        Name = model.Name,
                        LastTime = DateTime.Now,
                        ArticleCode = Convert.ToInt32(model.ArticleCode.Split(',').Last())
                    };

                    ArticleService.Create(article);
                    result.Message = "添加文章信息成功!";
                    LogHelper.WriteLog("添加文章信息成功");
                    return RedirectToAction("index");
                }
                catch (Exception ex)
                {
                    result.Message = Utilities.GetInnerMostException(ex);
                    result.AddServiceError(result.Message);
                    LogHelper.WriteLog("添加文章信息错误", ex);
                    return View(model);
                }
            }
            else
            {
                result.Message = "请检查表单是否填写完整!";
                result.AddServiceError("请检查表单是否填写完整!");
                return View(model);
            }
        }
Esempio n. 2
0
 public ActionResult Edit(int id)
 {
     Article article = ArticleService.Find(id);
     List<int> ids = article.ArticleCodeValue.Split(',').Select(x => Convert.ToInt32(x)).ToList();
     ViewBag.Data_ArticleCode = GetForeignData(ids);
     ArticleViewModel model = new ArticleViewModel()
     {
         Name = article.Name,
         ID = article.ID,
         ArticleCode = article.ArticleCodeValue,
         Content = article.Content
     };
     return View(model);
 }
Esempio n. 3
0
 public ActionResult Edit(ArticleViewModel model)
 {
     List<int> ids = model.ArticleCode.Split(',').Select(x => Convert.ToInt32(x)).ToList();
     ViewBag.Data_ArticleCode = GetForeignData(ids);
     ServiceResult result = new ServiceResult();
     TempData["Service_Result"] = result;
     if (ModelState.IsValid)
     {
         try
         {
             Article entity = new Article()
             {
                 ID = model.ID,
                 Name = model.Name,
                 Content = model.Content,
                 ArticleCodeValue = model.ArticleCode,
                 ArticleCode = Convert.ToInt32(model.ArticleCode.Split(',').Last()),
                 LastTime = DateTime.Now
             };
             ArticleService.Update(entity);
             result.Message = "编辑文章信息成功!";
             LogHelper.WriteLog("编辑文章信息成功");
             return RedirectToAction("index");
         }
         catch (Exception ex)
         {
             result.Message = Utilities.GetInnerMostException(ex);
             result.AddServiceError(result.Message);
             LogHelper.WriteLog("编辑文章信息错误", ex);
             return View(model);
         }
     }
     else
     {
         result.Message = "请检查表单是否填写完整!";
         result.AddServiceError("请检查表单是否填写完整!");
         return View(model);
     }
 }