public async Task <bool> CreateIssueIssueTypeAsync(IssueIssueType issueIssueType)
        {
            if (issueIssueType == null)
            {
                return(false);
            }

            await _issueIssueTypeRepository.CreateAsync(issueIssueType).ConfigureAwait(false);

            var created = await _issueIssueTypeRepository.SaveAsync().ConfigureAwait(false);

            return(created > 0);
        }
Esempio n. 2
0
        /*private async Task AddIssueTypes(Issue issue)
         * {
         *  foreach (var type in issue.Types)
         *  {
         *      var existingIssueType =
         *          await _dataContext.IssueTypes.SingleOrDefaultAsync(x =>
         *              x.Name == type.Name && x.ProjectId == type.ProjectId).ConfigureAwait(false);
         *      if (existingIssueType != null)
         *          continue;
         *
         *      await _dataContext.IssueTypes.AddAsync(new IssueType
         *      { Name = type.Name, ProjectId = issue.ProjectId });
         *  }
         * }*/

        private async Task AddIssueTypes(Issue issue, List <IssueType> types)
        {
            List <IssueIssueType> newTypes = new List <IssueIssueType> {
            };

            foreach (var type in types)
            {
                var existingType =
                    await _issueTypeRepository
                    .FindByCondition(x =>
                                     x.Name == type.Name && x.ProjectId == issue.ProjectId)
                    .SingleOrDefaultAsync().ConfigureAwait(false);

                if (existingType != null)
                {
                    continue;
                }
                else
                {
                    var newType = new IssueType {
                        Id = Guid.NewGuid(), Name = type.Name, ProjectId = issue.ProjectId
                    };
                    await _issueTypeRepository.CreateAsync(newType).ConfigureAwait(false);

                    newTypes.Add(new IssueIssueType {
                        Issue = issue, IssueType = newType
                    });
                }
            }
            await _issueIssueTypeRepository.AddRangeAsync(newTypes).ConfigureAwait(false);

            await _issueIssueTypeRepository.SaveAsync().ConfigureAwait(false);

            await _issueTypeRepository.SaveAsync().ConfigureAwait(false);
        }