public ActionResult BindGroupAndTest(string TestId, string GroupId)
        {
            ModelContainer data = new ModelContainer();
            Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
            Test.Models.GroupDAO gdao = new GroupDAO();

            Group g = (gdao.ReadAll(x => x.GroupId.ToString() == GroupId, data).Value as IEnumerable<Group>).First();
            Models.Test t = (tdao.ReadTests(x => x.TestId.ToString() == TestId, data).Value as IEnumerable<Models.Test>).First();

            tdao.Bind(t, g, data);

            return RedirectToAction("GroupsAndTests", "Lector");
        }
 public ActionResult CreateQuestion(string TestId, string QuestionText)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r1 = tdao.ReadTests(test => test.TestId.ToString() == TestId, data);
     if (r1.Success)
     {
         Res r2 = tdao.CreateQuastion((r1.Value as IEnumerable<Test.Models.Test>).First(), QuestionText, data);
         if (r2.Success)
         {
             return RedirectToAction("Test", "Lector", new { TestId  = TestId });
         }
         else
             return RedirectToAction("Errors", "Shared");
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult CreateTest(string TestName, string DisciplineId)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Test.Models.DisciplineDAO ddao = new DisciplineDAO();
     Res r1 = ddao.ReadAllDisciplines(disciline => disciline.DisciplineId.ToString() == DisciplineId, data);
     if (r1.Success)
     {
         Res r2 = tdao.CreateTests(TestName, (r1.Value as IEnumerable<Test.Models.Discipline>).First(), data);
         if (r2.Success)
         {
             return RedirectToAction("Tests", "Lector");
         }
         else
             return RedirectToAction("Errors", "Shared");
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
        public ActionResult Begin(string TestId)
        {
            ViewData["links"] = getLinks();
            ViewData["functions"] = getFunctions();
            ModelContainer data = new ModelContainer();
            Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
            Res r = tdao.ReadTests(test => test.TestId.ToString() == TestId, data);
            if (r.Success)
            {
                Test.Models.Test test = (r.Value as IEnumerable<Test.Models.Test>).First();
                //полностью клонируем его и суём в сессию
                Test.Models.Test test1 = data.Tests.Create();
                test1.TestId = test.TestId;
                test1.Name = test.Name;
                foreach (Quastion q in test.Quastions)
                {
                    Quastion q1 = data.Quastions.Create();
                    q1.Text = q.Text;
                    q1.QuastionId = q.QuastionId;
                    test1.Quastions.Add(q1);

                    foreach (Variant v in q.Variants)
                    {
                        Variant v1 = data.Variants.Create();
                        q1.Variants.Add(v1);
                        v1.Text = v.Text;
                        v1.VariantId = v.VariantId;
                        v1.IsValid = false;
                    }
                }
                Session["test"] = test1;
                return RedirectToAction("Test", "Student");
            }
            else
                return RedirectToAction("Errors", "Shared");
        }
 public ActionResult CreateVariant(string QuestionId, string VariantText, bool isValid)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r0 = tdao.ReadQuastions(question => question.QuastionId.ToString() == QuestionId, data);
     Models.Quastion q = null;
     if (r0.Success)
     {
         q = (r0.Value as IEnumerable<Test.Models.Quastion>).First();
     }
     Res r = tdao.CreateVariant(q, VariantText, isValid, data);
     if (r.Success && r0.Success)
     {
         return RedirectToAction("Test", "Lector", new { TestId = q.Test_TestId });
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult Variant(string VariantId)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r = tdao.ReadVariants(variant => variant.VariantId.ToString() == VariantId, data);
     if (r.Success)
     {
         Models.Variant variant = (r.Value as IEnumerable<Test.Models.Variant>).First();
         return View((r.Value as IEnumerable<Test.Models.Variant>).First());
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult Tests()
 {
     ViewData["links"] = getLinks();
     ViewData["functions"] = getFunctions();
     Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     DisciplineDAO disciplineDAO = new DisciplineDAO();
     ModelContainer data = new ModelContainer();
     Res r = tdao.ReadTests(test => (disciplineDAO.ReadAllDisciplines(d => d.aspnet_Users.LoweredUserName == User.Identity.Name.ToLower(), data).Value as IEnumerable<Discipline>).Contains(test.Discipline), data);
     Res result = disciplineDAO.ReadAllDisciplines(x => (x.aspnet_Users.LoweredUserName == User.Identity.Name.ToLower()), data);
     return View(new object[] {r.Value, result.Value, data.Groups});
 }
 public ActionResult Test(string TestId)
 {
     ViewData["links"] = getLinks();
     ViewData["functions"] = getFunctions();
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r = tdao.ReadTests(test => test.TestId.ToString() == TestId, data);
     if (r.Success)
     {
         Models.Test test = (r.Value as IEnumerable<Test.Models.Test>).First();
         return View(test);
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult Question(string QuestionId)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r = tdao.ReadQuastions(quastion => quastion.QuastionId.ToString() == QuestionId, data);
     if (r.Success)
     {
         Models.Quastion quastion = (r.Value as IEnumerable<Test.Models.Quastion>).First();
         return View(quastion);
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult GroupsAndTests()
 {
     ViewData["links"] = getLinks();
     ViewData["functions"] = getFunctions();
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Test.Models.GroupDAO gdao = new GroupDAO();
     Res rt = tdao.ReadTests(test => test.Discipline.aspnet_Users.LoweredUserName == User.Identity.Name.ToLower(), data);
     Res gr = gdao.ReadAll(group => true, data);
     return View(new object[] { rt.Value , gr.Value });
 }
 public ActionResult GetStatistics()
 {
     ViewData["links"] = getLinks();
     ViewData["functions"] = getFunctions();
     ModelContainer data = new ModelContainer();
     UserDAO udao = new UserDAO();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     IEnumerable<aspnet_Users> users = (udao.ReadAll(x => x.LoweredUserName == User.Identity.Name.ToLower(), data).Value as IEnumerable<aspnet_Users>);
     IEnumerable<Test.Models.Test> tests = (tdao.ReadTests(test => test.Discipline.aspnet_Users_UserId == users.First().UserId, data).Value as IEnumerable<Test.Models.Test>);
     Object results = (tdao.ReadAllResults(result => tests.Contains(result.Test), data)).Value;
     return View(results);
 }
 public ActionResult DeleteVariant(string VariantId)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r0 = tdao.ReadVariants(variant => variant.VariantId.ToString() == VariantId, data);
     Models.Variant v = null;
     string TestId = "";
     if (r0.Success)
     {
         v = (r0.Value as IEnumerable<Test.Models.Variant>).First();
         TestId = v.Quastion.Test_TestId.ToString();
     }
     Res r = tdao.DeleteVariant(variant => variant.VariantId.ToString() == VariantId, data);
     if (r.Success && r0.Success)
     {
         return RedirectToAction("Test", "Lector", new { TestId = TestId });
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
 public ActionResult DeleteTest(string TestId)
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     Res r = tdao.DeleteTests(test => test.TestId.ToString() == TestId, data);
     if (r.Success)
     {
         return RedirectToAction("Tests", "Lector");
     }
     else
         return RedirectToAction("Errors", "Shared");
 }
        public ActionResult DeleteQuestion(string QuestionId)
        {
            ModelContainer data = new ModelContainer();
            Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
            Res r0 = tdao.ReadQuastions(question => question.QuastionId.ToString() == QuestionId, data);
            string TestId = "";
            if (r0.Success)
            {
                TestId = (r0.Value as IEnumerable<Models.Quastion>).First().Test_TestId.ToString();
            }
            Res r1 = tdao.DeleteQuastions(question => question.QuastionId.ToString() == QuestionId, data);
            if (r1.Success && r0.Success)
            {

                return RedirectToAction("Test", "Lector", new { TestId = TestId });
            }
            else
                return RedirectToAction("Errors", "Shared");
        }
 public ActionResult Tests()
 {
     ViewData["links"] = getLinks();
     ViewData["functions"] = getFunctions();
     ModelContainer data = new Models.ModelContainer();
     GroupDAO gdao = new GroupDAO();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     UserDAO udao = new UserDAO();
     IEnumerable<aspnet_Users> users = (udao.ReadAll(x => x.LoweredUserName == User.Identity.Name.ToLower(), data).Value as IEnumerable<aspnet_Users>);
     IEnumerable<Group> groups = (gdao.ReadAll(x => x.aspnet_Users.Contains(users.First()), data).Value as IEnumerable<Group>);
     IEnumerable<Test.Models.Test> tests = (tdao.ReadTests(x => x.Groups.Contains(groups.First()), data).Value as IEnumerable<Models.Test>);
     return View(tests);
 }
 public ActionResult SendTest()
 {
     ModelContainer data = new ModelContainer();
     Test.Models.DAO.TestDAO tdao = new Models.DAO.TestDAO();
     UserDAO udao = new UserDAO();
     IEnumerable<aspnet_Users> users = (udao.ReadAll(x => x.LoweredUserName == User.Identity.Name.ToLower(), data).Value as IEnumerable<aspnet_Users>);
     Res r = tdao.Check((Session["test"] as Test.Models.Test), data, users.First());
     return View(r.Value);
 }