示例#1
0
 public ActionResult CreatePost(CreateArticleView model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var entity = Mapper.Map <Article>(model);
             _unitOfWork.ArticleRepository.Insert(entity);
             _unitOfWork.Save();
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message);
         }
     }
     return(RedirectToAction("Create"));
 }
示例#2
0
 public ActionResult Create(CreateArticleView model)
 {
     model.ArticleCategory = _unitOfWork.ArticleCategoryRepository.Get()
                             .Where(x => x.Id != Guid.Empty)
                             .Select(x => new SelectListItem
     {
         Text  = x.Name,
         Value = x.Id.ToString()
     }).ToList();
     model.Users = _unitOfWork.UserRepository.Get()
                   .Where(x => x.Id != Guid.Empty)
                   .Select(x => new SelectListItem
     {
         Text  = x.LoginName,
         Value = x.Id.ToString()
     }).ToList();
     return(View(model));
 }