示例#1
0
        public async Task <IActionResult> Create([Bind("ProjectId,ProjectName,ProjectDescription")] Project project)
        {
            if (ModelState.IsValid)
            {
                // Add the project
                _context.Add(project);

                await _context.SaveChangesAsync();

                // Add the user to the project with the master privilege level
                var userProjectInfo = new UserProjectInfo()
                {
                    ProjectId   = project.ProjectId,
                    UserId      = userId,
                    PrivilegeId = _context.Privilege.Where(p => p.PrivilegeLevel == 4)
                                  .FirstOrDefault()?.PrivilegeId ?? 0
                };

                _context.Add(userProjectInfo);

                await _context.SaveChangesAsync();


                return(RedirectToAction(nameof(Index)));
            }

            return(View(project));
        }
        public async Task <IActionResult> Create([Bind("UserProjectInfoId,UserId,ProjectId,PrivilegeId")] UserProjectInfo userProjectInfo)
        {
            userProjectInfo.UserId = GetUserId(userProjectInfo.UserId, userProjectInfo.ProjectId);
            if (string.IsNullOrEmpty(userProjectInfo.UserId))
            {
                ModelState.AddModelError("", "Error: You must enter a unique and valid user email!");
            }
            else if (!IsUserAdmin(userProjectInfo.ProjectId))
            {
                ModelState.AddModelError("", "You have insufficient privileges to create this item!");
            }
            else if (ModelState.IsValid)
            {
                _context.Add(userProjectInfo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ProjectsController.Details), "Projects", new { id = userProjectInfo.ProjectId }));
            }

            var project = _context.Project.FirstOrDefault(p => p.ProjectId == userProjectInfo.ProjectId);

            userProjectInfo.Project = project;
            ViewData["ProjectName"] = project.ProjectName;
            ViewData["PrivilegeId"] = GetPrivilegeSelectList();

            return(View(userProjectInfo));
        }
示例#3
0
        public async Task <IActionResult> Create([Bind("ProjectId,BugId,BugName,SeverityId,Behavior,StepsDescription,UserReportedId,UserAssignedId")] Bug bug)
        {
            var status = (bug.UserAssignedId == _context.Users.FirstOrDefault(u => u.FirstName == UNASSIGNED).Id) ? "New" : "Assigned";

            bug.Status     = _context.Status.FirstOrDefault(s => s.StatusName == status);
            bug.ReportDate = DateTime.Now;

            if (!CRUDEnabled(bug.ProjectId))
            {
                ModelState.AddModelError("", "You have insufficient privileges to create this item!");
            }
            else if (ModelState.IsValid)
            {
                _context.Add(bug);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(ProjectsController.Details), "Projects", new { id = bug.ProjectId }));
            }

            var project = _context.Project.FirstOrDefault(p => p.ProjectId == bug.ProjectId);

            ViewData["ProjectName"]    = project.ProjectName;
            ViewData["SeverityId"]     = new SelectList(_context.Severity.OrderByDescending(s => s.Priority), "SeverityId", "SeverityDisplay");
            ViewData["StatusId"]       = new SelectList(_context.Status.OrderBy(s => s.Step), "StatusId", "StatusDisplay");
            ViewData["UserAssignedId"] = GetUserSelect(bug.ProjectId);
            ViewData["UserReportedId"] = GetUserSelect(bug.ProjectId);

            return(View(bug));
        }