Exemplo n.º 1
0
        public async Task<ActionResult> Edit(PostViewModel model)
        {
            if (ModelState.IsValid)
            {
                await Task.Run(() =>
                {
                    _unitOfWork.Posts.Update(Mapper.Map<PostViewModel, Post>(model));
                    _unitOfWork.Save();
                });

                return RedirectToRoute(new { area = "", controller = "Blog", action = "Details", url = model.UrlSlug });
            }
            return RedirectToRoute(new { area = "Admin", controller = "Post", action = "Posts" });
        }
Exemplo n.º 2
0
        public ActionResult Create(PostViewModel model)
        {
            if (ModelState.IsValid)
            {
                var post = _unitOfWork.DataContext.Posts.FirstOrDefault(x => x.UrlSlug == model.UrlSlug);
                if (post != null)
                {
                    ModelState.AddModelError("", "Такой пост уже существует.");
                }
                else
                {
                    // TODO: Стремное решение

                    model.Author = _unitOfWork.DataContext.Users.Find(User.Identity.GetUserId());
                    _unitOfWork.Posts.Add(Mapper.Map<PostViewModel, Post>(model));
                    _unitOfWork.Save();
                    return RedirectToRoute(new { area = "", controller = "Blog", action = "Details", url = model.UrlSlug });
                }
            }
            return RedirectToAction("Create");
        }