Ver código fonte

Сделана история ответов
Доделан профиль
Юнит тестики?

Imagara 2 anos atrás
pai
commit
0ecce1ff19

+ 25 - 0
MyTests/Answers.cs

@@ -0,0 +1,25 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Этот код создан по шаблону.
+//
+//     Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+//     Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MyTests
+{
+    using System;
+    using System.Collections.Generic;
+    
+    public partial class Answers
+    {
+        public int IdUserAnswer { get; set; }
+        public int IdQuestion { get; set; }
+        public int IdUser { get; set; }
+        public string Answer { get; set; }
+    
+        public virtual Questions Questions { get; set; }
+        public virtual Users Users { get; set; }
+    }
+}

+ 2 - 0
MyTests/EDM.Context.cs

@@ -28,5 +28,7 @@ namespace MyTests
         public virtual DbSet<Questions> Questions { get; set; }
         public virtual DbSet<Tests> Tests { get; set; }
         public virtual DbSet<Users> Users { get; set; }
+        public virtual DbSet<sysdiagrams> sysdiagrams { get; set; }
+        public virtual DbSet<Answers> Answers { get; set; }
     }
 }

+ 199 - 68
MyTests/EDM.edmx

@@ -4,74 +4,127 @@
   <edmx:Runtime>
     <!-- SSDL content -->
     <edmx:StorageModels>
