public int GetCursNumber(string materie, string mail) { int index = 0; using (var db = new EducatieIncluzivaDBContext()) { var rr = new EduIncluziva.Metrics.ResourcesRepository(); var teach = rr.GetProfesoriByMail(mail); var curs = from p in db.Courses where p.ProfesorId == teach.UserId select p; foreach (var c in curs) { if (c.Nume.Equals(materie)) { break; } else { index++; } } } return(index); }
public List <Lesson> GetAllLessons(string mail, string materie) { List <Lesson> myList = new List <Lesson>(); try { using (var db = new EducatieIncluzivaDBContext()) { var rr = new EduIncluziva.Metrics.ResourcesRepository(); var teach = rr.GetProfesoriByMail(mail); var curs = (from p in db.Courses where p.Nume.Equals(materie) && p.ProfesorId == teach.UserId select p).FirstOrDefault(); var lectii = from p in db.Lessons where p.ProfesorOwner == teach select p; var b = db.Lessons.ToList(); foreach (Lesson c in b) { if (c.ProfesorOwnerId == teach.UserId && c.CourseId == curs.CourseId) { myList.Add(c); } } return(myList); } } catch (Exception exc) { throw exc; } }
private void UpdateCurs(string cursNume, Teacher t1, string numevechi1) { using (var context = new EducatieIncluzivaDBContext()) { Course curs = (from p in context.Courses where p.ProfesorId == t1.UserId && p.Nume.Equals(numevechi1) select p).FirstOrDefault(); if (curs != null) { curs.Nume = cursNume; DbEntityEntry <Course> entry = context.Entry(curs); entry.State = EntityState.Modified; context.SaveChanges(); } else { Course cur = new Course(); cur.Nume = cursNume; cur.ProfesorId = t1.UserId; context.Courses.Add(cur); context.SaveChanges(); } } }
public void InseramElevi() { using (var context = new EducatieIncluzivaDBContext()) { string parola = "parola"; string nume = "nume"; string prenume = "prenume"; string mail = "*****@*****.**"; for (int i = 0; i < 10; i++) { Random random = new Random(); int rand = random.Next(0, _numeLicee.Length); string name = _numeLicee[rand]; HighSchool highSchool = _resourcesRepository.GetHighSchoolByName(name); Student student = new Student(parola + i.ToString(), nume + i.ToString(), prenume + i.ToString(), mail + i.ToString(), highSchool); context.Students.Add(student); } context.SaveChanges(); } }
public void InseramProfesori() { using (var context = new EducatieIncluzivaDBContext()) { const string parola = "parola"; const string nume = "nume"; const string prenume = "prenume"; const string mail = "*****@*****.**"; const string imageUrlForTest = "C:\\Users\\vlad.mirel\\Documents\\Visual Studio 2012\\Projects\\EduIncluziva(1)\\EduIncluziva_01\\EduIncluziva\\Pictures\\Profesori\\Test\\testpic1.jpg"; for (int i = 0; i < 10; i++) { var random = new Random(); int rand = random.Next(0, _numeLicee.Length); string name = _numeLicee[rand]; HighSchool highSchool = _resourcesRepository.GetHighSchoolByName(name); var teacher = new Teacher( parola + i.ToString(), nume + i.ToString(), prenume + i.ToString(), mail + i.ToString(), highSchool, imageUrlForTest, "Bio test in care punem si liceul " + highSchool); context.Teachers.Add(teacher); } context.SaveChanges(); } }
public ActionResult RegisterElevi(ElevRegisterModel model) { if (ModelState.IsValid) { ResourcesRepository rr = new ResourcesRepository(); HighSchool hs = rr.GetHighSchoolByName(model.ScoalaDeProvenienta); Student elev = new Student(model.Parola, model.Nume, model.Prenume, model.Mail, hs); //User user = new User(model.Parola, model.Nume, model.Prenume, model.Mail); using (var db = new EducatieIncluzivaDBContext()) { //db.Useri.Add(user); db.Entry(hs).State = EntityState.Unchanged; db.Students.Add(elev); try { db.SaveChanges(); } catch (Exception ex) { throw ex; } FormsAuthentication.SetAuthCookie(model.Mail, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } } // If we got this far, something failed, redisplay form return(View()); }
public int EraseLesson(string nume, string mail, string materii) { try { var rr = new ResourcesRepository(); var model = rr.GetProfesoriByMail(mail); using (var context = new EducatieIncluzivaDBContext()) { Course curs = (from p in context.Courses where p.ProfesorId == model.UserId && p.Nume.Equals(materii) select p).FirstOrDefault(); Lesson l = (from m in context.Lessons where m.CourseId == curs.CourseId && m.ProfesorOwnerId == model.UserId && m.Titlu.Equals(nume) select m).FirstOrDefault(); if (l != null) { context.Lessons.Remove(l); context.SaveChanges(); return(1); } } } catch { } return(0); }
public ActionResult Reject(Guid id) { using (var context = new EducatieIncluzivaDBContext()) { var entry = context.RegistrationRequests.Find(id); context.RegistrationRequests.Remove(entry); context.SaveChanges(); } return(RedirectToAction("CereriInregistrare")); }
public void UpdateTeacher(string mail, string imageUrl) { using (var context = new EducatieIncluzivaDBContext()) { var teacher = this.GetProfesoriByMail(mail); teacher.ImageUrl = imageUrl; context.Teachers.Attach(teacher); context.Entry(teacher).State = EntityState.Modified; context.SaveChanges(); } }
public void InsertAdministrator() { using (var context = new EducatieIncluzivaDBContext()) { var resourcesRepository = new ResourcesRepository(); var highSchool = resourcesRepository.GetHighSchoolByName(SchoolName); var administrator = new Administrator(Parola, Nume, Prenume, Mail, highSchool); context.Administrators.Add(administrator); context.SaveChanges(); } }
public void UpdateTeacher(string nume, string prenume, string mail, string bio, string numevechi1, string numevechi2, string c1, string c2) { using (var context = new EducatieIncluzivaDBContext()) { // get the teacher var theUser = this.GetProfesoriByMail(mail); //update general info about the teacher theUser.Description = bio; theUser.Mail = mail; theUser.Nume = nume; theUser.Prenume = prenume; /* Course cur = new Course(); * cur.Nume = c1; * Course cur2 = new Course(); * cur2.Nume = c2; * * cur.ProfesorId = theUser.UserId; * cur2.ProfesorId = theUser.UserId; * * //if the teacher already has some courses * if (theUser.Materii != null) * { * if (!theUser.Materii.Contains(cur)) * { * context.Courses.Add(cur); * } * if (!theUser.Materii.Contains(cur2)) * { * context.Courses.Add(cur2); * } * } * else * { * context.Courses.Add(cur); * context.Courses.Add(cur2); * * } */ UpdateCurs(c1, theUser, numevechi1); UpdateCurs(c2, theUser, numevechi2); DbEntityEntry <Teacher> entry = context.Entry(theUser); entry.State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult InregistrareProfesori(InregistrareProfesorModel model) { if (ModelState.IsValid) { using (var context = new EducatieIncluzivaDBContext()) { model.UserId = Guid.NewGuid(); context.RegistrationRequests.Add(model); context.SaveChanges(); //ViewData["inregProf"] = "Cererea dumneavoastra a fost inregistrata. Va rugam asteptati mesajul de confirmare"; } } return(RedirectToAction("Confirm", "Cont")); }
public void InsertInitialHighSchools() { using (var context = new EducatieIncluzivaDBContext()) { foreach (var numeLiceu in _numeLicee) { var highSchool = new HighSchool(); highSchool.Nume = numeLiceu; highSchool.HighSchoolId = Guid.NewGuid(); context.HighSchools.Add(highSchool); } context.SaveChanges(); } }
/// <summary> /// Returns a Profesor corresponding to the Profesor_Mail parameter. /// </summary> /// <param name="mail"></param> /// <returns></returns> public Teacher GetProfesoriByMail(string mail) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.Teachers.SingleOrDefault(item => item.Mail == mail)); } } catch { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw new InvalidUserException(); } }
/// <summary> /// Returns an User corresponding to the Mail parameter. /// </summary> /// <param name="mail"></param> /// <returns></returns> public User GetUserByMail(string mail) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.Users.SingleOrDefault(item => item.Mail == mail)); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public List <InregistrareProfesorModel> GetAllRegistrationRequests() { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.RegistrationRequests.ToList()); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public Course GetCourseById(Guid courseId) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.Courses.SingleOrDefault(item => item.CourseId.Equals(courseId))); } } catch { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw new InvalidUserException(); } }
public List <HighSchool> GetAllHighSchools() { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.HighSchools.ToList()); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public HighSchool GetHighSchoolByName(string name) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.HighSchools.Include("Users") .SingleOrDefault(item => item.Nume == name)); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public InregistrareProfesorModel GetRequestById(Guid id) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.RegistrationRequests.SingleOrDefault( request => request.UserId == id)); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public HighSchool GetHighSchoolById(Guid highSchoolId) { try { using (var context = new EducatieIncluzivaDBContext()) { return(context.HighSchools.Include("Users").SingleOrDefault( highschool => highschool.HighSchoolId == highSchoolId)); } } catch (Exception exc) { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw exc; } }
public void UpdateUser(string parola, string nume, string prenume, string mail, HighSchool scoalaDeProvenienta) { using (var context = new EducatieIncluzivaDBContext()) { var theUser = this.GetUserByMail(mail); theUser.Parola = parola == null ? theUser.Parola : parola; theUser.Nume = nume == null ? theUser.Nume : nume; theUser.Prenume = prenume == null ? theUser.Prenume : prenume; theUser.Mail = mail == null ? theUser.Mail : mail; theUser.ScoalaDeProvenienta = (scoalaDeProvenienta == theUser.ScoalaDeProvenienta) ? theUser.ScoalaDeProvenienta : scoalaDeProvenienta; context.Users.Attach(theUser); context.Entry(theUser).State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult Approve(Guid id) { var rr = new ResourcesRepository(); var request = rr.GetRequestById(id); var highschool = rr.GetHighSchoolByName(request.ScoalaDeProveninenta); var teacher = new Teacher(request.Parola, request.Nume, request.Prenume, request.Mail, highschool); using (var context = new EducatieIncluzivaDBContext()) { var entry = context.RegistrationRequests.Find(id); context.RegistrationRequests.Remove(entry); context.Teachers.Add(teacher); context.SaveChanges(); } return(RedirectToAction("CereriInregistrare")); }
public List <Course> GetCoursesByTeacherMail(string mail) { var courses = new List <Course>(); var user = this.GetProfesoriByMail(mail); var userId = user.UserId; try { using (var context = new EducatieIncluzivaDBContext()) { courses = context.Courses .Where(c => c.ProfesorId == userId) .OrderBy(c => c.Nume) .ToList <Course>(); } } catch { //Logger.Instance.LogError(ErrorCategory.Data, "Unable to retrieve information about Employees.", exc); throw new InvalidUserException(); } return(courses); }
public void UpdateTeacher(string nume, string prenume, string mail, string bio, string numevechi1, string numevechi2, string numevechi3, string c2, string c1, string c3) { using (var context = new EducatieIncluzivaDBContext()) { // get the teacher var theUser = this.GetProfesoriByMail(mail); //update general info about the teacher theUser.Description = bio; theUser.Mail = mail; theUser.Nume = nume; theUser.Prenume = prenume; UpdateCurs(c1, theUser, numevechi1); UpdateCurs(c2, theUser, numevechi2); UpdateCurs(c3, theUser, numevechi3); DbEntityEntry <Teacher> entry = context.Entry(theUser); entry.State = EntityState.Modified; context.SaveChanges(); } }
public ActionResult AddLesson(HttpPostedFileBase file, string mail, string materie) { var rr = new ResourcesRepository(); // Verify that the user selected a file if (file != null && file.ContentLength > 0) { ViewData["fileUp"] = null; // extract only the fielname var fileName = Path.GetFileName(file.FileName); // store the file inside ~/App_Data/uploads folder var subPath = "~/App_Data/uploads/" + mail; bool IsExists = System.IO.Directory.Exists(Server.MapPath(subPath)); if (!IsExists) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath)); } var subPath2 = "~/App_Data/uploads/" + mail + "/" + materie; bool IsExists2 = System.IO.Directory.Exists(Server.MapPath(subPath2)); if (!IsExists2) { System.IO.Directory.CreateDirectory(Server.MapPath(subPath2)); } var path = Path.Combine(Server.MapPath("~/App_Data/uploads/"), mail + "/", materie, fileName); file.SaveAs(path); using (var db = new EducatieIncluzivaDBContext()) { var myTeacher = db.Teachers.SingleOrDefault(item => item.Mail == mail); var curs = from p in db.Courses where p.Nume.Equals(materie) && p.ProfesorId == myTeacher.UserId select p; /* Course cur = new Course(); * cur.Nume = materie; * cur.ProfesorId = myTeacher.UserId; */ Lesson l = new Lesson(); l.ProfesorOwner = myTeacher; l.ProfesorOwnerId = myTeacher.UserId; l.Titlu = fileName; foreach (var c in curs) { c.Lectii.Add(l); break; } /* if (myTeacher.Materii != null) * { * if (myTeacher.Materii.Contains(cur)) * { * db.Lessons.Add(l); * } * else * { * Console.WriteLine("Nu exista"); * } * } * else * { * Console.WriteLine("e NULL"); * } * /* * if (myTeacher.Materii[0].Nume.Equals(materie)) * { * nr = 0; * } * else if (myTeacher.Materii[1].Nume.Equals(materie)) * { * nr = 1; * } * else * { * nr = 2; * } * myTeacher.Materii[nr].Lectii.Add(l); */ DbEntityEntry <Teacher> entry = db.Entry(myTeacher); entry.State = EntityState.Modified; db.SaveChanges(); ViewData["fileUp"] = "incarcat"; ViewData["materie"] = materie; } } var model = rr.GetUserByMail(mail); // redirect back to the index action to show the form once again return(View("../../Views/AddLesson/AddLesson", model)); }
public ActionResult Update(FormCollection te, string mail) { var rr = new ResourcesRepository(); var model = rr.GetUserByMail(mail); if (te.GetValue("teach.Nume").AttemptedValue.Equals("") || te.GetValue("teach.Prenume").AttemptedValue.Equals("") || te.GetValue("teach.Description").AttemptedValue.Equals("")) { TempData["alertMessage"] = "The user has to be alerted"; return(View("../../Views/Cont/ContulMeu", model)); } else { TempData["alertMessage"] = null; string numeCurs1 = te.GetValue("teach.Materii[0]").AttemptedValue; string numeCurs2 = te.GetValue("teach.Materii[1]").AttemptedValue; string numeCurs3 = te.GetValue("teach.Materii[2]").AttemptedValue; string nume = te.GetValue("teach.Nume").AttemptedValue; string prenume = te.GetValue("teach.Prenume").AttemptedValue; string description = te.GetValue("teach.Description").AttemptedValue; int index = 0; string c1, c2, c3; c1 = ""; c2 = ""; c3 = ""; using (var db = new EducatieIncluzivaDBContext()) { var curs = from p in db.Courses where p.ProfesorId == model.UserId select p; foreach (var c in curs) { if (index == 0) { c1 = c.Nume; } else if (index == 1) { c2 = c.Nume; } else if (index == 2) { c3 = c.Nume; } index++; } } // if (c1.Equals("") || c2.Equals("") || c3.Equals("")) // { if (!numeCurs1.Equals(""))// && c1.Equals("")) { rr.UpdateTeacher(nume, prenume, mail, description, c1, numeCurs1); } if (!numeCurs2.Equals(""))//&& c2.Equals("")) { rr.UpdateTeacher(nume, prenume, mail, description, c2, numeCurs2); } if (!numeCurs3.Equals(""))// && c3.Equals("")) { rr.UpdateTeacher(nume, prenume, mail, description, c3, numeCurs3); } // } /* else * { * if (numeCurs2.Equals("")) * { * rr.UpdateTeacher(nume, prenume, mail, description, * c1,numeCurs1); * } * else if (numeCurs3.Equals("")) * { * rr.UpdateTeacher(nume, prenume, mail, description, * c1, c2, * numeCurs1, numeCurs2); * } * else * { * rr.UpdateTeacher(nume, prenume, mail, description, * c1,c2, c3, * numeCurs1, numeCurs2, numeCurs3); * } * }*/ return(View("../../Views/Cont/ContulMeu", model)); } }