示例#1
0
        private void ButtonSubmit_Click(object sender, EventArgs e)
        {
            using (var lDataContext = new IssueTrackerDataContext())
            {
                var lIssue = new Issue();
                lIssue.ProjectId           = this.Project.Id;
                lIssue.Title               = this.mTextBoxTitle.Text;
                lIssue.Body                = this.mTextPreviewViewBody.Text;
                lIssue.CreationDateTime    = DateTime.UtcNow;
                lIssue.LastUpdatedDateTime = DateTime.UtcNow;
                lIssue.OpenedByUser        = lDataContext.CurrentUser;
                lIssue.IsOpen              = true;
                lDataContext.Issues.InsertOnSubmit(lIssue);

                foreach (var lLabel in this.mSelectedLabels)
                {
                    var lIssueLabel = new IssueLabel();
                    lIssueLabel.Issue   = lIssue;
                    lIssueLabel.LabelId = lLabel.Id;

                    lDataContext.IssueLabels.InsertOnSubmit(lIssueLabel);
                }

                lDataContext.SubmitChanges();

                this.IssueCreated.Fire(this, ReadOnlyValueEventArgs.Create(lIssue));
            }
        }
示例#2
0
        //TODO: Extract method in base class because it is duplicated in the ProjectService
        private void AddLabels(IEnumerable <Label> labels, Issue issue)
        {
            foreach (var label in labels)
            {
                var labelEntity = this.data.LabelRepository.Get(l => l.Name == label.Name).FirstOrDefault();
                if (labelEntity == null)
                {
                    labelEntity = new Label()
                    {
                        Name = label.Name
                    };
                    this.data.LabelRepository.Insert(labelEntity);
                }

                var issueLabel = new IssueLabel()
                {
                    Label = labelEntity,
                    Issue = issue
                };

                //var projectLabelEntity = this.data.ProjectLabelsRepository.Get(e => e.LabelId == labelEntity.Id
                //                                                            && e.ProjectId == project.Id).FirstOrDefault();
                //if (projectLabelEntity == null)
                issue.IssueLabels.Add(issueLabel);
            }
        }
示例#3
0
        public static Issue CreateIssue(int projectId,
                                        string issueTitle,
                                        string issueDescription,
                                        string issueAssignee,
                                        IssueLabel issueLabel   = IssueLabel.Task,
                                        IssueStatus issueStatus = IssueStatus.ToDo
                                        )
        {
            Issue issue = new Issue
            {
                ProjectId        = projectId,
                IssueTitle       = issueTitle,
                IssueDescription = issueDescription,
                IssueStatus      = issueStatus,
                IssueLabel       = issueLabel,
                IssueAssignee    = issueAssignee,
                Deleted          = false
            };

            db.Issues.Add(issue);
            db.SaveChanges();
            return(issue);
        }
        public async Task <IActionResult> Create([FromBody] IssueCreateDto dto)
        {
            var userId = User.GetUserId();
            var user   = await _repo.GetUser(userId);

            if (user == null)
            {
                return(NotFound(new { message = "User not found" }));
            }

            var project = await _repo.GetProject(dto.ProjectId, userId);

            if (project == null)
            {
                return(NotFound(new { message = "Project not found." }));
            }

            var phase = project.Phases.FirstOrDefault(p => p.Id == dto.PhaseId);

            if (phase == null)
            {
                return(NotFound(new { message = "Phase not found." }));
            }

            var issue = _mapper.Map <Issue>(dto);

            issue.CreatedById = userId;
            issue.CreatedAt   = DateTime.Today.ToShortDateString();
            issue.PhaseId     = dto.PhaseId;
            issue.Status      = Status.TO_DO;

            _repo.Add(issue);

            if (dto.Labels != null)
            {
                foreach (var id in dto.Labels)
                {
                    var label = await _repo.GetLabel(id);

                    var il = new IssueLabel
                    {
                        IssueId = issue.Id,
                        LabelId = label.Id,
                        Issue   = issue,
                        Label   = label
                    };
                    issue.IssueLabels.Add(il);
                }
            }


            foreach (var id in dto.IssuedTo)
            {
                var iu = new IssueUser
                {
                    IssueId = issue.Id,
                    UserId  = id
                };
                issue.IssuedTo.Add(iu);
            }


            if (await _repo.SaveAll())
            {
                var issueToReturn = _mapper.Map <IssueListItemDto>(issue);
                return(Ok(new { message = "Successfully created the issue", issue = issueToReturn }));
            }

            return(BadRequest(new { message = "Error saving the issue." }));
        }