コード例 #1
0
        private void SetupUserAndTicket(Guid userId, Guid ticketId, TrackilyContext context)
        {
            var user = new TrackilyUser()
            {
                Id             = userId,
                UserName       = MockUsername,
                CreatedTickets = new List <Ticket>(),
                AssignedTo     = new List <UserTicket>()
            };

            context.Users.Add(user);
            context.SaveChanges();

            var userSaved = context.Users.Find(userId);
            var ticket    = new Ticket()
            {
                Project  = new Project(),
                Creator  = userSaved,
                TicketId = ticketId,
                Assigned = new List <UserTicket>()
            };

            context.Tickets.Add(ticket);
            context.SaveChanges();
        }
コード例 #2
0
        public async Task CreateTicket(TicketCreateBindingModel form, HttpContext request)
        {
            var ticket = new Ticket
            {
                Title          = form.Title,
                Creator        = await _userManager.GetUserAsync(request.User),
                Content        = form.Content,
                CommentThreads = new List <CommentThread>(),
                Assigned       = new List <UserTicket>(),
                Project        = _context.Projects.Include(p => p.Members).Single(p => p.Title.Equals(form.SelectedProject))
            };

            var projectMemberIds = ticket.Project.Members.Select(m => m.Id).ToList();

            foreach (string username in form.AddAssigned.Where(entry => entry != null))
            {
                var user = _context.Users.Single(u => u.UserName == username);
                Debug.Assert(user != null);

                var userTicket = _userTicketService.CreateUserTicket(user, ticket);
                ticket.Assigned.Add(userTicket);

                // If the user is not already a member of the given project, add them as a member.
                if (!projectMemberIds.Contains(user.Id))
                {
                    var userProject = _userProjectService.CreateUserProject(user, ticket.Project);
                    ticket.Project.Members.Add(userProject);
                }
            }

            _context.Tickets.Add(ticket);
            _context.SaveChanges(true);
        }
コード例 #3
0
ファイル: TicketsController.cs プロジェクト: sprzeng/trackily
        public async Task <IActionResult> Details(Guid id, TicketDetailsBindingModel input, string task)
        {
            var ticket = _ticketService.GetTicket(id);

            if (ticket == null)
            {
                return(View("Error404"));
            }

            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                var viewModel = _ticketService.DetailsTicketViewModel(ticket, allErrors);
                return(View(viewModel));
            }

            if (task == "create")
            {
                if (input.NewCommentThreadContent != null)
                {
                    await _commentService.AddCommentThread(ticket, input, HttpContext);
                }
                if (input.NewComments != null)
                {
                    await _commentService.AddComments(input, HttpContext);
                }
            }
            else
            {
                if (input.EditCommentThreads != null)
                {
                    _commentService.EditCommentThread(input);
                }

                if (input.EditComments != null)
                {
                    _commentService.EditComments(input);
                }
            }

            ticket.UpdatedDate = DateTime.Now;
            _context.SaveChanges(true);

            return(RedirectToAction("Details", new { id }));
        }
コード例 #4
0
        public async Task CreateProject(ProjectCreateBindingModel form, HttpContext request)
        {
            var project = new Project
            {
                ProjectId   = form.ProjectId,
                CreatedDate = DateTime.Now,
                Title       = form.Title,
                Description = form.Description,
                Creator     = await _userManager.GetUserAsync(request.User),
                Tickets     = new List <Ticket>(),
                Members     = new List <UserProject>()
            };

            if (!form.AddMembers.Contains(project.Creator.UserName)) // In case user still adds themselves as a member.
            {
                form.AddMembers.Add(project.Creator.UserName);
            }

            _userProjectService.AddMembersToProject(form.AddMembers, project);

            _context.Projects.Add(project);
            _context.SaveChanges(true);
        }
コード例 #5
0
        public void DeletingProject_DeletesAssociatedTickets()
        {
            var projectId = Guid.NewGuid();
            var ticketId  = Guid.NewGuid();

            var project = new Project
            {
                ProjectId = projectId,
                Tickets   = new List <Ticket>()
            };

            project.Tickets.Add(new Ticket
            {
                TicketId = ticketId,
            });

            var options = GetInMemoryDbContextOptions();

            using (var context = new TrackilyContext(options))
            {
                context.Database.EnsureCreated();
                context.Projects.Add(project);
                context.SaveChanges();
            }

            using (var context = new TrackilyContext(options))
            {
                var projectSaved = context.Projects.Include(p => p.Tickets).Single(p => p.ProjectId == projectId);
                Assert.NotNull(projectSaved);

                var ticketSaved = projectSaved.Tickets.ToList()[0];
                Assert.NotNull(ticketSaved);

                context.Projects.Remove(projectSaved);
                context.SaveChanges();
            }

            using (var context = new TrackilyContext(options))
            {
                var projects = context.Projects.ToList();
                Assert.Empty(projects);

                var tickets = context.Tickets.ToList();
                Assert.Empty(tickets);
            }
        }
コード例 #6
0
        public void DeletingTicket_DeletesUserTicket()
        {
            var ticketId = Guid.NewGuid();
            var userId   = Guid.NewGuid();

            var options = GetInMemoryDbContextOptions();

            using (var context = new TrackilyContext(options))
            {
                context.Database.EnsureCreated();

                var user = new TrackilyUser()
                {
                    Id             = userId,
                    CreatedTickets = new List <Ticket>(),
                    AssignedTo     = new List <UserTicket>()
                };

                context.Users.Add(user); // User must exist in the database before creating a Ticket/UserTicket due to FK constraint.
                context.SaveChanges();
            }

            using (var context = new TrackilyContext(options))
            {
                var userSaved = context.Users.Find(userId);
                Assert.NotNull(userSaved);

                var ticket = new Ticket()
                {
                    Project  = new Project(),
                    Creator  = userSaved,
                    TicketId = ticketId,
                    Assigned = new List <UserTicket>()
                };

                var userTicket = new UserTicket()
                {
                    Id       = userId,
                    TicketId = ticketId,
                    Ticket   = ticket,
                    User     = userSaved
                };

                ticket.Assigned.Add(userTicket);

                context.Tickets.Add(ticket);
                context.SaveChanges();
            }

            using (var context = new TrackilyContext(options))
            {
                var ticketSaved = context.Tickets.Find(ticketId);
                Assert.NotNull(ticketSaved);

                var userTicketSaved = context.UserTickets.Find(userId, ticketId);
                Assert.NotNull(userTicketSaved);

                context.Tickets.Remove(ticketSaved);
                context.SaveChanges();
            }

            using (var context = new TrackilyContext(options))
            {
                var tickets = context.Tickets.ToList();
                Assert.Empty(tickets);

                var userTickets = context.UserTickets.ToList();
                Assert.Empty(userTickets);
            }
        }