-    <Schema Namespace="MyTestsDataBaseModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2012" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
-  <EntityContainer Name="MyTestsDataBaseModelStoreContainer">
-    <EntitySet Name="Questions" EntityType="MyTestsDataBaseModel.Store.Questions" store:Type="Tables" Schema="dbo" />
-    <EntitySet Name="Tests" EntityType="MyTestsDataBaseModel.Store.Tests" store:Type="Tables" Schema="dbo" />
-    <EntitySet Name="Users" EntityType="MyTestsDataBaseModel.Store.Users" store:Type="Tables" Schema="dbo" />
-    <AssociationSet Name="FK_Questions_Tests" Association="MyTestsDataBaseModel.Store.FK_Questions_Tests">
-      <End Role="Tests" EntitySet="Tests" />
-      <End Role="Questions" EntitySet="Questions" />
-    </AssociationSet>
-    <AssociationSet Name="FK_Tests_Users" Association="MyTestsDataBaseModel.Store.FK_Tests_Users">
-      <End Role="Users" EntitySet="Users" />
-      <End Role="Tests" EntitySet="Tests" />
-    </AssociationSet>
-  </EntityContainer>
-  <EntityType Name="Questions">
-    <Key>
-      <PropertyRef Name="IdQuestion" />
-    </Key>
-    <Property Name="IdQuestion" Type="int" Nullable="false" />
-    <Property Name="IdTest" Type="int" Nullable="false" />
-    <Property Name="Content" Type="nvarchar" Nullable="false" MaxLength="150" />
-    <Property Name="Answer" Type="nvarchar" Nullable="false" MaxLength="150" />
-  </EntityType>
-  <EntityType Name="Tests">
-    <Key>
-      <PropertyRef Name="IdTest" />
-    </Key>
-    <Property Name="IdTest" Type="int" Nullable="false" />
-    <Property Name="IdUser" Type="int" Nullable="false" />
-    <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="150" />
-    <Property Name="Image" Type="varbinary(max)" Nullable="true" />
-  </EntityType>
-  <EntityType Name="Users">
-    <Key>
-      <PropertyRef Name="IdUser" />
-    </Key>
-    <Property Name="IdUser" Type="int" Nullable="false" />
-    <Property Name="Login" Type="nvarchar" Nullable="false" MaxLength="50" />
-    <Property Name="Password" Type="nvarchar" Nullable="false" MaxLength="50" />
-    <Property Name="Email" Type="nvarchar" Nullable="false" MaxLength="50" />
-    <Property Name="Info" Type="nvarchar" Nullable="true" MaxLength="50" />
-    <Property Name="Image" Type="varbinary(max)" Nullable="true" />
-  </EntityType>
-  <Association Name="FK_Questions_Tests">
-    <End Role="Tests" Type="MyTestsDataBaseModel.Store.Tests" Multiplicity="1" />
-    <End Role="Questions" Type="MyTestsDataBaseModel.Store.Questions" Multiplicity="*" />
-    <ReferentialConstraint>
-      <Principal Role="Tests">
-        <PropertyRef Name="IdTest" />
-      </Principal>
-      <Dependent Role="Questions">
-        <PropertyRef Name="IdTest" />
-      </Dependent>
-    </ReferentialConstraint>
-  </Association>
-  <Association Name="FK_Tests_Users">
-    <End Role="Users" Type="MyTestsDataBaseModel.Store.Users" Multiplicity="1" />
-    <End Role="Tests" Type="MyTestsDataBaseModel.Store.Tests" Multiplicity="*" />
-    <ReferentialConstraint>
-      <Principal Role="Users">
-        <PropertyRef Name="IdUser" />
-      </Principal>
-      <Dependent Role="Tests">
-        <PropertyRef Name="IdUser" />
-      </Dependent>
-    </ReferentialConstraint>
-  </Association>
-</Schema></edmx:StorageModels>
+    <Schema Namespace="MyTestsDataBaseModel.Store" Provider="System.Data.SqlClient" ProviderManifestToken="2012" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
+        <EntityType Name="Answers">
+          <Key>
+            <PropertyRef Name="IdUserAnswer" />
+          </Key>
+          <Property Name="IdUserAnswer" Type="int" Nullable="false" />
+          <Property Name="IdQuestion" Type="int" Nullable="false" />
+          <Property Name="IdUser" Type="int" Nullable="false" />
+          <Property Name="Answer" Type="nvarchar" MaxLength="150" Nullable="false" />
+        </EntityType>
+        <EntityType Name="Questions">
+          <Key>
+            <PropertyRef Name="IdQuestion" />
+          </Key>
+          <Property Name="IdQuestion" Type="int" Nullable="false" />
+          <Property Name="IdTest" Type="int" Nullable="false" />
+          <Property Name="Content" Type="nvarchar" MaxLength="150" Nullable="false" />
+          <Property Name="Answer" Type="nvarchar" MaxLength="150" Nullable="false" />
+        </EntityType>
+        <EntityType Name="sysdiagrams">
+          <Key>
+            <PropertyRef Name="diagram_id" />
+          </Key>
+          <Property Name="name" Type="nvarchar" MaxLength="128" Nullable="false" />
+          <Property Name="principal_id" Type="int" Nullable="false" />
+          <Property Name="diagram_id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
+          <Property Name="version" Type="int" />
+          <Property Name="definition" Type="varbinary(max)" />
+        </EntityType>
+        <EntityType Name="Tests">
+          <Key>
+            <PropertyRef Name="IdTest" />
+          </Key>
+          <Property Name="IdTest" Type="int" Nullable="false" />
+          <Property Name="IdUser" Type="int" Nullable="false" />
+          <Property Name="Name" Type="nvarchar" MaxLength="150" Nullable="false" />
+          <Property Name="Image" Type="varbinary(max)" />
+        </EntityType>
+        <EntityType Name="Users">
+          <Key>
+            <PropertyRef Name="IdUser" />
+          </Key>
+          <Property Name="IdUser" Type="int" Nullable="false" />
+          <Property Name="Login" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Password" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Email" Type="nvarchar" MaxLength="50" Nullable="false" />
+          <Property Name="Info" Type="nvarchar" MaxLength="50" />
+          <Property Name="Image" Type="varbinary(max)" />
+        </EntityType>
+        <Association Name="FK_Answers_Questions">
+          <End Role="Questions" Type="Self.Questions" Multiplicity="1" />
+          <End Role="Answers" Type="Self.Answers" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Questions">
+              <PropertyRef Name="IdQuestion" />
+            </Principal>
+            <Dependent Role="Answers">
+              <PropertyRef Name="IdQuestion" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        <Association Name="FK_Answers_Users">
+          <End Role="Users" Type="Self.Users" Multiplicity="1" />
+          <End Role="Answers" Type="Self.Answers" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Users">
+              <PropertyRef Name="IdUser" />
+            </Principal>
+            <Dependent Role="Answers">
+              <PropertyRef Name="IdUser" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        <Association Name="FK_Questions_Tests">
+          <End Role="Tests" Type="Self.Tests" Multiplicity="1" />
+          <End Role="Questions" Type="Self.Questions" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Tests">
+              <PropertyRef Name="IdTest" />
+            </Principal>
+            <Dependent Role="Questions">
+              <PropertyRef Name="IdTest" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        <Association Name="FK_Tests_Users">
+          <End Role="Users" Type="Self.Users" Multiplicity="1" />
+          <End Role="Tests" Type="Self.Tests" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Users">
+              <PropertyRef Name="IdUser" />
+            </Principal>
+            <Dependent Role="Tests">
+              <PropertyRef Name="IdUser" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        <EntityContainer Name="MyTestsDataBaseModelStoreContainer">
+          <EntitySet Name="Answers" EntityType="Self.Answers" Schema="dbo" store:Type="Tables" />
+          <EntitySet Name="Questions" EntityType="Self.Questions" Schema="dbo" store:Type="Tables" />
+          <EntitySet Name="sysdiagrams" EntityType="Self.sysdiagrams" Schema="dbo" store:Type="Tables" />
+          <EntitySet Name="Tests" EntityType="Self.Tests" Schema="dbo" store:Type="Tables" />
+          <EntitySet Name="Users" EntityType="Self.Users" Schema="dbo" store:Type="Tables" />
+          <AssociationSet Name="FK_Answers_Questions" Association="Self.FK_Answers_Questions">
+            <End Role="Questions" EntitySet="Questions" />
+            <End Role="Answers" EntitySet="Answers" />
+          </AssociationSet>
+          <AssociationSet Name="FK_Answers_Users" Association="Self.FK_Answers_Users">
+            <End Role="Users" EntitySet="Users" />
+            <End Role="Answers" EntitySet="Answers" />
+          </AssociationSet>
+          <AssociationSet Name="FK_Questions_Tests" Association="Self.FK_Questions_Tests">
+            <End Role="Tests" EntitySet="Tests" />
+            <End Role="Questions" EntitySet="Questions" />
+          </AssociationSet>
+          <AssociationSet Name="FK_Tests_Users" Association="Self.FK_Tests_Users">
+            <End Role="Users" EntitySet="Users" />
+            <End Role="Tests" EntitySet="Tests" />
+          </AssociationSet>
+        </EntityContainer>
+      </Schema></edmx:StorageModels>
     <!-- CSDL content -->
     <edmx:ConceptualModels>
       <Schema Namespace="MyTestsDataBaseModel" Alias="Self" annotation:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
