public void SavePost(Post post)
		{
			if (post.ID == default(int))
			{
				context.Posts.Add(post);
			}
			else
			{
				context.Entry(post).State = EntityState.Modified;
			}

			context.SaveChanges();
		}
Exemplo n.º 2
0
		public ActionResult Create(Post post)
		{
			post.Author = User.Identity.Name;

			if (ModelState.IsValid)
			{
				db.SavePost(post);
				logger.Info(string.Format("New album added by {0} width ID = {1}", User.Identity.Name, post.ID));
				TempData["message"] = string.Format("New blog post saved with ID = {0}", post.ID);
				return RedirectToAction("Index");
			}

			AddCategoriesToViewBag();
			return View(post);
		}