private async Task UpdateIssueTypes(Project project, List <IssueType> types)
        {
            for (int i = 0; i < types.Count; i++)
            {
                var existingType =
                    await _issueTypeRepository
                    .FindByCondition(x =>
                                     x.Name == types[i].Name && x.ProjectId == project.Id)
                    .SingleOrDefaultAsync().ConfigureAwait(false);

                if (existingType != null)
                {
                    types[i] = existingType;
                    continue;
                }
                else
                {
                    var newType = new IssueType {
                        Id = Guid.NewGuid(), Name = types[i].Name, ProjectId = project.Id
                    };
                    await _issueTypeRepository.CreateAsync(newType).ConfigureAwait(false);
                }
            }
            project.Types = types;
            _projectRepository.Update(project);
            await _projectRepository.SaveAsync().ConfigureAwait(false);

            await _issueTypeRepository.SaveAsync().ConfigureAwait(false);
        }
Exemple #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);
        }
        public async Task <(List <IssueType> list, int count)> GetAllIssueTypesByProjectAsync(Guid projectId, PaginationFilter paginationFilter = null)
        {
            var queryable = _issueTypeRepository
                            .FindByCondition(x => x.ProjectId == projectId);
            List <IssueType> issueTypes;
            var count = await queryable.CountAsync().ConfigureAwait(false);

            if (paginationFilter == null)
            {
                issueTypes = await queryable
                             .ToListAsync()
                             .ConfigureAwait(false);
            }
            else
            {
                var skip = (paginationFilter.PageNumber - 1) * paginationFilter.PageSize;
                issueTypes = await queryable
                             .Skip(skip)
                             .Take(paginationFilter.PageSize)
                             .ToListAsync()
                             .ConfigureAwait(false);
            }
            return(list : issueTypes, count);
        }