예제 #1
0
        public ActionResult Edit(NewsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                //notify!
                return(RedirectToAction("Edit"));
            }
            HttpPostedFileBase[] previewPics = model.PreviewPics;

            var article = NewsMapper.ToEntity(model);

            var entry = newsSrv.Edit(article, model.TagIds);

            model = NewsMapper.ToViewModel(entry);

            if (model == null)
            {
                //notify!
                return(RedirectToAction("Edit"));
            }

            if (model.ArticleId != 0 && previewPics != null && previewPics.Count() > 0)
            {
                SavePreviewPictrures(previewPics, model.ArticleId, model.Name, true);
            }

            return(RedirectToAction("Edit", new { id = model.ArticleId }));
        }
예제 #2
0
        public ViewResult Edit(int id = 0)
        {
            NewsViewModel model    = new NewsViewModel();
            string        userId   = User.Identity.GetUserId();
            UserProfile   userProf = userSrv.Get(userId);

            if (id > 0)
            {
                var article = newsSrv.Get(id);

                if (article == null)
                {
                    ModelState.AddModelError("", "Указанная статья не найдена!");
                }

                model = NewsMapper.ToViewModel(article);

                model.TagIds = model.Tags?.Select(x => x.Id).ToArray();
            }
            else
            {
                //newsSrv.Edit()
            }

            model.Tags     = newsSrv.Tags;
            model.IsInRole = User.IsInRole;
            model.OwnerId  = userProf.Id;

            return(View(model));
        }