public ActionResult Create(Micropost micropost) { if (!Request.IsAuthenticated) { return(RedirectToAction("Create", "Sessions")); } int currentUserId = int.Parse(User.Identity.Name); var currentUser = db.Users.Find(currentUserId); micropost.User = currentUser; micropost.DateCreated = DateTime.Now; try { db.Microposts.Add(micropost); db.SaveChanges(); TempData["success"] = "A new micropost was successfully created."; return(RedirectToAction("Dashboard", "Home")); } catch { TempData["error"] = "Can not create a micropost."; return(RedirectToAction("Dashboard", "Home")); } }
public ActionResult Create(Project project) { if (!Request.IsAuthenticated) { return(RedirectToAction("Create", "Sessions")); } project.DateCreated = DateTime.Now; if (ModelState.IsValid) { db.Projects.Add(project); db.SaveChanges(); TempData["success"] = "Project has successfully been created."; return(RedirectToAction("Details", "Projects", new { id = project.Id })); } return(View(project)); }
public ActionResult Create(User user) { if (Request.IsAuthenticated) { return(RedirectToAction("Dashboard", "Home")); } user.DateCreated = DateTime.Now; user.IsAdmin = false; if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); TempData["success"] = "Welcome to the Project Management App!"; FormsAuthentication.SetAuthCookie(user.Id.ToString(), false); // Session["CurrentUser"] = user; return(RedirectToAction("Dashboard", "Home")); } return(View(user)); }
public ActionResult Create(int pid, Task task) { if (!Request.IsAuthenticated) { return(RedirectToAction("Create", "Sessions")); } var project = db.Projects.Find(pid); task.Project = project; task.DateCreated = DateTime.Now; if (ModelState.IsValid) { db.Tasks.Add(task); db.SaveChanges(); TempData["success"] = "Task has successfully been created."; return(RedirectToAction("Tasks", "Projects", new { id = pid })); } return(View(task)); }