@@ -84,6 +137,7 @@
           <Property Name="Content" Type="String" MaxLength="150" FixedLength="false" Unicode="true" Nullable="false" />
           <NavigationProperty Name="Tests" Relationship="Self.FK_Questions_Tests" FromRole="Questions" ToRole="Tests" />
           <Property Name="Answer" Type="String" Nullable="false" MaxLength="150" FixedLength="false" Unicode="true" />
+          <NavigationProperty Name="Answers" Relationship="MyTestsDataBaseModel.FK_Answers_Questions" FromRole="Questions" ToRole="Answers" />
         </EntityType>
         <EntityType Name="Tests">
           <Key>
@@ -107,6 +161,7 @@
           <Property Name="Info" Type="String" MaxLength="50" FixedLength="false" Unicode="true" />
           <Property Name="Image" Type="Binary" MaxLength="Max" FixedLength="false" />
           <NavigationProperty Name="Tests" Relationship="Self.FK_Tests_Users" FromRole="Users" ToRole="Tests" />
+          <NavigationProperty Name="Answers" Relationship="MyTestsDataBaseModel.FK_Answers_Users" FromRole="Users" ToRole="Answers" />
         </EntityType>
         <Association Name="FK_Questions_Tests">
           <End Role="Tests" Type="Self.Tests" Multiplicity="1" />
@@ -144,7 +199,62 @@
             <End Role="Users" EntitySet="Users" />
             <End Role="Tests" EntitySet="Tests" />
           </AssociationSet>
+          <EntitySet Name="sysdiagrams" EntityType="MyTestsDataBaseModel.sysdiagrams" />
+          <EntitySet Name="Answers" EntityType="MyTestsDataBaseModel.Answers" />
+          <AssociationSet Name="FK_Answers_Questions" Association="MyTestsDataBaseModel.FK_Answers_Questions">
+            <End Role="Questions" EntitySet="Questions" />
+            <End Role="Answers" EntitySet="Answers" />
+          </AssociationSet>
+          <AssociationSet Name="FK_Answers_Users" Association="MyTestsDataBaseModel.FK_Answers_Users">
+            <End Role="Users" EntitySet="Users" />
+            <End Role="Answers" EntitySet="Answers" />
+          </AssociationSet>
         </EntityContainer>
