コード例 #1
0
        public ActionResult AddCategory(AddCategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                BlogCategory bc = new BlogCategory()
                {
                    BlogId     = model.BlogId,
                    CategoryId = model.CategoryId
                };
                BusinessLayerResult <BlogCategory> res = _blogCategoryManager.Insert(bc);
                if (res.Errors.Count > 0)
                {
                    // başarısız
                    res.Errors.ForEach(x => ModelState.AddModelError("", x.Message));
                }
                else
                {
                    // başarılı
                    CacheHelper.RemoveGetBlogsWithOutDraftDeleteFromCache();
                    return(RedirectToAction("Edit", "Blog", new { @id = model.BlogId }));
                }
            }
            var catList = _categoryManager.List();

            ViewBag.CategoryId = new SelectList(catList, "Id", "Name", model.CategoryId);
            return(View(model));
        }
コード例 #2
0
 public ActionResult AddCategory(AddCategoryViewModel model)
 {
     if (ModelState.IsValid)
     {
         BlogCategory bc = new BlogCategory()
         {
             BlogId     = model.BlogId,
             CategoryId = model.CategoryId
         };
         BusinessLayerResult <BlogCategory> res = _blogCategoryManager.Insert(bc);
         if (res.Errors.Count > 0)
         {
             // başarısız
             res.Errors.ForEach(x => ModelState.AddModelError("", x.Message));
         }
         else
         {
             // başarılı
             return(RedirectToAction("Edit", "Blog", new { @id = model.BlogId }));
         }
     }
     ViewBag.CategoryId = new SelectList(CacheHelper.GetCategoriesFromCache(), "Id", "Name");
     return(View(model));
 }