public void Save(IEnumerable<RedmineProject> entities) { var projectEntities = entities.Select(project => new ProjectEntity { ExternalId = project.Id, Name = project.Name, Description = project.Description, BegintDate = project.CreatedOn }); foreach (var projectEntity in projectEntities) { var sourceProject = _dbContext.Projects.FirstOrDefault(project => project.ExternalId == projectEntity.ExternalId); if (sourceProject == null) { _dbContext.Projects.Add(projectEntity); } else { sourceProject.Name = projectEntity.Name; sourceProject.BegintDate = projectEntity.BegintDate; sourceProject.Description = projectEntity.Description; _dbContext.Projects.Update(sourceProject); } } _dbContext.SaveChanges(); }
public void Save(IEnumerable <RedmineIssueStatus> entities) { var issueStatuses = entities.Select(status => new IssueStatusEntity { ExternalId = status.Id, Name = status.Name }); foreach (var statusEntity in issueStatuses) { var sourceStatus = _dbContext.IssueStatuses.FirstOrDefault(project => project.ExternalId == statusEntity.ExternalId); if (sourceStatus == null) { _dbContext.IssueStatuses.Add(statusEntity); } else { sourceStatus.Name = statusEntity.Name; _dbContext.IssueStatuses.Update(sourceStatus); } } _dbContext.SaveChanges(); }
public void Save(IEnumerable <RedmineEmployee> entities) { var employeeEntities = entities.Select(user => new EmployeeEntity { ExternalId = user.Id, Login = user.Login, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName }); foreach (var employeeEntity in employeeEntities) { var sourceEmployee = _dbContext.Employees.FirstOrDefault(employee => employee.ExternalId == employeeEntity.ExternalId); if (sourceEmployee == null) { _dbContext.Employees.Add(employeeEntity); } else { sourceEmployee.FirstName = employeeEntity.FirstName; sourceEmployee.LastName = employeeEntity.LastName; sourceEmployee.Email = employeeEntity.Email; sourceEmployee.Login = employeeEntity.Login; _dbContext.Employees.Update(sourceEmployee); } } _dbContext.SaveChanges(); }
public void Save(IEnumerable <RedmineTimeRecord> entities) { var timeRecords = entities.Where(entity => entity.Issue != null).Select(timeRecord => new TimeRecordEntity { ExternalId = timeRecord.Id, Hours = timeRecord.Hours, Comments = timeRecord.Comments, Activity = timeRecord.Activity?.Name, Date = timeRecord.SpentOn, Employee = _dbContext.Employees.FirstOrDefault(employee => employee.ExternalId == timeRecord.User.Id), Issue = _dbContext.Issues.FirstOrDefault(issue => issue.ExternalId == timeRecord.Issue.Id) }) .Where(timeRecord => timeRecord.Issue != null && timeRecord.Employee != null); foreach (var timeRecordEntity in timeRecords) { var sourceTimeRecord = _dbContext.TimeRecords.FirstOrDefault(timeRecord => timeRecord.ExternalId == timeRecordEntity.ExternalId); if (sourceTimeRecord == null) { _dbContext.TimeRecords.Add(timeRecordEntity); } else { sourceTimeRecord.Activity = timeRecordEntity.Activity; sourceTimeRecord.Comments = timeRecordEntity.Comments; sourceTimeRecord.Date = timeRecordEntity.Date; sourceTimeRecord.Hours = timeRecordEntity.Hours; _dbContext.TimeRecords.Update(sourceTimeRecord); } } _dbContext.SaveChanges(); }
public PaymentRecord Add(Guid projectId, int?projectVersionId, DateTime date, decimal amount) { var paymentRecord = new PaymentRecordEntity { ProjectId = projectId, ProjectVersionId = projectVersionId, Date = date, Amount = amount }; _dbContext.Payments.Add(paymentRecord); _dbContext.SaveChanges(); return(new PaymentRecord { Id = paymentRecord.Id, ProjectVersionId = paymentRecord.ProjectVersionId, Date = paymentRecord.Date, Amount = paymentRecord.Amount }); }
public void Save(IEnumerable <RedmineIssue> entities) { var projectVersionIds = _dbContext.ProjectVersions.Select(i => i.ExternalId).ToList(); var issues = entities.Where(i => i.ProjectVersion == null || projectVersionIds.Contains(i.ProjectVersion.Id)).Select(issue => new IssueEntity { ExternalId = issue.Id, Priority = issue.Priority?.Name, Description = issue.Description, StartDate = issue.StartDate.Date, Author = issue.Author?.Name, AssignedTo = issue.AssignedTo?.Name, IssueStatus = _dbContext.IssueStatuses.FirstOrDefault(i => i.ExternalId == issue.Status.Id), Project = _dbContext.Projects.FirstOrDefault(p => p.ExternalId == issue.Project.Id), ProjectVersion = _dbContext.ProjectVersions.ToArray().FirstOrDefault(pv => pv.ExternalId == issue.ProjectVersion?.Id) }); foreach (var issueEntity in issues) { var sourceIssue = _dbContext.Issues.FirstOrDefault(issue => issue.ExternalId == issueEntity.ExternalId); if (sourceIssue == null) { _dbContext.Issues.Add(issueEntity); _dbContext.SaveChanges(); } else { sourceIssue.Priority = issueEntity.Priority; sourceIssue.Description = issueEntity.Description; sourceIssue.AssignedTo = issueEntity.AssignedTo; _dbContext.Issues.Update(sourceIssue); } } _dbContext.SaveChanges(); }
public void UpdateProject(Project projectInfo) { var project = _dbContext.Projects.FirstOrDefault(i => i.Id == projectInfo.Id); if (project == null) { throw new ArgumentException(nameof(projectInfo)); } project.Name = projectInfo.Name ?? project.Name; project.Currency = projectInfo.Currency != CurrencyTypes.Undefined ? projectInfo.Currency : project.Currency; _dbContext.SaveChanges(); }
public void UpdateTimeRecordResource(Guid timeRecordId, string resourceName) { var timeRecord = _dbContext.TimeRecords .Include(i => i.Resources) .ThenInclude(i => i.Resource) .Single(i => i.Id == timeRecordId); var timeRecordResources = timeRecord.Resources.ToArray(); foreach (var resource in timeRecordResources.Where(resource => resource.Resource.Name != resourceName)) { timeRecord.Resources.Remove(resource); } _dbContext.TimeRecords.Update(timeRecord); _dbContext.SaveChanges(); }
public void Save(IEnumerable <RedmineVersion> entities) { var redmineVersions = entities as RedmineVersion[] ?? entities.ToArray(); var openVersions = redmineVersions.Where(i => i.Status == "open").ToList(); var recentlyClosedVersions = redmineVersions.Where(i => i.Status == "closed").OrderByDescending(i => i.CreatedOn).Take(3); var versions = openVersions.Union(recentlyClosedVersions).Select(version => new ProjectVersionEntity { ExternalId = version.Id, Name = version.Name, Status = version.Status, Description = version.Description, CreatedOn = version.CreatedOn, Project = _dbContext.Projects.FirstOrDefault(p => p.ExternalId == version.Project.Id) }); foreach (var versionEntity in versions) { var sourceVersion = _dbContext.ProjectVersions.FirstOrDefault(version => version.ExternalId == versionEntity.ExternalId); if (sourceVersion == null) { _dbContext.ProjectVersions.Add(versionEntity); } else { sourceVersion.Name = versionEntity.Name; sourceVersion.Status = versionEntity.Status; sourceVersion.Description = versionEntity.Description; sourceVersion.CreatedOn = versionEntity.CreatedOn; _dbContext.ProjectVersions.Update(sourceVersion); } } _dbContext.SaveChanges(); }
private static void UpdateTimeRecords(IEnumerable <SoldResourceEntity> resources) { var resourceTimeRecords = resources.Select(resource => new { Resource = resource, TimeRecords = resource.Employees.SelectMany(i => i.Employee.TimeRecords.Where(tr => { if (tr.Resources.Any()) { return(false); } if (tr.Issue.ProjectVersion != null) { return(tr.Issue.ProjectVersion.Id == resource.ProjectVersion.Id); } return(tr.Issue.Project.Id == resource.Project.Id); })) .ToList() }) .ToArray(); foreach (var resourceTimeRecord in resourceTimeRecords) { resourceTimeRecord.TimeRecords.ForEach(timeRecord => { timeRecord.Resources.Add(new ResourceTimeRecordEntity { Resource = resourceTimeRecord.Resource, TimeRecord = timeRecord }); _dbContext.Update(timeRecord); _dbContext.SaveChanges(); }); } }