+        <EntityType Name="sysdiagrams">
+          <Key>
+            <PropertyRef Name="diagram_id" />
+          </Key>
+          <Property Name="name" Type="String" Nullable="false" MaxLength="128" FixedLength="false" Unicode="true" />
+          <Property Name="principal_id" Type="Int32" Nullable="false" />
+          <Property Name="diagram_id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
+          <Property Name="version" Type="Int32" />
+          <Property Name="definition" Type="Binary" MaxLength="Max" FixedLength="false" />
+        </EntityType>
+        <EntityType Name="Answers">
+          <Key>
+            <PropertyRef Name="IdUserAnswer" />
+          </Key>
+          <Property Name="IdUserAnswer" Type="Int32" Nullable="false" />
+          <Property Name="IdQuestion" Type="Int32" Nullable="false" />
+          <Property Name="IdUser" Type="Int32" Nullable="false" />
+          <Property Name="Answer" Type="String" Nullable="false" MaxLength="150" FixedLength="false" Unicode="true" />
+          <NavigationProperty Name="Questions" Relationship="MyTestsDataBaseModel.FK_Answers_Questions" FromRole="Answers" ToRole="Questions" />
+          <NavigationProperty Name="Users" Relationship="MyTestsDataBaseModel.FK_Answers_Users" FromRole="Answers" ToRole="Users" />
+        </EntityType>
+        <Association Name="FK_Answers_Questions">
+          <End Type="MyTestsDataBaseModel.Questions" Role="Questions" Multiplicity="1" />
+          <End Type="MyTestsDataBaseModel.Answers" Role="Answers" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Questions">
+              <PropertyRef Name="IdQuestion" />
+            </Principal>
+            <Dependent Role="Answers">
+              <PropertyRef Name="IdQuestion" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
+        <Association Name="FK_Answers_Users">
+          <End Type="MyTestsDataBaseModel.Users" Role="Users" Multiplicity="1" />
+          <End Type="MyTestsDataBaseModel.Answers" Role="Answers" Multiplicity="*" />
+          <ReferentialConstraint>
+            <Principal Role="Users">
+              <PropertyRef Name="IdUser" />
+            </Principal>
+            <Dependent Role="Answers">
+              <PropertyRef Name="IdUser" />
+            </Dependent>
+          </ReferentialConstraint>
+        </Association>
       </Schema>
     </edmx:ConceptualModels>
     <!-- C-S mapping content -->
@@ -183,6 +293,27 @@
         </MappingFragment>
       </EntityTypeMapping>
     </EntitySetMapping>
+          <EntitySetMapping Name="sysdiagrams">
+            <EntityTypeMapping TypeName="MyTestsDataBaseModel.sysdiagrams">
+              <MappingFragment StoreEntitySet="sysdiagrams">
+                <ScalarProperty Name="definition" ColumnName="definition" />
+                <ScalarProperty Name="version" ColumnName="version" />
+                <ScalarProperty Name="diagram_id" ColumnName="diagram_id" />
+                <ScalarProperty Name="principal_id" ColumnName="principal_id" />
+                <ScalarProperty Name="name" ColumnName="name" />
+              </MappingFragment>
+            </EntityTypeMapping>
+          </EntitySetMapping>
+          <EntitySetMapping Name="Answers">
+            <EntityTypeMapping TypeName="MyTestsDataBaseModel.Answers">
+              <MappingFragment StoreEntitySet="Answers">
+                <ScalarProperty Name="Answer" ColumnName="Answer" />
+                <ScalarProperty Name="IdUser" ColumnName="IdUser" />
+                <ScalarProperty Name="IdQuestion" ColumnName="IdQuestion" />
+                <ScalarProperty Name="IdUserAnswer" ColumnName="IdUserAnswer" />
+              </MappingFragment>
+            </EntityTypeMapping>
+          </EntitySetMapping>
   </EntityContainerMapping>
 </Mapping></edmx:Mappings>
   </edmx:Runtime>

+ 8 - 0
MyTests/EDM.edmx.diagram

@@ -10,6 +10,14 @@
         <EntityTypeShape EntityType="MyTestsDataBaseModel.Users" Width="1.5" PointX="0.75" PointY="1" IsExpanded="true" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Questions_Tests" ManuallyRouted="false" />
         <AssociationConnector Association="MyTestsDataBaseModel.FK_Tests_Users" ManuallyRouted="false" />
+        <EntityTypeShape EntityType="MyTestsDataBaseModel.sysdiagrams" Width="1.5" PointX="0.75" PointY="4.75" />
+        <EntityTypeShape EntityType="MyTestsDataBaseModel.Answers" Width="1.5" PointX="3.125" PointY="4" />
+        <AssociationConnector Association="MyTestsDataBaseModel.FK_Answers_Questions" />
+        <AssociationConnector Association="MyTestsDataBaseModel.FK_Answers_Users" ManuallyRouted="true" >
+          <ConnectorPoint PointX="1.5" PointY="3.5571907552083331" />
+          <ConnectorPoint PointX="1.5" PointY="4.4754490993496754" />
+          <ConnectorPoint PointX="3.125" PointY="4.4754490993496754" />
+        </AssociationConnector>
       </Diagram>
     </edmx:Diagrams>
   </edmx:Designer>

