public ActionResult PostAdd(int? id, Blog.Data.Model.User user) { var postView = new PostCreateEditView { Id = -1, CategoryId = -1, Author = user.Login, MainImage = Url.Content("~/Content/img/post_defult.jpg") }; if (id.HasValue) { var post = UoW.Repository<Post>().GetById(id.Value); postView = Mapper.Map<Post, PostCreateEditView>(post); postView.CategoryId = post.Category.Id; postView.CurrentTags = JsonConvert.SerializeObject(post.Tag.Select(x => x.Text).ToArray()); } postView.CurrentCategories = UoW.Repository<Category>().Get().Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Title, Selected = postView.CategoryId > -1 && postView.CategoryId == x.Id }).ToList(); var alltags = UoW.Repository<Tag>().Get().Select(x => x.Text).ToList(); postView.AllTags = JsonConvert.SerializeObject(alltags); return View(postView); }
public ActionResult Create(Blog blog) { if (ModelState.IsValid) { db.Blogs.Add(blog); db.SaveChanges(); return RedirectToAction("Index"); } return View(blog); }
public ActionResult Create(Blog.Models.Post post) { if (ModelState.IsValid) { model.Posts.Add(post); model.SaveChanges(); return RedirectToAction("Index"); } return View(post); }
public ActionResult Edit(Blog blog) { if (ModelState.IsValid) { db.Entry(blog).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(blog); }