public Res SatisfyRequest(Func<StudentRequest, bool> p, ModelContainer data) { bool Success = true; IEnumerable<StudentRequest> requests = null; // try // { requests = data.StudentRequests.Select(row => row).Where(p); List<StudentRequest> list = requests.ToList(); int i = requests.Count(); foreach (StudentRequest r in list) { //удаляем пользователя из всех групп, в которых он состоит foreach (Group g in r.aspnet_Users.Groups) g.aspnet_Users.Remove(r.aspnet_Users); //добавляем пользователя в группу r.Group.aspnet_Users.Add(r.aspnet_Users); //удаляем пользовательский запрос на вступление data.StudentRequests.Remove(r); } data.SaveChanges(); // } // catch (Exception e) // { // Success = false; // } return new Res(Success, requests); }
public ActionResult CreateStudentRequest(string GroupName) { ModelContainer data = new ModelContainer(); StudentRequestDAO studentrequestdao = new StudentRequestDAO(); UserDAO userdao = new UserDAO(); GroupDAO groupdao = new GroupDAO(); IEnumerable<aspnet_Users> users = (IEnumerable<aspnet_Users>)(userdao.ReadAll(x => (x.LoweredUserName == User.Identity.Name.ToLower()), data).Value); IEnumerable<Group> groups = (IEnumerable<Group>)(groupdao.ReadAll(x => (x.GroupName == GroupName), data).Value); Res result = studentrequestdao.CreateRequest(users.First(x => true), groups.First(x => true), data); return RedirectToAction("CreateStudentRequestView", "Student"); }
public ActionResult CreateDiscipline(string Name) { ViewData["links"] = getLinks(); ViewData["functions"] = getFunctions(); ModelContainer data = new ModelContainer(); DisciplineDAO disciplineDAO = new DisciplineDAO(); UserDAO userDAO = new UserDAO(); IEnumerable<aspnet_Users> users = (IEnumerable<aspnet_Users>)userDAO.ReadAll(x => (x.LoweredUserName == User.Identity.Name.ToLower()), data).Value; Res result = disciplineDAO.CreateDiscipline(Name, users.First(x => (x.LoweredUserName == User.Identity.Name.ToLower())), data); return RedirectToAction("Disciplines", "Lector"); }
public ActionResult CreateRequest(string message, string role) { ViewData["links"] = getLinks(); ViewData["functions"] = getFunctions(); RequestDAO requestDAO = new RequestDAO(); UserDAO userdao = new UserDAO(); Test.Models.ModelContainer data = new ModelContainer(); IEnumerable<aspnet_Users> users = (IEnumerable<aspnet_Users>)userdao.ReadAll(x => (x.LoweredUserName == User.Identity.Name.ToLower()), data).Value; aspnet_Users user = users.First(x => true); requestDAO.CreateRequest(user , role, message, data); return RedirectToAction("Index", "Home"); }
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 Res ReadAll(Func<Group, bool> p, ModelContainer data) { bool Success = true; IEnumerable<Group> groups = null; try { groups = data.Groups.Select(row => row).Where(p); } catch (Exception e) { Success = false; } return new Res(Success, groups); }
//методы, выполняющиеся отдельно public Res ReadAllDisciplines(Func<Discipline, bool> p, ModelContainer data) { bool Success = true; IEnumerable<Discipline> disciplines = null; try { disciplines = data.Disciplines.Select(row => row).Where(p); } catch (Exception e) { Success = false; } return new Res(Success, disciplines); }
public Res ReadAllRequests(Func<Request, bool> p, ModelContainer data) { bool Success = true; IEnumerable<Request> requests = null; try { requests = data.Requests.Select(row => row).Where(p); } catch (Exception e) { Success = false; } return new Res(Success, requests); }
public Res UpdateGroup(string NewName, string OldName, ModelContainer data) { bool Success = true; Group g = null; try { g = data.Groups.First(row => (row.GroupName == OldName)); g.GroupName = NewName; data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, g); }
public Res DeleteGroup(Func<Group, bool> p, ModelContainer data) { bool Success = true; IEnumerable<Group> groups = null; try { groups = data.Groups.Select(row => row).Where(p); foreach (Group g in groups) data.Groups.Remove(g); data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, groups); }
public Res RenameDiscipline(string NewName, string OldName, ModelContainer data) { bool Success = true; Discipline d = null; try { d = data.Disciplines.First(row => (row.DisciplineName == OldName)); d.DisciplineName = NewName; data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, d); }
public Res DeleteDiscipline(Func<Discipline, bool> p, ModelContainer data) { bool Success = true; Discipline d = null; try { IEnumerable<Discipline> disciplines = data.Disciplines.Select(row => row).Where(p); foreach (Discipline di in disciplines) data.Disciplines.Remove(di); data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, d); }
public Res AddStudent(aspnet_Users student, Group group, ModelContainer data) { bool Success = true; IEnumerable<Group> groups = null; try { foreach (Group g in student.Groups) g.aspnet_Users.Remove(student); group.aspnet_Users.Add(student); data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, groups); }
public Res CreateGroup(string Name, ModelContainer data) { bool Success = true; Group g = null; try { g = data.Groups.Create(); g.GroupId = Guid.NewGuid(); g.GroupName = Name; data.Groups.Add(g); data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, g); }
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 Res ReadAll(Func<aspnet_Users, bool> p, ModelContainer data) { bool Success = true; IEnumerable<aspnet_Users> users = null; //try // { users = data.aspnet_Users.Select(row => row).Where(p); // } // catch (Exception e) // { Success = false; // } // finally // { // } return new Res(Success, users); }
public Res CreateDiscipline(string Name, aspnet_Users user, ModelContainer data) { bool Success = true; Discipline d = null; try { d = data.Disciplines.Create(); d.DisciplineId = Guid.NewGuid(); d.aspnet_Users = user; d.DisciplineName = Name; data.Disciplines.Add(d); data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, d); }
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 Res RejectRequest(Func<Request, bool> p, ModelContainer data) { bool Success = true; IEnumerable<Request> requests = null; try { requests = data.Requests.Select(row => row).Where(p); foreach (Request r in requests) { data.Requests.Remove(r); } data.SaveChanges(); } catch (Exception e) { Success = false; } return new Res(Success, requests); }
public Res CreateRequest(aspnet_Users user, Group group, ModelContainer data) { bool Success = true; IEnumerable<StudentRequest> requests = null; //try // { StudentRequest request = data.StudentRequests.Create(); request.StudentRequestId = Guid.NewGuid(); request.aspnet_Users = user; request.Message = "m"; request.Group = group; data.StudentRequests.Add(request); data.SaveChanges(); // } // catch (Exception e) // { //Success = false; // } return new Res(Success, requests); }
public Res RejectRequest(Func<StudentRequest, bool> p, ModelContainer data) { bool Success = true; IEnumerable<StudentRequest> requests = null; // try // { requests = data.StudentRequests.Select(row => row).Where(p); foreach (StudentRequest r in requests) { //удаляем пользовательский запрос на вступление data.StudentRequests.Remove(r); } data.SaveChanges(); // } // catch (Exception e) // { // Success = false; // } return new Res(Success, requests); }
public Res CreateRequest(aspnet_Users user, string role, string Message, ModelContainer data) { bool Success = true; Request request = null; try { request = data.Requests.Add(data.Requests.Create<Request>()); aspnet_Roles ROLE = data.aspnet_Roles.Select(row => row).First(row => row.RoleName == role); request.RequestId = Guid.NewGuid(); request.aspnet_Roles = ROLE; request.aspnet_Users = user; request.Message = Message; data.SaveChanges(); } catch (Exception e) { Success = false; } finally { } return new Res(Success, request); }
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 UpdateDiscipline(string NewName, string OldName) { ViewData["links"] = getLinks(); ViewData["functions"] = getFunctions(); ModelContainer data = new ModelContainer(); DisciplineDAO disciplineDAO = new DisciplineDAO(); disciplineDAO.RenameDiscipline(NewName, OldName, data); return RedirectToAction("Disciplines", "Lector"); }
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 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 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 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 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"); }