+ 13 - 0
MyTests/Functions.cs

@@ -41,5 +41,18 @@ namespace MyTests
         {
             return cnt.db.Users.Select(item => item.Login).Contains(login);
         }
+        // Валидация электронной почты
+        public static bool IsValidEmail(string email)
+        {
+            if (System.Text.RegularExpressions.Regex.IsMatch(email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
+                return true;
+            else
+                return false;
+        }
+        // Проверка на уникальность электронной почты
+        public static bool IsEmailAlreadyTaken(string Email)
+        {
+            return cnt.db.Users.Select(item => item.Email).Contains(Email);
+        }
     }
 }

+ 6 - 0
MyTests/MyTests.csproj

@@ -64,6 +64,9 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="Answers.cs">
+      <DependentUpon>EDM.tt</DependentUpon>
+    </Compile>
     <Compile Include="EDM.Context.cs">
       <AutoGen>True</AutoGen>
       <DesignTime>True</DesignTime>
@@ -99,6 +102,9 @@
     </Compile>
     <Compile Include="Session.cs" />
     <Compile Include="Styles\Style.cs" />
+    <Compile Include="sysdiagrams.cs">
+      <DependentUpon>EDM.tt</DependentUpon>
+    </Compile>
     <Compile Include="Tests.cs">
       <DependentUpon>EDM.tt</DependentUpon>
     </Compile>

+ 30 - 2
MyTests/Pages/CurTestPage.xaml.cs

@@ -25,13 +25,41 @@ namespace MyTests.Pages
 
         private void NextButton_Click(object sender, RoutedEventArgs e)
         {
+            try
+            {
+                string strContent = Session.Quest.Content[Session.CurQuestion];
+                string strAnswer = Session.Quest.Answer[Session.CurQuestion];
+                if (cnt.db.Answers.Select(item => item.IdQuestion + " " + item.IdUser).Contains(cnt.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault() + " " + Session.User.IdUser))
+                {
+                    Answers answer = cnt.db.Answers.Where(item => item.IdQuestion == cnt.db.Questions.Where(i => i.Content == strContent && i.Answer == strAnswer).Select(i => i.IdQuestion).FirstOrDefault() && item.IdUser == Session.User.IdUser).FirstOrDefault();
+                    answer.Answer = AnswerBox.Text;
+                }
+                else
+                {
+                    Answers newAnswer = new Answers()
+                    {
+                        IdUserAnswer = cnt.db.Answers.Select(p => p.IdUserAnswer).DefaultIfEmpty(0).Max() + 1,
+                        IdQuestion = cnt.db.Questions.Where(item => item.Content == strContent && item.Answer == strAnswer).Select(item => item.IdQuestion).FirstOrDefault(),
+                        IdUser = Session.User.IdUser,
+                        Answer = AnswerBox.Text
+                    };
+                    cnt.db.Answers.Add(newAnswer);
+                    cnt.db.SaveChanges();
+                }
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show(ex.ToString());
+                //new ErrorWindow(ex.ToString()).ShowDialog();
+            }
+
             if (AnswerBox.Text.ToLower().Trim() == Session.Quest.Answer[Session.CurQuestion].ToLower().Trim())
                 Session.Points++;
-            if(Session.CurQuestion >= Session.OpenedTest.Questions.Count()-1)
+            if (Session.CurQuestion >= Session.OpenedTest.Questions.Count() - 1)
                 NavigationService.Navigate(new Pages.ResultTestPage());
             else
             {
-                Session.CurQuestion++; 
+                Session.CurQuestion++;
                 NavigationService.Navigate(new Pages.CurTestPage());
             }
         }

+ 34 - 30
MyTests/Pages/ProfilePage.xaml

@@ -43,28 +43,44 @@
             </Grid>
 
 
-            <Grid Grid.Column="1"
+            <Grid Name="UserInfoGrid"
+                  Grid.Column="1"
                   Margin="10"
                   Background="{StaticResource color3}">
                 <Grid.RowDefinitions>
                     <RowDefinition Height="49"/>
                     <RowDefinition/>
                 </Grid.RowDefinitions>
