public ActionResult CreateUserBlog() { var mobilePost = new MobilePost(); var user = Helpers.Helpers.GetUserForName(User.Identity.Name, db); if (user!=null) { mobilePost.UserId = (int)user.UserId; } ViewBag.HeaderString = "Create New Post"; return View("Create", mobilePost); }
public ActionResult SavePost(MobilePost post) { ViewBag.Message = "Failed: Title and Content cannot be empty..."; if (ModelState.IsValid) { if (!string.IsNullOrEmpty(post.Title) & !string.IsNullOrEmpty(post.Content)) { if (post.ID == 0) { post.PublishDate = DateTime.Now; _blogPostDal.Enitities.Add(post); } else { _blogPostDal.Enitities.Attach(post); _blogPostDal.Entry(post).State = EntityState.Modified; } db.SaveChanges(); //send email to administrator SendEmailToAdministrator(post.Title, post.Content); if(post.UserId>0) { return RedirectToAction("ArtistHome", "Gallery", new {userId = post.UserId}); } return RedirectToAction("Index", "Blog"); ViewBag.Message = "Message posted successfully!"; } } if (Request.IsAjaxRequest()) { return PartialView(); } return View("Create", post); // return "FAILED: Title and Comment must not be blank!"; }
public ActionResult Create() { var mobilePost = new MobilePost(); ViewBag.HeaderString = "Create New Post"; return View(mobilePost); }