Пример #1
0
        public async Task <IActionResult> Create([Bind("Name,Description,Severity,Priority,Status,Project")] IssueViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Issue issue = new Issue()
                {
                    Name        = viewModel.Name,
                    Description = viewModel.Description,
                    Severity    = viewModel.Severity,
                    Priority    = viewModel.Priority,
                    Status      = viewModel.Status,
                    Project     = _context.Project.Find(viewModel.Project),
                };
                _context.Add(issue);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = issue.Id }));
            }
            var currentuserid = _userManager.GetUserId(User);

            viewModel.Projects = await _context.UserProject
                                 .Where(up => up.UserId.Equals(currentuserid))
                                 .Select(up => up.Project)
                                 .Include(p => p.CreatedBy)
                                 .Include(p => p.LastModifiedBy)
                                 .ToListAsync();

            return(View(viewModel));
        }
Пример #2
0
        public async Task <IActionResult> Create(CreateProjectViewModel createViewModel)
        {
            if (ModelState.IsValid)
            {
                //Create new project object to add.
                Project project = new Project()
                {
                    Name         = createViewModel.Name,
                    Description  = createViewModel.Description,
                    UserProjects = new List <UserProject>(),
                };
                //From posted email list, get emails that exist in db, then return a new UserProject object list (EqualityComparer is not used here).
                var toaddlist = createViewModel.Members
                                .Where(email => UserExists(email))
                                .Select(email => new UserProject()
                {
                    Project = project,
                    User    = _context.Users.FirstOrDefault(u => u.Email.Equals(email)),
                });

                project.UserProjects.AddRange(toaddlist);
                _context.Add(project);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Details), new { id = project.Id }));
            }
            return(View(createViewModel));
        }
Пример #3
0
        public async Task <ActionResult> Create([Bind("Body, IssueId")] Comment comment)
        {
            try
            {
                // TODO: Add insert logic here
                _context.Add(comment);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Details", "Issues", new { id = comment.IssueId }));
            }
            catch
            {
                return(RedirectToAction("Details", "Issues", new { id = comment.IssueId }));
            }
        }