-                <TextBox Grid.Row="0"
-                         Name="EmailBox"
-                         Text="Email"
+                <StackPanel Grid.Row="0"
+                            Orientation="Horizontal">
+                    <TextBox Text="Email: "
+                             Background="{x:Null}"
+                             BorderBrush="{x:Null}"
+                             FontSize="22"/>
+                    <TextBox Name="EmailBox"
+                         Text=" "
                          FontSize="22"
                          Background="{x:Null}"
                          BorderBrush="{x:Null}"
-                         MinWidth="50">
-                </TextBox>
+                         Width="{Binding Path=ActualWidth, ElementName=UserInfoGrid}">
+                    </TextBox>
+                </StackPanel>
 
-                <TextBox Grid.Row="1"
-                       Text="Инфо: "
-                       FontSize="22"
+                <StackPanel Grid.Row="1"
+                            Orientation="Horizontal">
+                    <TextBox Text="Инфо: "
+                         FontSize="22"
                          Background="{x:Null}"
                          BorderBrush="{x:Null}">
-                </TextBox>
+                    </TextBox>
+                    <TextBox Name="InfoBox"
+                         Text=""
+                         FontSize="22"
+                         Background="{x:Null}"
+                         BorderBrush="{x:Null}"
+                             Width="{Binding Path=ActualWidth, ElementName=UserInfoGrid}">
+                    </TextBox>
+                </StackPanel>
             </Grid>
         </Grid>
 
@@ -96,7 +112,7 @@
                                 </StackPanel>
                                 <TextBlock Margin="0,-7,0,0">
                                     <Run Text="Вопросов: " Foreground="White"/>
-                                    <Run Text="{Binding Questions.Count, Mode=OneTime}" />
+                                    <Run Text="{Binding Questions.Count, Mode=OneTime}"/>
                                 </TextBlock>
                             </StackPanel>
                         </StackPanel>
@@ -105,24 +121,12 @@
             </ListBox.ItemTemplate>
         </ListBox>
 
-        <Grid Grid.Row="2">
-            <StackPanel Orientation="Horizontal" 
-                        HorizontalAlignment="Center">
-                <Button Visibility="Collapsed"
-                        Width="120"
-                        Margin="5,0,5,0"
-                        Content="Назад"
-                        FontSize="20"
-                        Click="BackButton">
-                </Button>
-                <Button Width="120"
-                        Margin="5,0,5,0"
-                        Content="Сохранить"
-                        FontSize="20"
-                        Click="SaveButton">
-                </Button>
-            </StackPanel>
-
-        </Grid>
+        <Button Grid.Row="2"
+                Width="120"
+                Margin="5,0,5,0"
+                Content="Сохранить"
+                FontSize="20"
+                Click="SaveButton">
+        </Button>
     </Grid>
 </Page>

+ 14 - 11
MyTests/Pages/ProfilePage.xaml.cs

@@ -1,17 +1,9 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace MyTests.Pages
 {
@@ -27,9 +19,9 @@ namespace MyTests.Pages
                 ProfileImage.Source = new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute));
             else
                 ProfileImage.Source = ImagesManip.NewImage(user);
+            EmailBox.Text = user.Email;
+            InfoBox.Text = user.Info;
             TestsLoading();
