Skip to content

Commit

Permalink
NullReferenceException on delete/edit fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
xtenzQ committed Mar 12, 2019
1 parent a2544eb commit cbcf571
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ResearchersWPF.Data/Managers/ReportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public List<Report> FindByResearcher(int researcherId)
using (var context = new ResDbContext())
{
context.ChangeTracker.AutoDetectChangesEnabled = false;

return context.Reports.Where(s => s.ResearcherId == researcherId).ToList();
//return context.Researchers.First(i => i.Id == researcherId).Reports.ToList();
}
Expand All @@ -64,6 +63,7 @@ public Report Find(int reportId)
{
using (var context = new ResDbContext())
{
//return context.Reports.FirstOrDefault(i => i.Id == reportId);
return context.Reports.First(i => i.Id == reportId);
}
}
Expand Down
9 changes: 5 additions & 4 deletions ResearchersWPF.Data/Managers/ResearcherManager.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using ResearchersWPF.Data.IManagers;
using ResearchersWPF.Data.Model;

Expand Down Expand Up @@ -67,31 +68,31 @@ public Researcher FindByArticle(int articleId)
{
using (var context = new ResDbContext())
{
return context.Articles.First(i => i.Id == articleId).Researcher;
return context.Articles.Include(i => i.Researcher).FirstOrDefault(i => i.Id == articleId)?.Researcher;
}
}

public Researcher FindByMonograph(int monographId)
{
using (var context = new ResDbContext())
{
return context.Monographs.First(i => i.Id == monographId).Researcher;
return context.Monographs.Include(i => i.Researcher).FirstOrDefault(i => i.Id == monographId)?.Researcher;
}
}

public Researcher FindByPresentation(int presentationId)
{
using (var context = new ResDbContext())
{
return context.Presentations.First(i => i.Id == presentationId).Researcher;
return context.Presentations.Include(i => i.Researcher).FirstOrDefault(i => i.Id == presentationId)?.Researcher;
}
}

public Researcher FindByReport(int reportId)
{
using (var context = new ResDbContext())
{
return context.Reports.First(i => i.Id == reportId).Researcher;
return context.Reports.Include(i => i.Researcher).FirstOrDefault(i => i.Id == reportId)?.Researcher;
}
}
}
Expand Down
Binary file modified ResearchersWPF.Service/App_Data/Researchers.db
Binary file not shown.
4 changes: 0 additions & 4 deletions ResearchersWPF.Service/ResearchersWPF.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
<Project>{d7b00cc2-0c31-47ec-9250-6c42580d0b98}</Project>
<Name>ResearchersWPF.Business</Name>
</ProjectReference>
<ProjectReference Include="..\ResearchersWPF.Data\ResearchersWPF.Data.csproj">
<Project>{3b27ae7e-a295-401c-801f-19822eb9ea1f}</Project>
<Name>ResearchersWPF.Data</Name>
</ProjectReference>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
2 changes: 1 addition & 1 deletion ResearchersWPF.UI/View/ArticleListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</Button>
</ToolBar>
</ToolBarTray>
<DataGrid Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvArticleList" ItemsSource="{Binding Articles}">
<DataGrid GridLinesVisibility="None" Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvArticleList" ItemsSource="{Binding Articles}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Название статьи" Binding="{Binding Path=Name }"/>
<DataGridTextColumn Width="*" Header="Название журнала" Binding="{Binding Path=MagazineName }"/>
Expand Down
2 changes: 1 addition & 1 deletion ResearchersWPF.UI/View/MonographListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvMonographList" ItemsSource="{Binding Monographs}">
<DataGrid GridLinesVisibility="None" Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvMonographList" ItemsSource="{Binding Monographs}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Название" Binding="{Binding Path=Name}"/>
<DataGridTextColumn Width="*" Header="Фамилия соавтора" Binding="{Binding Path=CoauthorLastName }"/>
Expand Down
2 changes: 1 addition & 1 deletion ResearchersWPF.UI/View/PresentationListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvPresentationList" ItemsSource="{Binding Presentations}">
<DataGrid GridLinesVisibility="None" Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvPresentationList" ItemsSource="{Binding Presentations}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Название" Binding="{Binding Path=Name }"/>
<DataGridTextColumn Width="*" Header="Название конференции" Binding="{Binding Path=ConferenceName }"/>
Expand Down
2 changes: 1 addition & 1 deletion ResearchersWPF.UI/View/ReportListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvReportList" ItemsSource="{Binding Reports}">
<DataGrid GridLinesVisibility="None" Background="White" IsReadOnly="True" Grid.Column="0" Grid.Row="0" CanUserAddRows="False" AutoGenerateColumns="False" Height="auto" SelectionMode="Single" x:Name="lsvReportList" ItemsSource="{Binding Reports}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Название" Binding="{Binding Path=Name }"/>
<DataGridTextColumn Width="*" Header="Регистрационный номер" Binding="{Binding Path=RegisterNumber }"/>
Expand Down
2 changes: 1 addition & 1 deletion ResearchersWPF.UI/View/ResearcherListView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<DataGrid Background="White" Grid.Column="0" Grid.Row="0" SelectionMode="Single" CanUserAddRows="False" IsReadOnly="True" AutoGenerateColumns="False" Height="auto" x:Name="lsvResearcherList" ItemsSource="{Binding ResearcherList}" SelectedItem="{Binding SelectedResearcher}">
<DataGrid GridLinesVisibility="None" Background="White" Grid.Column="0" Grid.Row="0" SelectionMode="Single" CanUserAddRows="False" IsReadOnly="True" AutoGenerateColumns="False" Height="auto" x:Name="lsvResearcherList" ItemsSource="{Binding ResearcherList}" SelectedItem="{Binding SelectedResearcher}">
<DataGrid.Columns>
<DataGridTextColumn Width="*" Header="Фамилия" Binding="{Binding Path=LastName }"/>
<DataGridTextColumn Width="*" Header="Имя" Binding="{Binding Path=FirstName}"/>
Expand Down

0 comments on commit cbcf571

Please sign in to comment.