Skip to content

Commit

Permalink
Массовый коммент всего что есть, чтобы разобраться с проблемой FK Cas…
Browse files Browse the repository at this point in the history
…cadeDelete - почему он ругался при select ???

Определена связь между QuestionAswer - MToM.

Вылезло npgsql/npgsql#1439 после установки VSIX.
  • Loading branch information
zamachuga committed Jul 20, 2020
1 parent 530e137 commit 296c6a7
Show file tree
Hide file tree
Showing 20 changed files with 650 additions and 365 deletions.
7 changes: 6 additions & 1 deletion KnowledgeTesting/BL/DAO/Answer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ namespace KnowledgeTesting.BL.DAO
/// </summary>
public class Answer
{
public Answer()
{
Questions = new List<Question>();
}

public int Id { get; set; }
public string Text { get; set; }
public List<Question> Questions { get; set; }
public ICollection<Question> Questions { get; set; }
}
}
10 changes: 1 addition & 9 deletions KnowledgeTesting/BL/DAO/Question.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ public class Question
{
public Question()
{
Tests = new List<Test>();
Answers = new List<Answer>();
}

public int Id { get; set; }
public string Text { get; set; }
/// <summary>
/// Тесты в которых участвует вопрос.
/// </summary>
public List<Test> Tests { get; set; }
/// <summary>
/// Ответы на вопрос.
/// </summary>
public List<Answer> Answers { get; set; }
public ICollection<Answer> Answers { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
namespace KnowledgeTesting.BL.DAO
{
/// <summary>
/// Ответы на вопрос.
/// Ответ на вопрос.
/// </summary>
public class QuestionAnswers
public class QuestionAnswer
{
public int Id { get; set; }
public Question Question { get; set; }
public Answer Answer { get; set; }
/// <summary>
/// True - правильный ответ на вопрос.
/// </summary>
public bool IsCorrect { get; set; }
}
}
2 changes: 0 additions & 2 deletions KnowledgeTesting/BL/DAO/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ public class Test
{
public Test()
{
Questions = new List<Question>();
}

public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public List<Question> Questions { get; private set; }
}
}
17 changes: 17 additions & 0 deletions KnowledgeTesting/BL/DAO/TestQuestion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace KnowledgeTesting.BL.DAO
{
/// <summary>
/// Вопрос теста.
/// </summary>
public class TestQuestion
{
public int Id { get; set; }
public Test Test { get; set; }
public Question Question { get; set; }
}
}
16 changes: 4 additions & 12 deletions KnowledgeTesting/BL/DB/PgSql/ClassDbPgSqlContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ namespace KnowledgeTesting.BL.DB.PgSql
/// </summary>
public class ClassDbPgSqlContext : DbContext
{
public DbSet<DAO.Question> Questions { get; set; }
public DbSet<DAO.Test> Tests { get; set; }
public DbSet<DAO.Answer> Answers { get; set; }
public DbSet<DAO.Question> Questions { get; set; }
//public DbSet<DAO.Test> Tests { get; set; }
//public DbSet<DAO.QuestionAnswer> QuestionAnswers { get; set; }
//public DbSet<DAO.TestQuestion> TestQuestions { get; set; }

public ClassDbPgSqlContext() : base("NpgsqlConnectionString") { }

Expand All @@ -22,16 +24,6 @@ public class ClassDbPgSqlContext : DbContext
/// <param name="modelBuilder">Конструктор моделей в БД.</param>
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Ответы и вопросы многие-ко-многим.
modelBuilder.Entity<DAO.Question>()
.HasMany(x => x.Answers)
.WithMany(x => x.Questions)
.Map(
m =>
{
m.ToTable("QuestionAnswers");
}
);
}
}
}
138 changes: 69 additions & 69 deletions KnowledgeTesting/Controllers/TestManagementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,74 +13,74 @@ namespace KnowledgeTesting.Controllers
{
public class TestManagementController : Controller
{
BL.TestManagement _TestManagement = new BL.TestManagement();
BL.DB.PgSql.ClassDbPgSqlContext _DbContext = new BL.DB.PgSql.ClassDbPgSqlContext();

public ActionResult Index(TestsViewModel Model)
{
return View(Model);
}

public ActionResult CreateTest(CreateTestModel Model)
{
CreateTestModel _Model = Model;

ViewBag.Questions = new SelectList(GetQuestionsDtoModels(), "Id", "Text");

return View(Model);
}

/// <summary>
/// Добавить вопрос в тест.
/// </summary>
/// <param name="Model"></param>
/// <returns></returns>
public ActionResult AddQuestion(CreateTestModel Model)
{
CreateTestModel _Model = Model;

string _Notification = "";

DTO.Question _Question = GetQuestionsDtoModels().First(x => x.Id == _Model.SelectedQuestionId);
_Model.Test.Questions.Add(_Question);

_Model.Notification = _Notification;

return CreateTest(_Model);
}

public ActionResult SaveNewTest(CreateTestModel Model)
{
CreateTestModel _Model = Model;
string _Notification = "";

if (_TestManagement.CheckTestData(_Model.Test, out _Notification))
{
_Notification = $"Тест <{_Model.Test.Name}> сохранен.";
}

_Model.Notification = _Notification;

return CreateTest(_Model);
}

public string GetQuestions()
{
DTO.Question[] _Questions = GetQuestionsDtoModels();
return JsonConvert.SerializeObject(_Questions);
}

private DTO.Question[] GetQuestionsDtoModels()
{
DTO.Question[] _Questions = _DbContext.Questions.Select(
x => new DTO.Question()
{
Id = x.Id,
Text = x.Text
}
).ToArray();

return _Questions;
}
//BL.TestManagement _TestManagement = new BL.TestManagement();
//BL.DB.PgSql.ClassDbPgSqlContext _DbContext = new BL.DB.PgSql.ClassDbPgSqlContext();

//public ActionResult Index(TestsViewModel Model)
//{
// return View(Model);
//}

//public ActionResult CreateTest(CreateTestModel Model)
//{
// CreateTestModel _Model = Model;

// ViewBag.Questions = new SelectList(GetQuestionsDtoModels(), "Id", "Text");

// return View(Model);
//}

///// <summary>
///// Добавить вопрос в тест.
///// </summary>
///// <param name="Model"></param>
///// <returns></returns>
//public ActionResult AddQuestion(CreateTestModel Model)
//{
// CreateTestModel _Model = Model;

// string _Notification = "";

// DTO.Question _Question = GetQuestionsDtoModels().First(x => x.Id == _Model.SelectedQuestionId);
// _Model.Test.Questions.Add(_Question);

// _Model.Notification = _Notification;

// return CreateTest(_Model);
//}

//public ActionResult SaveNewTest(CreateTestModel Model)
//{
// CreateTestModel _Model = Model;
// string _Notification = "";

// if (_TestManagement.CheckTestData(_Model.Test, out _Notification))
// {
// _Notification = $"Тест <{_Model.Test.Name}> сохранен.";
// }

// _Model.Notification = _Notification;

// return CreateTest(_Model);
//}

//public string GetQuestions()
//{
// DTO.Question[] _Questions = GetQuestionsDtoModels();
// return JsonConvert.SerializeObject(_Questions);
//}

//private DTO.Question[] GetQuestionsDtoModels()
//{
// DTO.Question[] _Questions = _DbContext.Questions.Select(
// x => new DTO.Question()
// {
// Id = x.Id,
// Text = x.Text
// }
// ).ToArray();

// return _Questions;
//}
}
}
21 changes: 14 additions & 7 deletions KnowledgeTesting/KnowledgeTesting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@
<HintPath>..\packages\EntityFramework6.Npgsql.6.4.1\lib\net461\EntityFramework6.Npgsql.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.1.1.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Npgsql, Version=4.1.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.4.1.3\lib\net461\Npgsql.dll</HintPath>
<Reference Include="Npgsql, Version=4.1.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL">
<HintPath>..\packages\Npgsql.4.1.4\lib\net461\Npgsql.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.12.0\lib\net45\nunit.framework.dll</HintPath>
Expand Down Expand Up @@ -170,14 +170,12 @@
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="BL\DAO\Answer.cs" />
<Compile Include="BL\DAO\Interviewee.cs" />
<Compile Include="BL\DAO\Question.cs" />
<Compile Include="BL\DAO\QuestionAnswers.cs" />
<Compile Include="BL\DAO\QuestionAnswer.cs" />
<Compile Include="BL\DAO\Test.cs" />
<Compile Include="BL\DAO\TestQuestion.cs" />
<Compile Include="BL\DTO\Question.cs" />
<Compile Include="BL\DTO\Test.cs" />
<Compile Include="BL\TestManagement.cs" />
<Compile Include="BL\DAO\Testing.cs" />
<Compile Include="BL\DB\PgSql\ClassDbPgSqlContext.cs" />
<Compile Include="BL\Utils.cs" />
<Compile Include="Controllers\TestManagementController.cs" />
Expand All @@ -186,6 +184,10 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Migrations\202007201459338_AnswerQuestion_MToM.cs" />
<Compile Include="Migrations\202007201459338_AnswerQuestion_MToM.designer.cs">
<DependentUpon>202007201459338_AnswerQuestion_MToM.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\Configuration.cs" />
<Compile Include="Models\CreateTestModel.cs" />
<Compile Include="Models\TestsViewModel.cs" />
Expand Down Expand Up @@ -357,6 +359,11 @@
<ItemGroup>
<Service Include="{4A0DDDB5-7A95-4FBF-97CC-616D07737A77}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Migrations\202007201459338_AnswerQuestion_MToM.resx">
<DependentUpon>202007201459338_AnswerQuestion_MToM.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 296c6a7

Please sign in to comment.