-            //EmailBox.Content = cnt.db.Dispatcher.Where(item => item.IdDispatcher == profile.DispatcherId).Select(item => item.Email).FirstOrDefault();
-            //PhoneNumBox.Content = "+7(" + phone.Substring(0, 3) + ")" + phone.Substring(3, 3) + "-" + phone.Substring(6, 2) + "-" + phone.Substring(8, 2);
         }
         private void EditImage_Click(object sender, RoutedEventArgs e)
         {
@@ -52,7 +44,18 @@ namespace MyTests.Pages
 
         private void SaveButton(object sender, RoutedEventArgs e)
         {
-
+            if (!Functions.IsValidEmail(EmailBox.Text))
+                new ErrorWindow("Email введен неверно.").Show();
+            else if (Functions.IsEmailAlreadyTaken(EmailBox.Text))
+                new ErrorWindow("Данный email уже используется.").Show();
+            else
+            {
+                Session.User.Email = EmailBox.Text;
+                Session.User.Info = InfoBox.Text;
+                cnt.db.SaveChanges();
+                new ErrorWindow("Успешно.").ShowDialog();
+            }
+            
         }
 
         private void BackButton(object sender, RoutedEventArgs e)

+ 2 - 12
MyTests/Pages/ResultTestPage.xaml.cs

@@ -1,17 +1,7 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 namespace MyTests.Pages
 {
@@ -25,7 +15,7 @@ namespace MyTests.Pages
 
         private void AnswersButton_Click(object sender, RoutedEventArgs e)
         {
-
+            NavigationService.Navigate(new Pages.TestPage(Session.OpenedTest.IdTest));
         }
 
         private void ExitButton_Click(object sender, RoutedEventArgs e)

+ 8 - 6
MyTests/Pages/TestPage.xaml

@@ -34,7 +34,8 @@
             </Image>
             <Label Name="AuthorName"
                    Content="Автор"
-                   FontSize="25">
+                   FontSize="25"
+                   MouseDown="AuthorName_MouseDown">
             </Label>
         </StackPanel>
         <ListBox Name="TestsListBox"
@@ -47,12 +48,13 @@
                     <Border Width="{Binding Path=ActualWidth, ElementName=TestsListBox}"
                             Height="50"
                             CornerRadius="10"
-                            Background="{StaticResource color2}"
-                            MouseDown="TestsListBox_Selected">
+                            Background="{StaticResource color2}">
                         <StackPanel>
-                            <Label Content="{Binding Content}"/>
-                            <TextBox Name="Testing"
-                                     Text="Ответ:"/>
+                            <Label Content="{Binding Questions.Content}"/>
+                            <TextBlock>
+                                <Run Text="Ответ: " Foreground="LightGray"/>
+                                <Run Text="{Binding Answer}" Foreground="White"/>
+                            </TextBlock>
                         </StackPanel>
                     </Border>
                 </DataTemplate>

+ 9 - 23
MyTests/Pages/TestPage.xaml.cs

@@ -1,19 +1,9 @@
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
 using System.Windows.Input;
-using System.Windows.Markup;
-using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
-using System.Windows.Shapes;
-using System.Globalization;
 
 namespace MyTests.Pages
 {
@@ -27,27 +17,23 @@ namespace MyTests.Pages
             Tests test = cnt.db.Tests.Where(item => item.IdTest == id).FirstOrDefault();
             TestName.Content = test.Name;
             AuthorName.Content = test.Users.Login;
+
+            if (test.Users.Image == null)
+                AuthorImg.Source = new BitmapImage(new Uri("../Resources/StandartImage.png", UriKind.RelativeOrAbsolute));
+            else
+                AuthorImg.Source = ImagesManip.NewImage(test.Users);
+
             LoadingQuestions();
         }
         void LoadingQuestions()
         {
             TestsListBox.Items.Clear();
-            TestsListBox.ItemsSource = cnt.db.Questions.Where(item=>item.IdTest == testId).ToList();
+            TestsListBox.ItemsSource = cnt.db.Answers.Where(item=>item.Questions.IdTest == testId && item.IdUser == Session.User.IdUser).ToList();
         }
 
-        private void TestsListBox_Selected(object sender, MouseButtonEventArgs e)
+        private void AuthorName_MouseDown(object sender, MouseButtonEventArgs e)
         {
-            try
-            {
-                if (((Questions)TestsListBox.SelectedItem) != null)
-                {
-                    MessageBox.Show(((Questions)TestsListBox.SelectedItem).IdQuestion.ToString());
-                }
-            }
-            catch
-            {
-                new ErrorWindow("Ошибка открытия теста.").ShowDialog();
-            }
+            NavigationService.Navigate(new Pages.ProfilePage(cnt.db.Users.Where(item => item.IdUser == Session.OpenedTest.IdUser).FirstOrDefault()));
         }
     }
 }

+ 8 - 0
MyTests/Questions.cs

@@ -14,11 +14,19 @@ namespace MyTests
     
     public partial class Questions
     {
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
+        public Questions()
+        {
+            this.Answers = new HashSet<Answers>();
+        }
+    
         public int IdQuestion { get; set; }
         public int IdTest { get; set; }
         public string Content { get; set; }
         public string Answer { get; set; }
     
         public virtual Tests Tests { get; set; }
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+        public virtual ICollection<Answers> Answers { get; set; }
     }
 }

+ 3 - 0
MyTests/Users.cs

@@ -18,6 +18,7 @@ namespace MyTests
         public Users()
         {
             this.Tests = new HashSet<Tests>();
+            this.Answers = new HashSet<Answers>();
         }
     
         public int IdUser { get; set; }
@@ -29,5 +30,7 @@ namespace MyTests
     
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
         public virtual ICollection<Tests> Tests { get; set; }
+        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
+        public virtual ICollection<Answers> Answers { get; set; }
     }
 }

+ 23 - 0
MyTests/sysdiagrams.cs

