Exemple #1
0
        public async Task <IActionResult> Create([Bind("CommentText")] Comment comm, int id, string on)
        {
            if (on == "Project")
            {
                if (comm.CommentText == null)
                {
                    HttpContext.Session.SetString("errorMessage", "Comment has to include characters!");
                    return(RedirectToAction("Details", "Projects", new { id }));
                }

                comm.CommentAccountId = HttpContext.Session.GetInt32("AccID");
                comm.CommentProjectId = id;
                comm.CommentTaskId    = null;
                _context.Add(comm);
                await _context.SaveChangesAsync();

                // Redirect to Project where where comment belongs
                return(RedirectToAction("Details", "Projects", new { id }));
            }
            if (on == "Task")
            {
                if (comm.CommentText == null)
                {
                    HttpContext.Session.SetString("errorMessage", "Comment has to include characters!");
                    return(RedirectToAction("Details", "Tasks", new { id }));
                }
                comm.CommentAccountId = HttpContext.Session.GetInt32("AccID");
                comm.CommentTaskId    = id;
                comm.CommentProjectId = null;
                _context.Add(comm);
                await _context.SaveChangesAsync();

                // Redirect to Project where where comment belongs
                return(RedirectToAction("Details", "Tasks", new { id }));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("ProjectId,ProjectName,ProjectCreatedDateTime,ProjectDeadline,ProjectDescription,ProjectCreatorAccountId,ProjectActive,ProjectEndDateTime")] Project project)
        {
            AuthorizeUser();
            if (ModelState.IsValid)
            {
                project.ProjectCreatedDateTime = DateTime.Now;
                project.ProjectEndDateTime     = null;
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectCreatorAccountId"] = new SelectList(_context.Account, "AccountId", "AccountEmail", project.ProjectCreatorAccountId);
            return(View(project));
        }