@@ -0,0 +1,23 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Этот код создан по шаблону.
+//
+//     Изменения, вносимые в этот файл вручную, могут привести к непредвиденной работе приложения.
+//     Изменения, вносимые в этот файл вручную, будут перезаписаны при повторном создании кода.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace MyTests
+{
+    using System;
+    using System.Collections.Generic;
+    
+    public partial class sysdiagrams
+    {
+        public string name { get; set; }
+        public int principal_id { get; set; }
+        public int diagram_id { get; set; }
+        public Nullable<int> version { get; set; }
+        public byte[] definition { get; set; }
+    }
+}

+ 64 - 4
UnitTestProject/UnitTest1.cs

@@ -1,15 +1,75 @@
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using System;
-
+using MyTests;
 namespace UnitTestProject
 {
     [TestClass]
     public class UnitTest1
     {
         [TestMethod]
-        public void TestMethod1()
+        public void IsValidEmail()
         {
-
+            Assert.IsTrue(Functions.IsValidEmail("Matrix@gmail.com"));
+            Assert.IsTrue(Functions.IsValidEmail("Imagine@mail.ru"));
+            Assert.IsFalse(Functions.IsValidEmail("usermail.com"));
+            Assert.IsFalse(Functions.IsValidEmail("usermailcom"));
+            Assert.IsFalse(Functions.IsValidEmail(""));
+        }
+        [TestMethod]
+        public void PasswordEncryptTest()
+        {
+            //string password = "qq";
+            //string expected = "BED4EB698C6EEEA7F1DDF5397D480D3F2C0FB938";
+            //Assert.AreEqual(Encrypt.GetHash(password), expected);
+        }
+        [TestMethod]
+        public void LoginTest()
+        {
+            string login = "Matrix";
+            string password = "meme3";
+            Assert.IsTrue(Functions.LoginCheck(login, password));
+        }
+        [TestMethod]
+        public void IsValidLoginAndPassword()
+        {
+            Assert.IsTrue(Functions.IsValidLogAndPass("Matrix", "meme3"));
+            Assert.IsTrue(Functions.IsValidLogAndPass("Imagine", "pizza"));
+            Assert.IsTrue(Functions.IsValidLogAndPass("Login???", "p@ssw0rd"));
+            Assert.IsFalse(Functions.IsValidLogAndPass("", ""));
+            Assert.IsFalse(Functions.IsValidLogAndPass("", "SimplePass"));
+            Assert.IsFalse(Functions.IsValidLogAndPass("SimpleLogin", ""));
+        }
+        [TestMethod]
+        public void IsLoginAlreadyTaken()
+        {
+            Assert.IsTrue(Functions.IsLoginAlreadyTaken("Matrix"));
+            Assert.IsTrue(Functions.IsLoginAlreadyTaken("Imagine"));
+            Assert.IsFalse(Functions.IsLoginAlreadyTaken("SimpleLogin"));
+            Assert.IsFalse(Functions.IsLoginAlreadyTaken("Login?"));
+            Assert.IsFalse(Functions.IsLoginAlreadyTaken(""));
+        }
+        [TestMethod]
+        public void IsEmailAlreadyTaken()
+        {
+            Assert.IsTrue(Functions.IsEmailAlreadyTaken("Matrix@gmail.com"));
+            Assert.IsTrue(Functions.IsEmailAlreadyTaken("Imagine@gmail.com"));
+            Assert.IsFalse(Functions.IsEmailAlreadyTaken("user3@mail.ru"));
+            Assert.IsFalse(Functions.IsEmailAlreadyTaken("user42@gmail.com"));
+            Assert.IsFalse(Functions.IsEmailAlreadyTaken("s0mpleEmail@sibmail.com"));
+        }
+        [TestMethod]
+        public void IsLogEqualPass()
+        {
+            Assert.IsFalse(Functions.IsLogEqualPass("Matrix", "Matrix"));
+            Assert.IsTrue(Functions.IsLogEqualPass("Matrix", "meme3"));
+        }
+        [TestMethod]
+        public void IsValidLength()
+        {
+            Assert.IsTrue(Functions.IsValidLength("Matrix"));
+            Assert.IsTrue(Functions.IsValidLength("Matrwerwewe"));
+            Assert.IsFalse(Functions.IsValidLength("Ma"));
+            Assert.IsFalse(Functions.IsValidLength(""));
         }
     }
-}
+}

+ 6 - 0
UnitTestProject/UnitTestProject.csproj

@@ -55,6 +55,12 @@
   <ItemGroup>
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\MyTests\MyTests.csproj">
+      <Project>{ecfa6225-9d0e-4041-91f6-12c6bf32bd70}</Project>
+      <Name>MyTests</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">